a = -1;
b = 1;
n = 50;

f = @(x) 1./(1+25.*x.^2);
%f = @(x) sin(2*pi*x);

x = linspace(a,b,n+1);
y = f(x);

p = polyfit(x,y,n);
x2 = linspace(a,b,300);
y2 = polyval(p,x2);

plot(x,y,'o',x2,y2);