Skip to main content

Basic

Struct Basic 

Source
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>
where I: Integrand<Point = f64>,

Source

pub const fn new(function: &'a I, rule: &'a Rule, limits: Limits) -> Self

Create a new Basic integrator.

The user first defines a function which is something implementing the Integrand trait and selects a Gauss-Kronrod quadrature Rule, rule, to integrate the function with between the integration Limits, limits.

Source

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$.

Source

pub const fn limits(&self) -> Limits

Return the integration Limits.

Trait Implementations§

Source§

impl<'a, I: Clone> Clone for Basic<'a, I>

Source§

fn clone(&self) -> Basic<'a, I>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, I: Debug> Debug for Basic<'a, I>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, I: PartialEq> PartialEq for Basic<'a, I>

Source§

fn eq(&self, other: &Basic<'a, I>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, I: PartialOrd> PartialOrd for Basic<'a, I>

Source§

fn partial_cmp(&self, other: &Basic<'a, I>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, I: Copy> Copy for Basic<'a, I>

Source§

impl<'a, I> StructuralPartialEq for Basic<'a, I>

Auto Trait Implementations§

§

impl<'a, I> Freeze for Basic<'a, I>

§

impl<'a, I> RefUnwindSafe for Basic<'a, I>
where I: RefUnwindSafe,

§

impl<'a, I> Send for Basic<'a, I>
where I: Sync,

§

impl<'a, I> Sync for Basic<'a, I>
where I: Sync,

§

impl<'a, I> Unpin for Basic<'a, I>

§

impl<'a, I> UnsafeUnpin for Basic<'a, I>

§

impl<'a, I> UnwindSafe for Basic<'a, I>
where I: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.