
Metoda Newtona
By:
Mistic92 on
May 8th, 2012 | syntax:
Java | size: 0.68 KB | hits: 25 | expires: Never
package numeryczne;
import java.lang.System;
public class styczne {
static double f(double x)
{
return x*x-1;
}
static double fpoch(double x)
{
return 2*x;
}
public static void main(String[]args)
{
long time1 = System.nanoTime();
double a=-0.5,b=3,eps=0.000001,x=a;
int l=0;
while (Math.abs(f(x)) > eps || x>3 )
{
x=x -(f(x)/Math.abs(fpoch(x)));
l++;
}//while
long time2 = System.nanoTime();
long wynik = time2-time1;
System.out.println("Wykonałem "+l+" operacji a x wyniósł "+x+" w czasie: "+wynik);
}
}