I have used Chebyshev nodes to avoid Runge's phenomenon
x = −5 : 0.001 : 5;
i = 0 : 10;
xc = −1/2 ∗ 10∗cos((2 ∗ i + 1)/(2 ∗ 10 + 2) ∗ pi);
yc = 1./(1 + xc.ˆ2);
pc = polyfit(xc, yc, length(xc) − 1);
pyc = polyval(pc, x);
plot(x, pyc,'k')
But:
x = −5 : 0.001 : 5;
i = 0 : 50;
xc = −1/2 ∗ 10∗cos((2 ∗ i + 1)/(2 ∗ 10 + 2) ∗ pi);
yc = 1./(1 + xc.ˆ2);
pc = polyfit(xc, yc, length(xc) − 1);
pyc = polyval(pc, x);
plot(x, pyc,'k')
What is the problem in this case?
Thanks!


Try this:
Note the change in the line that starts with
xc =. With MATLAB, I get this warning whenN>14: