pub struct TanhSinhEngine {
pub tolerance: f64,
pub max_levels: usize,
/* private fields */
}Expand description
Integrates over a finite interval with the substitution x = tanh(π/2 · sinh t) (Takahasi and
Mori), which makes the transformed integrand decay double exponentially and lets the
trapezoid rule in t converge exponentially fast, even for integrable endpoint singularities
such as 1/√x or ln x. The step is halved each level (reusing earlier points) until two
successive estimates agree to the tolerance.
Abscissae are formed from the endpoint distance (b − a)/(1 + e^{2u}). Points whose absolute
position rounds onto an endpoint are skipped by CanIntegrate1D::integrate; for
singularities at endpoints away from zero (such as 1/√(1 − x²)), use
TanhSinhEngine::integrate_with_complement, which also passes that exact distance so the
integrand can avoid the cancellation in 1 − x.
Fields§
§tolerance: f64Relative tolerance between successive levels (default 1e-12).
max_levels: usizeMaximum number of step halvings (default 10, i.e. h = 2⁻¹⁰).
Implementations§
Source§impl TanhSinhEngine
impl TanhSinhEngine
Sourcepub fn new(lower_bound: f64, upper_bound: f64) -> Self
pub fn new(lower_bound: f64, upper_bound: f64) -> Self
A tanh-sinh integrator over [lower_bound, upper_bound] with the default tolerance and
level limit.
use lib_jsl_integration::tanh_sinh::TanhSinhEngine;
// ∫₀¹ ln(x) dx = −1, with a logarithmic singularity at x = 0.
let (value, _) = TanhSinhEngine::new(0.0, 1.0).integrate_with_error(f64::ln).unwrap();
assert!((value + 1.0).abs() < 1e-12);Sourcepub fn integrate_with_error<F: Fn(f64) -> f64>(
&self,
f: F,
) -> Result<(f64, f64), ErrorsJSL>
pub fn integrate_with_error<F: Fn(f64) -> f64>( &self, f: F, ) -> Result<(f64, f64), ErrorsJSL>
The integral together with the difference between the last two levels (an error estimate, typically very pessimistic since convergence is exponential).
Sourcepub fn integrate_with_complement<F: Fn(f64, f64) -> f64>(
&self,
f: F,
) -> Result<(f64, f64), ErrorsJSL>
pub fn integrate_with_complement<F: Fn(f64, f64) -> f64>( &self, f: F, ) -> Result<(f64, f64), ErrorsJSL>
Integrates f(x, c), where c is the signed offset of x from its nearer endpoint
(x − a in the lower half, x − b in the upper half), computed without rounding. Returns
the integral and an error estimate.