pub struct Basic<'a, I> { /* private fields */ }Expand description
A non-adaptive Gauss-Kronrod integrator.
The Basic integrator applies a Gauss-Kronrod integration Rule to approximate the
integral of a one-dimensional function. It is non-adaptive: it runs exactly once on the input
function. Thus, it is only suitable for the integration of smooth functions with no problematic
regions in the integration region. If higher accuracy is required then the Adaptive or
AdaptiveSingularity integrators should be used instead.
§Example
Here we present a calculation of the golden ratio $\varphi$ (std::f64::consts::GOLDEN_RATIO)
using the integral representation,
$$
\ln \varphi = \int_{0}^{1/2} \frac{dx}{\sqrt{1 + x^{2}}}
$$
use rint::{Integrand, Limits};
use rint::quadrature::{Basic, Rule};
const PHI: f64 = std::f64::consts::GOLDEN_RATIO;
struct GoldenRatio;
impl Integrand for GoldenRatio {
type Point = f64;
type Scalar = f64;
fn evaluate(&self, x: &Self::Point) -> Self::Scalar {
1.0 / (1.0 + x.powi(2)).sqrt()
}
}
let golden_ratio = GoldenRatio;
let limits = Limits::new(0.0,0.5)?;
let rule = Rule::gk15();
let integral = Basic::new(&golden_ratio, &rule, limits)
.integrate();
let result = integral.result();
let error = integral.error();
let abs_actual_error = (PHI.ln() - result).abs();
let iters = integral.iterations();
assert_eq!(iters, 1);
assert!(abs_actual_error < error);Implementations§
Source§impl<'a, I> Basic<'a, I>
impl<'a, I> Basic<'a, I>
Sourcepub fn integrate(&self) -> IntegralEstimate<I::Scalar>
pub fn integrate(&self) -> IntegralEstimate<I::Scalar>
Integrate the given function.
Applies the user supplied integration rule to obtain an IntegralEstimate, which is the
numerically evaluated estimate of the integral value and error, as well as the number of
function evaluations and integration routine iterations. Note: for the Basic integrator
the number of iterations is 1, and the number of function evaluations for an $n$-point
integration rule is $n$.