function int=trap1(f,a,b) 
% Trapezoidal Method 
% This function estimates the integral of equation 'f' between a and b.
% Input    - f is the integrand input as a string function handle i.e. @(x) 
%          - a and b are upper and lower limits of integration 
% Output   - int is the integral
 
if a>b                                  % b must be greater than a
error('b must be greater than a') 
end 
h=(b-a);                                % Difference between a and b.
int=h*(feval(f,a)+feval(f,b))/2;        % Formula for trapezoidal method.

end