用二分法求方程2x3-4x2+3x-6=0在(-10,10)之间的根.

问题描述:

用二分法求方程2x3-4x2+3x-6=0在(-10,10)之间的根.

nclude iostream>
using namespace std;
double p(double x)
{
return 2*x*x*x-4*x*x+3*x-6;
}
int main()
{
double a,b;
cin >> a >> b;
double fa = p(a),fb = p(b),fm;
do
{
fm = p((a+b)/2);
if(fm==0) break;
if(fm*fa0) b = (a+b)/2;
else if(fm*fb0) a = (a+b)/2;
}while(b-a>0.00001);
cout ((b+a)/2) endl;
}
------
你的修改过的:
#include stdio.h>
#include math.h>
int main()
{
float a=-10.0;
float b=10.0;
float fc,fa,fb,c;
c=(a+b)/2;
fc=2*pow(c,3)-4*pow(c,2)+3*c-6;
fa=2*pow(a,3)-4*pow(a,2)+3*a-6;
fb=2*pow(b,3)-4*pow(b,2)+3*b-6;
if (fc==0)
printf("the result is %lf.\n",c);
else
{
do
{
c=(a+b)/2;
if(fc==0) break;
if (fa*fc0)
else if(fb*fc0)
}
while (b-a>0.1e-6);
printf("the result is %lf.\n",c);
}
}
另外,虚机团上产品团购,超级便宜
匿名