Trapezoidal Integration in SepalSolver
The Trapezoidal Rule is a numerical method used to approximate the definiintegral of a function. It works by approximating the region under the graph of the function :math: f(x) as a trapezoid and calculating its area.
Mathematical Definition
To compute the integral over the interval [a, b], we partition the interval into n sub-intervals, each of width h = \cfrac{b-a}{n}. The composite trapezoidal rule is defined as:
SepalSolver Implementation: Manual Approach Writing the algorithm manually allows for a deeper understanding of how the weighting of the endpoints :math:x_0 and :math:x_n differs from the interior points.
Example 1C#
The approximate integral is: 1.9953967383788942
Error Analysis
The error in the trapezoidal rule, often denoted as E_t, is proportional to the square of the step size h. Specifically, for a function that is twice continuously differentiable, the error is:
where \xi is some number in the interval [a, b]. This indicates that the method is :math: O(h^2), meaning that halving the step size h will approximately reduce the error by a factor of four.
| Method | Accuracy Order | Weighting Logic |
|---|---|---|
| Left Riemann | O(h) | Uses f(x_{ i-1}) |
| Trapezoidal | O(h^2) | Average of endpoints |
| Simpson's | O(h^4) | Parabolic fit (1-4-1) |
Example 2C#
The integral of sin(x) from 0 to pi is approximately 2.000000000000283