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 , we partition the interval into sub-intervals, each of width . 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.9993
Error Analysis
The error in the trapezoidal rule, often denoted as , is proportional to the square of the step size . Specifically, for a function that is twice continuously differentiable, the error is:
where is some number in the interval . This indicates that the method is :math: O(h^2), meaning that halving the step size will approximately reduce the error by a factor of four.
| Method | Accuracy Order | Weighting Logic |
|---|---|---|
| Left Riemann | Uses | |
| Trapezoidal | Average of endpoints | |
| Simpson's | Parabolic fit (1-4-1) |
Example 2C#
The integral of sin(x) from 0 to pi is approximately 2.0000