Skip to main content

MidpointIntegrationEngine

Struct MidpointIntegrationEngine 

Source
pub struct MidpointIntegrationEngine { /* private fields */ }
Expand description

The composite midpoint rule: ∫ₐᵇ f ≈ h Σ f(a + (i + ½) h) over n panels of width h = (b − a)/n, sampling f at the centre of each panel.

Second order (the rule minus the integral is −(b − a) h² f''(ξ) / 24: half the trapezoid rule’s error, with the opposite sign), exact for straight lines, and open: it never evaluates f at the endpoints, so it tolerates integrable endpoint singularities (slowly).

Implementations§

Source§

impl MidpointIntegrationEngine

Source

pub fn new( number_of_points: usize, lower_bound: f64, upper_bound: f64, cache_x_points: bool, ) -> Self

An engine using number_of_points samples on [lower_bound, upper_bound] (the number of panels). With cache_x_points, the sample points are computed once and reused by every call to integrate.

Source

pub fn set_number_of_points(&mut self, x: usize)

Changes the number of samples (refreshing the cache, if enabled).

Trait Implementations§

Source§

impl CanIntegrate1D for MidpointIntegrationEngine

Source§

fn integrate<F>(&self, f: F) -> Result<f64, ErrorsJSL>
where F: Fn(f64) -> f64,

Approximates ∫ₐᵇ f(x) dx.
Source§

fn set_lower_bound(&mut self, x: f64)

Sets the lower bound a.
Source§

fn set_upper_bound(&mut self, x: f64)

Sets the upper bound b.

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.