function LegendreovaAproximace(f,a,b,n)

load GaussLegendreQuadrature
w = weights{18};
x = points{18};

fx = f((a+b)/2+(b-a)*x./2);
xxtilda = linspace(a,b,100);
xx = linspace(-1,1,100);
fxx = xx; fxx(:) = 0;
for i=0:n
    if i==0
        Pi = x.^0;
        Pixx = xx.^0;
    elseif i==1
        Pi_1 = Pi;
        Pi = x;
        Pi_1xx = Pixx;
        Pixx = xx;
    else
        tmp = Pi;
        Pi = ((2*(i-1)+1)/i)*x.*Pi - ((i-1)/i)*Pi_1;
        Pi_1 = tmp;
        tmpxx = Pixx;
        Pixx = ((2*(i-1)+1)/i)*xx.*Pixx - ((i-1)/i)*Pi_1xx;
        Pi_1xx = tmpxx;
    end
    
    alphai =  ((2*i+1)/2) * w * (fx.*Pi)'; % Gauss quadrature
    
    fxx = fxx + alphai*Pixx;
end

plot(xxtilda,fxx,'r',xxtilda,f(xxtilda),'b')
