用二分法求方程2x3-4x2+3x-6=0在(-10,10)之间的根.
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/05 20:40:00
用二分法求方程2x3-4x2+3x-6=0在(-10,10)之间的根.
用二分法求方程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);
}
}
另外,虚机团上产品团购,超级便宜
匿名
2x^3-4x^2+3x-6=0
(2x^3-4x^2)+(3x-6)=0
2x^2(x-2)+3(x-2)=0
(x-2)(2x^2+3)=0
故x-2=0或2x^2+3
显然2x^2+3≠0故x-2=0
即x=2
2x^3-4x^2+3x-6=0
(2x^3-4x^2)+(3x-6)=0
2x^2(x-2)+3(x-2)=0
(x-2)(2x^2+3)=0
故x-2=0或2x^2+3因为x在(-10,10)
显然2x^2+3≠0故x-2=0
即x=2