Pfeffer
2017-10-03 23:11我写的二分法,求方程的解,求大神优化和解释自己的疑问
10class 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值的极限呢?也就是能达到的最精确的值。
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- 设计一个函数,使用二分法求方程e^x+x=0在(-1,0)之间的根?
- c语言
- 1个回答
- 二分法查找升序一维数组,结果不对
- c语言
- 2个回答
- pie
- as
- each
- 1个回答
- 编程菜鸟一枚,有一个问题想请教
- c
- 编程
- 7个回答
- java的二分法怎么写??
- java
- 3个回答
换一换