function [Value,Appr1,Appr2,Appr3] = integral(a,b,n)
% Integrate exp(x) from a to b using n steps; uses several methods.

x = linspace (a,b,n+1);           % grid for x
f = exp(x);                     % grid for f

% Our integration functions.
Value = IntegralValue(a,b);
Appr1 = IntegralAppr1(x,f,n);
Appr2 = IntegralAppr2(x,f,n);
Appr3 = IntegralAppr3(x,f,n);

fprintf ('%2.10f\n', Value);
fprintf ('%2.10f\n', Appr1 );
fprintf ('%2.10f\n', Appr2);
fprintf ('%2.10f\n', Appr3);


function value = IntegralValue(a,b)             % Subfunction
% calculate the real value of function
 
function value = IntegralAppr1(x,f,n)           % Subfunction
%left-rectangular fitting method

function value = IntegralAppr2(x,f,n)           % Subfunction
% right-rectangular fitting method

function value = IntegralAppr3(x,f,n)           % Subfunction
% Trapezoid fitting
