Send
Close Add comments:
(status displays here)
Got it! This site "robinsnyder.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website. Note: This appears on each machine/browser from which this site is accessed.
Area using trapezoidal method
1. Area using trapezoidal method
In general, discrete mathematics is much more relevant in building software than is continuous mathematics.
2. Integral calculus
The purpose of
integral calculus is to calculate the length along a line, the area under a curve, the volume in a surface.
The area under function
f(x) from
x1 to
x2 can be expressed in integral calculus as follows.
3. Discrete curve approximation
horizontal values: xi
vertical values: f(xi)
4. Integral calculus
Integral calculus is used to calculate the area under a curve.
Discrete approximation: trapezoidal method
Area
= 0.5*(f(x
i)+f(x
i+1))*(x
i+1-x
i)
= 0.5*(f(x
i)+f(x
i+1))*dx
5. Trapezoidal method
The trapezoidal method is used to approximate the area under the curve by dividing the curve into trapezoids and adding the area of each trapezoid.
6. Summary
The trapezoidal method approximates the area under a curve by approximating the integral
with the explicit summation
7. More details
Consider a sequence of
n+1 points
(xi, f(xi)) where
0 ≤ i ≤ n. Two adjacent points are
(xi, f(xi)) and
(xi+1, f(xi+1)) where
0 ≤ i < n .
The area under the trapezoid formed by these two points is
(xi+1-xi) * (f(xi+1)+f(xi)) / 2.0 .
8. Algorithm
So the algorithm to determine the area under the curve is as follows.
Set the
area to
0.0
FOR EACH adjacent pair of points
(x1,f1) and
(x2,f2) DO
add
(x2-x1)*(f2+f1)/2.0 to the
area
END
In cases where the differences between each of the
xi and
xi+1 is the same, the algorithm may be simplified to the following.
Set the
area to
0.0
Set
dx to
x2-x1
FOR EACH adjacent pair of points
(x1,f1) and
(x2,f2) DO
add
dx*(f2+f1)/2.0 to the
area
END
In order to improve the machine performance of the algorithm, the multiplication by
(x2-x1) and the division by
2.0 need be done only once.
Set the
area to
0.0
FOR EACH adjacent pair of points
(x1,f1) and
(x2,f2) DO
add
f2+f1 to the
area
END
Multiply the
area by
(x2-x1)/2.0
What is the purpose of the trapezoidal method? Give a specific example.
9. End of page