Last modified: December 22, 2024

This article is written in: 🇺🇸

Trapezoidal Rule

Mathematical Formulation

The Trapezoidal Rule operates by assuming the region under the graph of the function as a trapezoid, then calculating its area.

Given a function $f(x)$ defined over an interval $[a, b]$, the approximation of the integral using the Trapezoidal Rule is expressed as:

$$ \frac{b - a}{2} [f(a) + f(b)] $$ $$I = \sum_{i=0}^{n-1} \frac{f(x_{i+1}) + f(x_{i})}{2} h$$

trapezoid

Let $h$ represent the width of the interval, i.e., $h = \frac{b-a}{N -1}$, where $N$ is the number of points.

The total area (or the integral) can be approximated as:

$$\int_a^b f(x)dx \approx h\sum_{k=1}^{N} \frac{f(x_{k-1})+f(x_k)}{2}$$

Algorithm Steps

  1. Partition the interval $[a, b]$ into several subintervals.
  2. Calculate the function values at the end points of each subinterval.
  3. Apply the Trapezoidal Rule formula to each subinterval.
  4. Aggregate the results from each subinterval to derive the total integral approximation.

Example

Take the function $f(x) = x^2$ for instance.

  1. Choose $a = 0$ and $b = 2$, and split this interval into 2 equal subintervals.
  2. Compute the function values at $x = 0$, $x = 1$, and $x = 2$. Thus, $f(0) = 0$, $f(1) = 1$, and $f(2) = 4$.
  3. Apply the Trapezoidal Rule formula to the interval [0, 1]: $\frac{b - a}{2} [f(a) + f(b)] = \frac{1 - 0}{2} [f(0) + f(1)] = 0.5 * (0 + 1) = 0.5$.
  4. Similarly, apply the formula to the interval [1, 2]: $\frac{b - a}{2} [f(a) + f(b)] = \frac{2 - 1}{2} [f(1) + f(2)] = 0.5 * (1 + 4) = 2.5$.
  5. The total integral approximation is the sum of these values, i.e., $0.5 + 2.5 = 3$.

Advantages

Limitations

Table of Contents

  1. Trapezoidal Rule
  2. Mathematical Formulation
  3. Algorithm Steps
  4. Example
  5. Advantages
  6. Limitations