Struct gauss_quad::legendre::GaussLegendre
source · pub struct GaussLegendre {
pub nodes: Vec<f64>,
pub weights: Vec<f64>,
}
Expand description
A Gauss-Legendre quadrature scheme.
These rules can integrate functions on the domain [a, b].
Examples
Basic usage:
// initialize a Gauss-Legendre rule with 3 nodes
let quad = GaussLegendre::init(3);
// numerically integrate x^2 - 1/3 over the domain [0, 1]
let integral = quad.integrate(0.0, 1.0, |x| x * x - 1.0 / 3.0);
assert_abs_diff_eq!(integral, 0.0);
The nodes and weights are computed in O(n)
time,
so large quadrature rules are feasible:
let quad = GaussLegendre::init(1_000_000);
let integral = quad.integrate(-3.0, 3.0, |x| x.sin());
assert_abs_diff_eq!(integral, 0.0);
Fields§
§nodes: Vec<f64>
§weights: Vec<f64>
Implementations§
source§impl GaussLegendre
impl GaussLegendre
sourcepub fn init(deg: usize) -> Self
pub fn init(deg: usize) -> Self
Initializes a Gauss-Legendre quadrature rule of the given degree by computing the needed nodes and weights.
sourcepub fn nodes_and_weights(deg: usize) -> (Vec<f64>, Vec<f64>)
pub fn nodes_and_weights(deg: usize) -> (Vec<f64>, Vec<f64>)
Compute the nodes and weights of a Gauss-Legendre quadrature rule of degree deg
with the algorithm by Ignace Bogaert.
Trait Implementations§
source§impl Clone for GaussLegendre
impl Clone for GaussLegendre
source§fn clone(&self) -> GaussLegendre
fn clone(&self) -> GaussLegendre
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for GaussLegendre
impl Debug for GaussLegendre
source§impl PartialEq for GaussLegendre
impl PartialEq for GaussLegendre
source§fn eq(&self, other: &GaussLegendre) -> bool
fn eq(&self, other: &GaussLegendre) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl StructuralPartialEq for GaussLegendre
Auto Trait Implementations§
impl RefUnwindSafe for GaussLegendre
impl Send for GaussLegendre
impl Sync for GaussLegendre
impl Unpin for GaussLegendre
impl UnwindSafe for GaussLegendre
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
Mutably borrows from an owned value. Read more
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.