Why is there an error?

2 次查看(过去 30 天)
function chebyshev (a, b, numpolys)
t=a:0.1:b;
allp=zeros(numpolys, length(t));
for n=1:numploys
x=(a+b)/2+(b-a)/2*cos((2*(1:n)-1)*pi/(2*n));
y=(1)./(x.^2+1);
allp(n,:)=newton(x, y, t);
end
plot (t, allp)
end
function p=newton(x,y,t)
n=length(x);
x=30;
y=1.0803306e-44;
t=[a,b];
c=y;
for k=2:n
c(k:n)=(c(k:n)-c(k-1))./(x(k:n)-x(k-1));
end
p=c(n)*ones(size(t));
for k=n-1:-1:1
p=p.*(t-x(k))+c(k);
end
end

采纳的回答

Wayne King
Wayne King 2014-2-6
编辑:Wayne King 2014-2-6
The simple answer is your input argument is spelled numpolys in the function declaration, but you spell it numploys in the for loop.
But you have other problems, for example you have a,b internal to the subfunction newton(), but you don't pass those.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by