Skip to main content

Basic

Struct Basic 

Source
pub struct Basic<'a, I, R, const N: usize> { /* private fields */ }
Expand description

A non-adaptive multi-dimensional integrator.

The Basic integrator applies a fully-symmetric integration Rule to approximate the integral of an $N$-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.

§Example

Here we present a calculation of Catalan’s constant $G$ using the integral representation: $$ G = \int_{0}^{1} \int_{0}^{1} \frac{1}{1 + x^{2} y^{2}} dy dx $$

 use rint::{Integrand, Limits};
 use rint::multi::{Basic, Rule13};

 const G: f64 = 0.915_965_594_177_219_015_054_603_514_932_384_110_774;
 const N: usize = 2;

 struct Catalan;

 impl Integrand for Catalan {
     type Point = [f64; N];
     type Scalar = f64;

     fn evaluate(&self, coordinate: &[f64; N]) -> Self::Scalar {
         let x = coordinate[0];
         let y = coordinate[1];

         1.0 / (1.0 + x.powi(2) * y.powi(2))
     }
 }

 let catalan = Catalan;
 let limits = [Limits::new(0.0,1.0)?,Limits::new(0.0,1.0)?];
 let rule = Rule13::generate();
 let integral = Basic::new(&catalan, &rule, limits)?.integrate();

 let result = integral.result();
 let error = integral.error();
 let abs_actual_error = (G - result).abs();
 let iters = integral.iterations();
 assert_eq!(iters, 1);
 assert!(abs_actual_error < error);

Implementations§

Source§

impl<'a, I, const N: usize, const FINAL: usize, const TOTAL: usize> Basic<'a, I, Rule<N, FINAL, TOTAL>, N>
where I: Integrand<Point = [f64; N]>,

Source

pub fn new( function: &'a I, rule: &'a Rule<N, FINAL, TOTAL>, limits: [Limits; N], ) -> Result<Self, InitialisationError>

Create a new Basic multi-dimensional integrator.

The user first defines a function which is something implementing the Integrand trait and selects a fully-symmetric multi-dimensional integration Rule, rule, to integrate the function in the hypercube formed by the Limits, limits in each of the $N$ integration directions.

§Errors

Will fail if $N < 2$ or $N > 15$. The routines probided in this module are developed for dimensionalities between $2 \le N \le 15$.

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.

Trait Implementations§

Source§

impl<'a, I: Clone, R: Clone, const N: usize> Clone for Basic<'a, I, R, N>

Source§

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

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, R: Debug, const N: usize> Debug for Basic<'a, I, R, N>

Source§

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

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

impl<'a, I: PartialEq, R: PartialEq, const N: usize> PartialEq for Basic<'a, I, R, N>

Source§

fn eq(&self, other: &Basic<'a, I, R, N>) -> 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, R: PartialOrd, const N: usize> PartialOrd for Basic<'a, I, R, N>

Source§

fn partial_cmp(&self, other: &Basic<'a, I, R, N>) -> 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, R: Copy, const N: usize> Copy for Basic<'a, I, R, N>

Source§

impl<'a, I, R, const N: usize> StructuralPartialEq for Basic<'a, I, R, N>

Auto Trait Implementations§

§

impl<'a, I, R, const N: usize> Freeze for Basic<'a, I, R, N>

§

impl<'a, I, R, const N: usize> RefUnwindSafe for Basic<'a, I, R, N>

§

impl<'a, I, R, const N: usize> Send for Basic<'a, I, R, N>
where I: Sync, R: Sync,

§

impl<'a, I, R, const N: usize> Sync for Basic<'a, I, R, N>
where I: Sync, R: Sync,

§

impl<'a, I, R, const N: usize> Unpin for Basic<'a, I, R, N>

§

impl<'a, I, R, const N: usize> UnsafeUnpin for Basic<'a, I, R, N>

§

impl<'a, I, R, const N: usize> UnwindSafe for Basic<'a, I, R, N>

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.