% Runge function in chebfun
f = inline('1 ./ (1 + x.^2)'); % the Runge function 
xx = [-5:0.1:5];
fxx = f(xx);
plot(xx,fxx,'-m')
p = chebfun('1./(1+x.^2)', [-5,5]); % Chebyshev polynomial 
coeffs = chebcoeffs(p); % vector of coefficients of the interpolant
%(note: in an older version of chebfun its was "chebpoly")
n = length(coeffs) % n=187 for this function on [-5,5] => 
% it means that we have a polynomial of degree 186 that interpolates f at 187 points 
hold on;
plot(p, '.-k'); 
xlabel ('x') ;
ylabel ('1/(1 + xˆ2)');
title('Runge function and Chebyshev polynomial');
legend('Runge function','Chebyshev polynomial');
%the two plots are almost indistinguishable!
