1个回答
展开全部
public class Dichotomie {
public static void main(String[] args)
{
double a = -10, b = 10, delta = 1E-15;
double x1 = a;
double x2 = b;
while(x2 - x1 > delta)
{
double diff = x2 - x1;
if (isArea(x1, x2))
x1 = x1 + diff / 2;
else
{
x2 = x1;
x1 = x1 - diff;
}
}
System.out.println("Solution: " + x1);
}
private static boolean isArea(double x1, double x2)
{
boolean result = true;
if(f(x1) * f(x2) > 0)
result = false;
else if(f(x1) * f(x2) < 0)
result = true;
return result;
}
private static double f(double x)
{
return 2*x*x*x - 4*x*x +3*x -6;
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询