function inter2 = Trap2(f,a,b,n)
% Composite Trapezium Rule 
% This function estimates the integral of 'f' between 'a' and 'b' with
% 'n' number of trapeziums.

% Input    - f is the integrand input as a string 'f' 
% Input    - a and b are upper and lower limits of integration 
% Output   - inter2 is the trapezoidal rule sum

numbofsections = n;
numbofn = size(n);
column = numbofn(1,2);
for column = 1:column
n = numbofsections(1,column);
h = (b-a)./n;

x=linspace(a,b,n+1);
y_val(1,n+1) = NaN;
for i=1:n+1
y_val(1,i) = feval(f,x(i));
end

inter2(1,column) = h*sum(y_val(2:end-1)) + (y_val(1)+y_val(end))*h/2;

end
end