[][src]Function rv::misc::try_quad_eps

pub fn try_quad_eps<F, E>(
    func: F,
    a: f64,
    b: f64,
    eps_opt: Option<f64>
) -> Result<f64, E> where
    F: Fn(f64) -> Result<f64, E>, 

Adaptive Simpson's quadrature with user supplied error tolerance over functions that can fail.

Example

Integrate f: x2 over the interval [0, 1].

use rv::misc::try_quad_eps;

let func = |x: f64| {
    if x > 2.0 {
        Err(String::from("> 2.0"))
    } else {
        Ok(x.powi(2))
    }
};
let q = try_quad_eps(func, 0.0, 1.0, Some(1E-10)).unwrap();

assert!((q - 1.0/3.0).abs() < 1E-10);