Crate numint

Source
Expand description

githubcrates-iodocs-rs

ODE solvers and numerical integration in Rust.

§Overview

At its core, this crate is designed to work with scalar-valued, vector-valued, and matrix-valued ordinary differential equations.

ODE TypeFunction Signature
scalar-valued$$\frac{dy}{dt}=f(t,y)\quad\quad\left(f:\mathbb{R}\times\mathbb{R}\to\mathbb{R}\right)$$
vector-valued$$\frac{d\mathbf{y}}{dt}=\mathbf{f}(t,\mathbf{y})\quad\quad\left(\mathbf{f}:\mathbb{R}\times\mathbb{R}^{p}\to\mathbb{R}^{p}\right)$$
matrix-valued$$\frac{d\mathbf{Y}}{dt}=\mathbf{F}(t,\mathbf{Y})\quad\quad\left(\mathbf{F}:\mathbb{R}\times\mathbb{R}^{p\times r}\to\mathbb{R}^{p\times r}\right)$$

§Initial Value Problem (IVP) Solver

The solve_ivp() function is a general purpose IVP solver with the following features:

  • it accepts a generic parameter defining the integration method
  • it can be used for scalar-valued, vector-valued, and matrix-valued problems (this is accomplished by accepting another generic parameter defining the type of the ODE state)
    • any types of vectors or matrices can be used with this function as long as they implement the OdeState trait (see The OdeState trait section below).

§Integration Methods

§Runge-Kutta Methods

Integration MethodOrderImplementation
Euler Method2Euler
Midpoint Method2RK2
Heun’s Second-Order Method2RK2Heun
Ralston’s Second-Order Method2RK2Ralston
Classic (Kutta’s) Third-Order method2RK3
Heun’s Third-Order Method3RK3Heun
Ralston’s Third-Order Method3RK3Ralston
Strong Stability Preserving Runge-Kutta Third-Order Method3SSPRK3
(Classic) Runge-Kutta Fourth-Order Method4RK4
Ralston’s Fourth-Order Method4RK4Ralston
3/8 Rule Fourth Order Method4RK438

§The OdeState trait

To allow users to use their favorite vector and matrix representations, this crate defines the OdeState trait. As long as the ODE state trait is implemented for a type, you can use that type to define an ODE to be solved using this crate.

This crate already defines the OdeState for a variety of different types from the standard library, nalgebra, and ndarray. For a full list, refer to the OdeState documentation. This crate also provides macros to automate the implementation of the OdeState trait for types that implement linalg_traits::Scalar, linalg_traits::Vector, or linalg_traits::Matrix traits.

MacroDescription
impl_ode_state_for_scalar!Implement OdeState for a scalar type already implementing the linalg_traits::Scalar trait.
impl_ode_state_for_dvector!Implement OdeState for a dynamically-sized vector type already implementing the linalg_traits::Vector trait.
impl_ode_state_for_svector!Implement OdeState for a statically-sized vector type already implementing the linalg_traits::Vector trait.
impl_ode_state_for_dmatrix!Implement OdeState for a dynamically-sized matrix type already implementing the linalg_traits::Matrix trait.
impl_ode_state_for_smatrix!Implement OdeState for a statically-sized matrix type already implementing the linalg_traits::Matrix trait.

Macros§

impl_ode_state_for_dmatrix
Macro to implement the OdeState trait for dynamically-sized matrix types.
impl_ode_state_for_dvector
Macro to implement the OdeState trait for dynamically-sized vector types.
impl_ode_state_for_scalar
Macro to implement the OdeState trait for scalar types.
impl_ode_state_for_smatrix
Macro to implement the OdeState trait for statically-sized matrix types.
impl_ode_state_for_svector
Macro to implement the crate::OdeState trait for statically-sized vector types.

Structs§

Euler
Euler (first-order) method.
RK2
Midpoint (second-order) method.
RK3
Classic (Kutta’s) third-order method.
RK4
Classic Runge-Kutta fourth-order method.
RK2Heun
Heun’s second-order method.
RK2Ralston
Ralston’s second-order method.
RK3Heun
Heun’s third-order method.
RK3Ralston
Ralston’s third-order method.
RK4Ralston
Ralston’s fourth-order method.
RK438
3/8 rule fourth-order method.
SSPRK3
Strong stability preserving Runge-Kutta third-order method.
Solution
Solution of an ordinary differential equation dy/dt = f(t,y).

Enums§

StateIndex
Index for indexing into ODE state.

Traits§

IntegrationMethod
Trait defining an integration method.
OdeState
Trait defining an ODE solver state (i.e. the dependent variable in an ODE).

Functions§

solve_ivp
Solve an initial value problem.