clear
X=poly(0,"X")
n=10;

function t=y(j)
  j=j-1;
  t=cos((2*j+1)/(2*n+2)*%pi);
endfunction
  
function y=f(t)
   y=1.0./(1+t.^2);
endfunction
 
 T(1)=1;
 T(2)=X;
 
for i=[3:n+1]
  T(i)=2*X*T(i-1)-T(i-2);
end


for i=1:n+1
  a(i)=0;
  for j=1:n+1
    a(i)=a(i)+horner(T(i),y(j))*f(y(j));
  end;
  a(i)=a(i)/(n+1);
end
a(1)=a(1)/2;

g=0
  for i=1:n+1
    g=g+a(i)*T(i);
  end
  

t=[-1:0.01:1];
plot2d(t,f(t))
plot2d(t,2*horner(g,t),5)

xset("window",1)
plot2d(t,f(t)-2*horner(g,t),5)
