clear all
for n=1:5
    N=10^n;
    x=1:N;
    sum_formula1 = sum(x);
    approx1 = N^2/2;
    sum_formula2 = sum(x.^2);
    approx2 = N^3/3;
    disp(sprintf('1+2+...+%d = %d ~= %d = %d^2/2',N,sum_formula1,approx1,N))
    disp(sprintf('Relative error = %f\n',abs(sum_formula1-approx1)/sum_formula1))
    disp(sprintf('1^2+2^2+...+%d^2 = %d ~= %d = %d^3/3',N,sum_formula2,approx2,N))
    disp(sprintf('Relative error = %f\n',abs(sum_formula2-approx2)/sum_formula2))
end
