
function demo_integrazione5(nV)

if nargin < 1
    nV=3:10;
end

experiment=2;


for ii=1:length(nV)
    
    n=nV(ii);
    
    switch experiment
        
        case 1
            
            if nargin < 1
                n=4;
            end
            [x,w]=newton_cotes(n);
            
            for jj=0:n+2
                f=@(x) x.^jj;
                I=1/(jj+1)-(-1)^(jj+1)/(jj+1);
                fx=feval(f,x);
                In=w*fx';
                fprintf('\n \t deg: %2.0f ae: %1.2e',jj,abs(I-In));
            end
            
        case 2
            [x,w]=newton_cotes(n);
            fprintf('\n \t $%2.0f$ & $%1.5e$\\\\',n,sum(abs(w)));
            
    end
    
end




function [x,w]=newton_cotes(n)

a=-1; b=1;

h=(b-a)/n;

x=linspace(a,b,n+1);

switch n
    case 3
        w=(3*h/8)*[1 3 3 1];
    case 4
        w=(2*h/45)*[ 7 32 12 32 7];
    case 5
        w=(5*h/288)*[19 75 50 50 75 19];
    case 6
        w=(1*h/140)*[41 216 27 272 27 216 41];
    case 7
        w=(7*h/17280)*[751 3577 1323 2989 2989 1323 3577 751];
    case 8
        w=(4*h/14175)*[989 5888 -928 10496 4540 10496 -928 5888 989];
    case 9
        w=(9*h/89600)*[2857 15741 1080 19344 5778 5778 19344 1080 15741 2857];
    case 10
        w=(5*h/299376)*[16067 106300 -48525 272400 -260550 427368 -260550 272400 -48525 106300 16067];
end