Why is there an error?

1 view (last 30 days)
Ehi Eromosele
Ehi Eromosele on 6 Feb 2014
Edited: Wayne King on 6 Feb 2014
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

Accepted Answer

Wayne King
Wayne King on 6 Feb 2014
Edited: Wayne King on 6 Feb 2014
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.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!