Trapezoidal Method
Comments0this wiki
The Trapezoidal Method, also known as the Trapezoidal Rule, is an approximation method of numerical integration, and is a member of the closed type group of the Newton-Cotes formulae.
|
Background
Edit
The Trapezoidal Method is used to approximate the values of definite integrals, defined as the area under the graph of the function
with respect to
(meaning if
is negative, then
has a negative area), over the compact interval
where
<
. Examples of definite integrals are
and
.
The Trapezoidal Method belongs to a group of numerical integration formulae called the Newton-Cotes formulae, named after Isaac Newton and Roger Cotes. Other formulae belonging to the group (for the closed type, of which the Trapezoidal Method is one) include the Simpson's 1/3 and 3/8 Rules, and the Boole's Rule.
There are two types of applications of the Trapezoidal Method. One is for evalutaion at only two points, and the other is for evalutaion at multiple points -- which is called the Composite Trapezoidal Method, For this particular discussion, we will focus on the latter.
Applications
Edit
There are arguably countless applications for integration throughout the many fields of engineering. Among the more common examples of which include finding the velocity of a body from an acceleration function, and finding the displacement of a body from a velocity function. The use of the Trapezoidal Method and other approximation methods for integration could prove to be an effective tool in such applications.
Method
Edit
Consider the definite integral
.
We assume that
is continuous on
into
subintervals of equal length, defined as
,
and using the
points
,
after which we can compute for f(x) at these points.
We then form
number of trapezoids by drawing straight line segments in between the points
and
for
, as shown below.

Added by TrapezoidalMethod
Recalling the formula in solving for the area of a trapezoid,
.
To solve for the area between two subintervals under the curve, defined as
, we replace
and
with
and
for
, and replace
with
, thus
.

Added by TrapezoidalMethod
To solve for the entire area under the curve, defined as
, we simply get the sum of all the areas between the subintervals.
Expanding the equation,
and further simplifying it, we get
.
Example
Edit
Use the trapezoidal rule with
to estimate
.
Compute also for percentage of error.
Solution
For
, we have
We compute for the values of
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Therefore,
To solve for the percentage of error, we compute for the exact value of the integral.
Percentage of error can then be computed using the formula
.
Substituting the values, we get:
Implementations
Edit
C++
Edit
double trapezoidal(double l, double u, int n)
{
double interval, timestwo, sum;
double x[n+1], y[n+1];
int ctr1, ctr2, ctr3;
//computes for the interval
interval = (u - l) / n;
//sets the values for x and f(x)
for(ctr1 = 0; ctr1 <= n; ctr1++)
{
x[ctr1] = l;
y[ctr1] = function(l);
l = l + interval;
}
//displays the x and f(x) values
cout << "\nx\tf(x)\n----------------\n";
for(ctr2 = 0; ctr2 <= n; ctr2++)
cout << x[ctr2] << "\t" << y[ctr2] << "\n";
//adds the values in between the lower and upper limits
for(ctr3 = 1; ctr3 < n; ctr3++)
{
sum = sum + y[ctr3];
}
//computes for the entire approximation
sum = ((sum * 2) + y[0] + y[n]) * (interval / 2);
return sum;
}
Java
Edit
private static double Integrate(double sizeofPanels, double yTable[]){
double firstY = yTable[0];
double lastY = yTable[yTable.length-1];
System.out.println("");
double middle = 0.0;
double middleValues = 0.0;
for(int i=1; i<yTable.length-1; i++)
middleValues = middleValues + yTable[i];
middle = 2*middleValues;
double integratedF = (sizeofPanels/2)*(firstY + middle + lastY);
return integratedF;
}
References
Edit
Trapezoidal rule - Wikipedia, the free encyclopedia
Trapezoidal Rule: Integration - Holistic Numerical Methods Institute