Matlab 入门级问题
function[c,err,yc]=bisect(f,a,b,delta)ya=feval(f,a);yb=feval(f,b);ifya*yb>0,return,en...
function [c,err,yc]=bisect(f,a,b,delta)
ya=feval(f,a);
yb=feval(f,b);
if ya*yb>0,return,end
max1=1+round((log(b-a)-log(delta))./log(2));
for k=1:max1
c=(a+b)/2;
yc=feval(f,c);
if yc==0
a=c;
b=c;
elseif yb*yc>0
b=c;
yb=yc;
else
a=c;
ya=yc;
end
if b-a<delta,return,end
end
c=(a+b)/2;
err=abs(b-a);
yc-feval(f,c);
一个二分法的程序,几乎是跟着书本打的,但输入
[a,b,c]=bisect('f',0,2,.0001)
时出现
??? Output argument "err" (and maybe others) not assigned during call to "E:\mathlab\work\bisect.m (bisect)".
Error in ==> bisect at 2
ya=feval(f,a);
求破。
function y=f(x)
y=x.*sin(x)-1; 展开
ya=feval(f,a);
yb=feval(f,b);
if ya*yb>0,return,end
max1=1+round((log(b-a)-log(delta))./log(2));
for k=1:max1
c=(a+b)/2;
yc=feval(f,c);
if yc==0
a=c;
b=c;
elseif yb*yc>0
b=c;
yb=yc;
else
a=c;
ya=yc;
end
if b-a<delta,return,end
end
c=(a+b)/2;
err=abs(b-a);
yc-feval(f,c);
一个二分法的程序,几乎是跟着书本打的,但输入
[a,b,c]=bisect('f',0,2,.0001)
时出现
??? Output argument "err" (and maybe others) not assigned during call to "E:\mathlab\work\bisect.m (bisect)".
Error in ==> bisect at 2
ya=feval(f,a);
求破。
function y=f(x)
y=x.*sin(x)-1; 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询