ニュートン反復ルートアルゴリズム
502 ワード
public class Test extends Thread {
private static float a = 121;
public static void main(String[] args){
float x0 = 1;
float x1 = (float) (x0+(a/x0-x0)*0.5);
float diff = x1 - x0;
while(true){
x0 = (float) (x1+(a/x1-x1)*0.5);
diff = x1 -x0;
if(diff<0.0001 && diff>-0.0001){
break;
}
x1 = (float) (x0+(a/x0-x0)*0.5);
diff = x1 -x0;
if(diff<0.1 && diff>-0.1){
break;
}
}
System.out.println(x0);
}
}