
function c=fourier_coefficients(degree)

for ii=0:degree
    c(ii+1)=quadl(@(x)myfun(x,ii),-1,1,10^(-15));
end




function y = myfun (x,j)

% f=@(x) x.^5;

%y1=feval(f,x);

y1=legendre_polynomials(4,x');
y2=legendre_polynomials(j,x');


y=y1'.*y2';

function px = legendre_polynomials(n,x)

% INPUT:
% n: maximum degree.
% x: column vector of dimansion M.

% OUTPUT:
% px: is the Legendre polynomial of degree "n" evaluated at x.


if ( n < 0 )
    px=[];
    return
end

px(:,1) = ones(size(x));
if ( n < 1 )
    return
end

px(:,2) = x;

for i = 2 : n
    
    px(:,i+1) = ( ( 2 * i - 1 ) * x .* px(:,i)   ...
        - (     i - 1 ) *     px(:,i-1) ) ...
        / (     i     );
    
end

px=px(:,end);

