N = 10;
res = [];
 for test=1:4
    n = N-1;
    h = 1/N;
    x = 1 + h*(1:n)';
    g = 2-2*x+x.^2;
    dia = (1-2/h^2)*ones(n,1);
    sub = 1/h^2 + g(2:n)/(2*h);
    sup = 1/h^2 - g(1:end-1)/(2*h);
    b =  zeros(n,1);
    b(n) = - (1/h^2-g(n)/(2*h));
    A = diag(dia) + diag(sub,-1) + diag(sup,1);
    y = A\b;
    X = [1;x;2];
    Y = [0;y;1];
    plot(X,Y)
    I = h*(sum(Y)-(Y(1)+Y(end))/2);
    N = N*2;
    res = [res;I];
 end
 I_best = I;
 I_diff=abs(I_best-res);
 I_diff(1:2)./I_diff(2:3)