Using the program for the trapezoidal rule given in the text
Solution
Following matlab code should give the integral values, errors for different n :
Use [a,b,c] = time() to get the required arrays
function [ integralValue, AbsoluteError, RelativeError ] = time()
     Ns = [2,4,8,16,32,64,128,256,512];
     integralValue = [];
     AbsoluteError = [];
     RelativeError = [];
     for index=1:size(Ns,2)
         N = Ns(1,index);
         a = 0;
         b = 1.0;
         h = (b - a)/N;
         answer = 0;
         xk = a;
         xkplus1 = a + h;
         for i=0:N-1
             answer = answer + ( xk^(2.5) + xkplus1^(2.5) );
             xk = xkplus1;
             xkplus1 = xkplus1 + h;
         end
         intgVal = answer*(h/2);
         integralValue = [ integralValue intgVal ];
         AbsoluteError = [ AbsoluteError abs( intgVal - 2/7 ) ];
         RelativeError = [ RelativeError abs( intgVal - 2/7 )*3.5 ];
     end
 end

