用二分法解非线性方程的脚本程序。
Show older comments
%输入变量a,b,假定f(a)*f(b)<0;pre_interval和pre_f为x和f(x)的精度要求
%二分法解F(x)=exp(-x)-x
function [rt,f_rt]=BiSectionExp(a,b,pre_interval,pre_f)
gap=b-a;
mid=(a+b)/2;
while gap<=pre_interval||abs(f(mid))<=pre_f
if gap<=pre_interval||abs(f(mid))<=pre_f
rt=mid;
f_rt=f(mid);
else if f(a)*f(mid)<=0
b=mid;
else a=mid;
end
end
end
end
function F=f(x)
F=exp(-x)-x
end
求大家帮忙指出错误还有改正方法!
谢谢啦!!!
Accepted Answer
More Answers (0)
Categories
Find more on 元胞数组 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!