function Division(fun,x,a,b)
p=-1;
while (fun(a)*fun(b) <=0) && (abs(a-b)>x)
c=(a+b)/2;
if fun(c)*fun(b)<=0
a=c;
p=p+1;
else
p=p+1;
b=c;
end
end
sprintf('二分次数为:%d',p)
sprintf('结果区间为:%f,%f,结果为:%f',a,b,(a+b)/2 )
end
clc;
fun=@(x) exp(x)+10*x-2;
Division(fun,0.005,0,1);
matlab 二分法
最新推荐文章于 2023-02-27 16:53:58 发布