clc; clear; close all;

N = 15;

fileID = fopen('LebesgueConstant1D.txt','w');
fprintf(fileID,'\\begin{tabular}{ccc}\n');
fprintf(fileID,'N & Gauss-Lobatto nodes & equidistant nodes \\\\ \\hline\n');

tic;
dr = -1:0.002:1;
n_points = length(dr);
for i = 1:N
    r_GL = GaussLobattoNodes(i + 1);
    r_equi = linspace(-1,1,i + 1);
    
    LagPols_GL = LagrangePolynomialBasis(r_GL);
    LagPols_equi = LagrangePolynomialBasis(r_equi);
    
    N_p = i + 1;
    LebConstPoints_GL = abs(polyval(LagPols_GL{1},dr));
    LebConstPoints_equi = abs(polyval(LagPols_equi{1},dr));
    for j = 2:N_p
        LebConstPoints_GL = LebConstPoints_GL + abs(polyval(LagPols_GL{j},dr));
        LebConstPoints_equi = LebConstPoints_equi + abs(polyval(LagPols_equi{j},dr));
    end
    
    LebConst_GL = max(LebConstPoints_GL);
    LebConst_equi = max(LebConstPoints_equi);
    
    fprintf(fileID,'%d & ',i);
    fprintf(fileID,'%f & ',LebConst_GL);
    fprintf(fileID,'%f',LebConst_equi);
    if i < N
        fprintf(fileID,' \\\\');
    end
    fprintf(fileID,'\n');
end
fprintf(fileID,'\\end{tabular}');
fclose(fileID);
toc;