%First, compute vectors x and f(x):\\
for k=1:n+1
  x(k)=cos( pi*(k-1+0.5) / (n+1) );
  F(k)=f(x(k));
end;

%Second, compute the corresponding $T_n$ and $T_n(x)$:\\
for k=1:2
T(k)=cos((k-1)*acos(a));
end;
for k=3:n+1
T(k)=2*a*T(k-1)-T(k-2);
end;


%Finally, compute the coefficients $c_n$:\\
c(1)=( 1 / (n+1) )*sum(F);
for k=2:n+1
c(k)=(1 / ( (n+1)/2 ) ) * sum(F.*subs(T(k),a,x));
end;

c