0% found this document useful (0 votes)
77 views

TrapComp Function

TrapComp estimates the value of the integral of f(x) from a to b by using the composite trapezoidal rule applied to n equal-length

Uploaded by

Eka Yani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

TrapComp Function

TrapComp estimates the value of the integral of f(x) from a to b by using the composite trapezoidal rule applied to n equal-length

Uploaded by

Eka Yani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

function I = TrapComp(f,a,b,n)

%
% TrapComp estimates the value of the integral of
f(x) from a to b
% by using the composite trapezoidal rule applied
to n equal-length
% subintervals.
%
% I = TrapComp(f,a,b,n), where
%
% f is an anonymous function representing the
integrand,
% a and b are the limits of integration,
% n is the number of equal-length subintervals in
[a,b],
%
% I is the integral estimate.
%
h = (b-a)/n; x = a:h:b;
y = f(x);
I = (y(1) + 2*sum(y(2:end-1)) + y(end))*h/2;

You might also like