Numerical Differentiation and Integration

Composite Trapezoidal Rule. To approximate the integral


by sampling at the equally spaced points , for . Notice that and .
function s=traprl(f,a,b,M)
%Input    - f is the integrand input as a string 'f'
%         - a and b are upper and lower limits of integration
%         - M is the number of subintervals
%Output   - s is the trapezoidal rule sum

h=(b-a)/M;
s=0;
for k=1:(M-1)
   x=a+h*k;
   s=s+feval(f,x);
end
s=h*(feval(f,a)+feval(f,b))/2+h*s;
You are given the function for the interval .
  1. Plot the function.
  2. Use the composite trapezoidal rule with 11 sample points to compute an approximation to the integral of taken over by using the MATLAB program given above.
  3. Do the error analysis. Error term for the composite trapezoidal rule is given as;


  4. Calculate the exact value of the integration by using MATLAB. Compare your results for the aspects of integration and error analysis.
  5. Repeat the procedure with increased number of sample points.


2004-12-24