永发信息网

JAVA帮忙

答案:1  悬赏:70  手机版
解决时间 2021-05-03 13:35
  • 提问者网友:謫仙
  • 2021-05-02 17:53

The Bisection method is a simple example of numerical algorithms for solving equations. The algorithm uses the classic divide and conquer strategy. Begin with an interval that contains the unknown solution. Divide it in half, discard the half that does not contain the solution, and repeat.
Write a program that implements the Bisection Algorithm to solve the equation

which has the same solution as the equation

最佳答案
  • 五星知识达人网友:春色三分
  • 2021-05-02 18:39
public class test
{
static double F( double x )
{
return Math.sqrt( x ) - Math.cos( x );
}
public static void main(String[] args) {
double l = 0, r = Math.PI/2;
final double TOL = 0.5e-7;
double m;
while ( Math.abs( r - l ) > TOL*2 ) {
m = ( r + l ) / 2;
if ( F( l ) * F( m ) > 0 ) {
l = m;
} else {
r = m;
}
}
m = (r + l) / 2;
System.out.println( "root: " + m );
}
}

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯