pub struct RombergEngine {
pub tolerance: f64,
pub max_levels: usize,
/* private fields */
}Expand description
Romberg integration: trapezoid estimates with 1, 2, 4, … panels, combined by Richardson
extrapolation R(k, j) = R(k, j−1) + (R(k, j−1) − R(k−1, j−1)) / (4^j − 1) to cancel the even
powers of the step in the Euler-Maclaurin error expansion. Converges very fast for smooth
integrands (row k is exact for polynomials of degree 2k + 1); for non-smooth or periodic
integrands use an adaptive or plain trapezoid rule instead.
Fields§
§tolerance: f64Relative tolerance between the last two diagonal entries (default 1e-12).
max_levels: usizeMaximum number of panel doublings (default 20, about a million evaluations).
Implementations§
Source§impl RombergEngine
impl RombergEngine
Sourcepub fn new(lower_bound: f64, upper_bound: f64) -> Self
pub fn new(lower_bound: f64, upper_bound: f64) -> Self
A Romberg integrator over [lower_bound, upper_bound] with the default tolerance and
level limit.
use lib_jsl_integration::romberg::RombergEngine;
let engine = RombergEngine::new(0.0, std::f64::consts::PI);
let (value, error_estimate, levels) = engine.integrate_with_error(f64::sin).unwrap();
assert!((value - 2.0).abs() < 1e-12 && error_estimate < 1e-10);
assert!(levels <= 8); // at most 2⁸ + 1 = 257 function evaluationsSourcepub fn tableau<F: Fn(f64) -> f64>(
&self,
f: F,
levels: usize,
) -> Result<Vec<Vec<f64>>, ErrorsJSL>
pub fn tableau<F: Fn(f64) -> f64>( &self, f: F, levels: usize, ) -> Result<Vec<Vec<f64>>, ErrorsJSL>
The full Romberg tableau with levels + 1 rows: table[k][0] is the trapezoid rule with
2^k panels and table[k][j] its j-th Richardson extrapolation, accurate to
O(h^{2j+2}). The diagonal table[k][k] is what RombergEngine::integrate_with_error
returns. Useful for studying how extrapolation removes the error terms.
use lib_jsl_integration::romberg::RombergEngine;
let t = RombergEngine::new(0.0, 1.0).tableau(|x| x.powi(3), 2).unwrap();
assert_eq!(t[0][0], 0.5); // one-panel trapezoid: (f(0) + f(1)) / 2
assert!((t[1][1] - 0.25).abs() < 1e-15); // the first extrapolation is Simpson's rule, exact for cubics