pub struct GaussLaguerre { /* private fields */ }
Expand description
A Gauss-Laguerre quadrature scheme.
These rules can perform integrals with integrands of the form x^alpha * e^(-x) * f(x) over the domain [0, ∞).
§Example
Compute the factorial of 5:
// initialize a Gauss-Laguerre rule with 4 nodes
let quad = GaussLaguerre::new(4, 0.0)?;
// numerically evaluate the integral x^5*e^(-x),
// which is a definition of the gamma function of six
let fact_5 = quad.integrate(|x| x.powi(5));
assert_abs_diff_eq!(fact_5, 1.0 * 2.0 * 3.0 * 4.0 * 5.0, epsilon = 1e-12);
Implementations§
Source§impl GaussLaguerre
impl GaussLaguerre
Sourcepub fn new(deg: usize, alpha: f64) -> Result<Self, GaussLaguerreError>
pub fn new(deg: usize, alpha: f64) -> Result<Self, GaussLaguerreError>
Initializes Gauss-Laguerre quadrature rule of the given degree by computing the nodes and weights
needed for the given alpha
parameter.
A rule of degree n can integrate polynomials of degree 2n-1 exactly.
Applies the Golub-Welsch algorithm to determine Gauss-Laguerre nodes & weights. Constructs the companion matrix A for the Laguerre Polynomial using the relation: -n L_{n-1} + (2n+1) L_{n} -(n+1) L_{n+1} = x L_n The constructed matrix is symmetric and tridiagonal with (2n+1) on the diagonal & -(n+1) on the off-diagonal (n = row number). Root & weight finding are equivalent to eigenvalue problem. see Gil, Segura, Temme - Numerical Methods for Special Functions
§Errors
Returns an error if deg
is smaller than 2, or if alpha
is smaller than -1.
Sourcepub fn integrate<F>(&self, integrand: F) -> f64
pub fn integrate<F>(&self, integrand: F) -> f64
Perform quadrature of
x^alpha
* e^(-x) * integrand
(x)
over the domain [0, ∞)
, where alpha
was given in the call to new
.
Sourcepub fn par_integrate<F>(&self, integrand: F) -> f64
Available on crate feature rayon
only.
pub fn par_integrate<F>(&self, integrand: F) -> f64
rayon
only.Same as integrate
but runs in parallel.
Source§impl GaussLaguerre
impl GaussLaguerre
Sourcepub fn nodes(&self) -> GaussLaguerreNodes<'_> ⓘ
pub fn nodes(&self) -> GaussLaguerreNodes<'_> ⓘ
Returns an iterator over the nodes of the quadrature rule.
Sourcepub fn weights(&self) -> GaussLaguerreWeights<'_> ⓘ
pub fn weights(&self) -> GaussLaguerreWeights<'_> ⓘ
Returns an iterator over the weights of the quadrature rule.
Sourcepub fn iter(&self) -> GaussLaguerreIter<'_> ⓘ
pub fn iter(&self) -> GaussLaguerreIter<'_> ⓘ
Returns an iterator over the node-weight pairs of the quadrature rule.
Sourcepub fn as_node_weight_pairs(&self) -> &[(Node, Weight)]
pub fn as_node_weight_pairs(&self) -> &[(Node, Weight)]
Returns a slice of all the node-weight pairs of the quadrature rule.
Sourcepub fn into_node_weight_pairs(self) -> Vec<(Node, Weight)>
pub fn into_node_weight_pairs(self) -> Vec<(Node, Weight)>
Converts the quadrature rule into a vector of node-weight pairs.
This function just returns the underlying vector without any computation or cloning.
Trait Implementations§
Source§impl Clone for GaussLaguerre
impl Clone for GaussLaguerre
Source§fn clone(&self) -> GaussLaguerre
fn clone(&self) -> GaussLaguerre
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for GaussLaguerre
impl Debug for GaussLaguerre
Source§impl<'de> Deserialize<'de> for GaussLaguerre
impl<'de> Deserialize<'de> for GaussLaguerre
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'a> IntoIterator for &'a GaussLaguerre
impl<'a> IntoIterator for &'a GaussLaguerre
Source§impl IntoIterator for GaussLaguerre
impl IntoIterator for GaussLaguerre
Source§impl PartialEq for GaussLaguerre
impl PartialEq for GaussLaguerre
Source§impl Serialize for GaussLaguerre
impl Serialize for GaussLaguerre
impl StructuralPartialEq for GaussLaguerre
Auto Trait Implementations§
impl Freeze for GaussLaguerre
impl RefUnwindSafe for GaussLaguerre
impl Send for GaussLaguerre
impl Sync for GaussLaguerre
impl Unpin for GaussLaguerre
impl UnwindSafe for GaussLaguerre
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.