
% DEMO GAUSS-LEGENDRE.

a=-1; b=1;
N=20;
ftype=1;

ajac=0; bjac=0;              
ab_jac=r_jacobi(N,ajac,bjac);    % TERM. RICORSIVI.
xw_jac=gauss(N,ab_jac);          % NODI E PESI IN MATRICE.
x_jac=xw_jac(:,1);                   % NODI GAUSS-LEGENDRE [-1,1].
x_jac_ab=((a+b)/2)+((b-a)/2)*x_jac;  % NODI GAUSS-LEGENDRE [a,b].  
w_jac=xw_jac(:,2);                   % PESI GAUSS-LEGENDRE [-1,1].
w_jac_ab=((b-a)/2)*w_jac;            % PESI GAUSS-LEGENDRE [a,b].
fx_jac_ab=f(x_jac_ab,ftype);         % VALUTAZIONE FUNZIONE.  
I_jac=w_jac_ab'*fx_jac_ab;           % VALORE INTEGRALE.


% RISULTATI.
fprintf('\n \t [RISULTATO][GAUSS-LEGENDRE  ]: %18.18f',I_jac);


% RISULTATI.
res=exact_results(ftype);
fprintf('\n \t [GAUSS-LEGENDRE  ][ERR.ASS.]: %2.2e',abs(I_jac-res)); 

% SOMMA ABS. PESI.
sw_jac=sum(abs(w_jac));
fprintf('\n \t [SOMMA ABS. PESI][GAUSS - LEGENDRE]: %2.2e',sw_jac);

% PLOT PESI.
hold off;
semilogy(1:length(x_jac),x_jac,'mo-'); pause
semilogy(1:length(w_jac),w_jac,'mo-'); hold on;
