永发信息网

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

答案:4  悬赏:10  手机版
解决时间 2021-11-28 20:53
  • 提问者网友:浩歌待明月
  • 2021-11-28 00:17
用二分法求方程2x*x*x-4x*x+3x-6=0在(-10,10)之间的根
最佳答案
  • 五星知识达人网友:独钓一江月
  • 2021-11-28 00:46
这个相对来讲你只要知道什么是二分法就很好做了,下面是我写的程序,仅供参考(我在visual C++6.0中测试通过,其他编译系统我不太清楚)
#include
#include
void main()
{
float x0,x1,x2,f0,f1,f2;
do
{
printf("please enter x1 & x2:\n");
scanf("%f,%f",&x1,&x2);
f1=((2*x1-4)*x1+3)*x1-6;
f2=((2*x2-4)*x2+3)*x2-6;
}
while ((f1*f2)>0);
do
{
x0=(x1+x2)/2;
f0=((2*x0-4)*x0+3)*x0-6;
if ((f0*f1)<0)
{
x2=x0;
f2=f0;
}
else
{
x1=x0;
f1=f0;
}
}
while(fabs(f0)>=1e-5);
printf("the root of equation is :%f\n",x0);
}
全部回答
  • 1楼网友:孤老序
  • 2021-11-28 05:16
2
  • 2楼网友:山君与见山
  • 2021-11-28 03:48
//3.7
#include
#include
void main()
{
float x0,x1,x2,f0,f1,f2;
printf("请输入x1,x2的值:");
scanf("%f%f",&x1,&x2);
f1=2*x1*x1*x1-4*x1*x1+3*x1-6;
f2=2*x2*x2*x2-4*x2*x2+3*x2-6;

do
{
x0=(x1+x2)/2;
f0=2*x0*x0*x0-4*x0*x0+3*x0-6;
if(f0*f1<0)
{x2=x0;f2=f0;}
else
{x1=x0;f1=f0;}
}while(fabs(f0)>=1e-5);
printf("方程的根为:%f\n",x0);
}
//完美运行。
  • 3楼网友:廢物販賣機
  • 2021-11-28 02:09
表1 函数 的零点取值区间表
中点 中点函数值 取值区间
f(-10)<0,f(10)>0 (-10,10)
0 f(0)<0 (0,10)
5 f(5)>0 (0,5)
2.5 f(2.5)>0 (0,2.5)
1.25 f(1.25)<0 (1.25,2.5)
……下面的自己算吧……看该题是要精确到多少位,来确定算到多少位,
用matlab就好算了
function rtn=bisection(fx,xa,xb,n,delta)
% Bisection Method
% The first parameter fx is a external function with respect to viable x.
% xa is the left point of the initial interval
% xb is the right point of the initial interval
% n is the number of iterations.
x=xa;fa=eval(fx);
x=xb;fb=eval(fx);
disp(' [ n xa xb xc fc ]');
for i=1:n
xc=(xa+xb)/2;x=xc;fc=eval(fx);
X=[i,xa,xb,xc,fc];
disp(X),
if fc*fa<0
xb=xc;
else xa=xc;
end
if (xb-xa)end

>>f='2*x*x*x-4*x*x+3*x-6';
>>bisection(f,-10,10,20,10^(-3))
10^(-3)看你精确到几位……

参考资料:数值计算方法

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