function [c,x] = chebpol_int(fn,n)   
% Cálculo de los coeficientes de los polinomios de Chebyshev
% 
 x = cos((2*(1:n)'-1)*pi/2/n);
 y = fn(x);
 T = [zeros(n,1) ones(n,1)];
 c = [sum(y)/n zeros(1,n-1)];
 a = 1;
 for k = 2:n
    T = [T(:,2) a*x.*T(:,2)-T(:,1)];
    c(k) = sum(T(:,2).* y)*2/n;
    a = 2;
 end
end

function u = chebpol_clenshaw(c,x)
 n = length(c);
 u = c(n)*ones(size(x));
 if n > 1
    ujp1 = u;
    u = c(n-1) + 2*x*c(n);
    for j = n-2:-1:1
       ujp2 = ujp1;
       ujp1 = u;
       u    = c(j)+2*x.*ujp1-ujp2;
    end
    u = u-x.*ujp1;
 end
end
