对分法(二分法)求解非线性方程-M语言

来源:互联网 发布:无力去爱谁 网络翻唱版 编辑:程序博客网 时间:2024/06/05 12:44

求解函数 f(x) = sin(exp(x)), 起始区间[0,3],精度 <0.00001

a = 0;
b = 3;
while (b-a)>0.00001,
c = (a+b)/2;
if sin(exp(a)) * sin(exp(c)) < 0
b =c;
elseif sin(exp(b)) * sin(exp(c)) < 0
a = c;
else
disp(‘no root’);
end
end
disp(‘the root is : ‘);
(a+b)/2

运行结果:(MATLAB数据显示格式为:long)
the root is :

ans =

1.144732475280762

0 0
原创粉丝点击