用弦截法任意实数方程求实根 用matlab 语言编程
推荐于2018-05-04
展开全部
由于y=0是一个没有意义的点,故从0.01开始。输入:y=secant('0.15/y-y*sin(0.15^y)-1',0.01,5)结果:y = 0.1369其中secant.m内容为:function root=Secant(f,a,b,eps)
if(nargin==3)
eps=1.0e-6;
endf1=subs(sym(f),findsym(sym(f)),a);
f2=subs(sym(f),findsym(sym(f)),b);
if(f1==0)
root=a;
end
if(f2==0)
root=b;
endif(f1*f2>0)
disp('两端点函数值乘积大于0!');
return;
else
tol=1;
fa=subs(sym(f),findsym(sym(f)),a);
fb=subs(sym(f),findsym(sym(f)),b);
root=a-(b-a)*fa/(fb-fa);
while(tol>eps)
r1=root;
fx=subs(sym(f),findsym(sym(f)),r1);
s=fx*fa;
if(s==0)
root=r1;
else
if(s>0)
root=b-(r1-b)*fb/(fx-fb);
else
root=a-(r1-a)*fa/(fx-fa);
end
end
tol=abs(root-r1);
end
end
if(nargin==3)
eps=1.0e-6;
endf1=subs(sym(f),findsym(sym(f)),a);
f2=subs(sym(f),findsym(sym(f)),b);
if(f1==0)
root=a;
end
if(f2==0)
root=b;
endif(f1*f2>0)
disp('两端点函数值乘积大于0!');
return;
else
tol=1;
fa=subs(sym(f),findsym(sym(f)),a);
fb=subs(sym(f),findsym(sym(f)),b);
root=a-(b-a)*fa/(fb-fa);
while(tol>eps)
r1=root;
fx=subs(sym(f),findsym(sym(f)),r1);
s=fx*fa;
if(s==0)
root=r1;
else
if(s>0)
root=b-(r1-b)*fb/(fx-fb);
else
root=a-(r1-a)*fa/(fx-fa);
end
end
tol=abs(root-r1);
end
end
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询