Numerical integration
A definite integral is the area under the graph on [a; b]. When there is no closed-form antiderivative or only measurements are available, the interval is split into n parts with step h = (b − a) / n and simple areas are summed.
- Rectangles:
I ≈ h · Σ f(xi); the midpoint rule has error O(h²), left/right O(h). - Trapezoidal rule:
I ≈ h · ((f0 + fn)/2 + f1 + … + fn−1), error O(h²). - Simpson’s rule:
I ≈ h/3 · (f0 + 4f1 + 2f2 + … + 4fn−1 + fn), n even, error O(h⁴).
Runge error estimate
The integral is computed with steps h and h/2: ε ≈ absolute(Ih/2 − Ih) / (2p − 1), p is the order of the method.
Example
∫ x²·sin(x) dx from 0 to π = π² − 4 ≈ 5.869604. With n = 10 the trapezoidal rule gives about 5.788 (error 0.08), Simpson’s rule about 5.8695 (error about 0.0001).