
用二分法求方程2x*x*x-4x*x+3x-6=0在(-10,10)之间的根
4个回答
展开全部
这个相对来讲你只要知道什么是二分法就很好做了,下面是我写的程序,仅供参考(我在visual C++6.0中测试通过,其他编译系统我不太清楚)
#include <stdio.h>
#include <math.h>
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);
}
#include <stdio.h>
#include <math.h>
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);
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?

2025-08-07 广告
广州赛恩科学仪器有限公司(原中大科仪)始创于2032年,是全球领先的精密测量仪器供应商和微弱信号检测方案提供商。公司以锁相放大器为核心产品,陆续推出光学斩波器、源表、功率放大器、电化学工作站、电流源等一系列产品。赛恩科仪推出的锁相放大器,覆...
点击进入详情页
本回答由赛恩科仪提供
展开全部
表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)<delta,break,end
end
>>f='2*x*x*x-4*x*x+3*x-6';
>>bisection(f,-10,10,20,10^(-3))
10^(-3)看你精确到几位……
中点 中点函数值 取值区间
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)<delta,break,end
end
>>f='2*x*x*x-4*x*x+3*x-6';
>>bisection(f,-10,10,20,10^(-3))
10^(-3)看你精确到几位……
参考资料: 数值计算方法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
//3.7
#include<stdio.h>
#include<math.h>
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);
}
//完美运行。
#include<stdio.h>
#include<math.h>
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);
}
//完美运行。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
2
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询