Create a function using matlab to compute integral numerically using Simpson ’ s 3/8 Rule, that complete the integration with either Simpson ’ s 1 / 3 Rule or Trapezoidal Rule ( whichever may be possible ) :
function integral = mysimpsons 38 ( x , f )
% Integrates numerically using Simpson's 3 / 8 Rule and completes the integration with
% either Simpson ’ s 1 / 3 or Trapezoidal Rule as applicable.
% Input: % = = = = =
% x = vector of independent variable values
% f = vector of corresponding function values % Output:
% = = = = = = =
% integral = numerically computed integral value
Integrate the following using both MATLAB ’ s integral ( ) and mysimpsons 38 ( ) and discuss your
comparison:
limits of integration from 2 to 1 ( x + 1 / x )² dx