class fun{
// TODO Auto-generated method stub
public static void Bisektion()
{
float ymiddle = (float)0.0;
float yleft = (float)0.0;
float yright = (float)0.0;
float a = 0;
float b = (float)3;
for(int i = 0;i <=10000;i++)
{
float c = (float)((a+b)/2);
float x = c;
ymiddle =(float) Math.pow(x, 3)-3*x-3; // 带入C, C 居于方程的中间
yleft =(float) Math.pow(a, 3)-3*a-3;
yright =(float) Math.pow(b, 3)-3*b-3;
if (ymiddle*yleft>0) {
a = c;
if(i==10000)
{
System.out.println("Die Resultat:"+c);
}
}else {
b = c;
if(i==10000)
{
System.out.println("Die Resultat:"+c);
}
}
}
}
}
public class Bisektionsverfahren {
public static void main(String[] args) {
fun.Bisektion();
}
}
上面是我写的程序,但是有一个东西完全没有思路,就是如何设置这个循环,尽可能达到double或者float值的极限呢?也就是能达到的最精确的值。