题目描述:
求解方程2x3-5x2+3x-6=0的1个实数根,要求精确到0.00001
已知f(x)=2x3-5x2+3x-6 在>0时单调递增
我的程序:
#include<stdio.h>
double f(double x)
{
return 2*x*x*x-5*x*x+3*x-6;
}
int main()
{
double a=0,b=10,c;
int i;
for(i=0;b-a>1e-6;i++)
{
c=(a+b)/2;
if(f(a)*f(c)<0) b=c;
else a=c;
}
printf("%.5lf",a);
}
运行结果:
扫描二维码关注公众号,回复:
9115292 查看本文章