Expand description
§differential-equations
A Rust library for solving ODE, DAE, DDE, and SDE initial value problems.
§Overview
This library provides numerical solvers for:
- Ordinary Differential Equations (ODE): initial value problems, fixed/adaptive step, event detection, flexible output
- Boundary Value Problems (BVP): problems with boundary conditions at both ends of the interval
- Differential Algebraic Equations (DAE): equations in the form M f’ = f(t,y) where M can be singular
- Delay Differential Equations (DDE): constant/state-dependent delays, same features as ODE
- Stochastic Differential Equations (SDE): drift-diffusion, user RNG, same features as ODE
§Feature Flags
nalgebra: Enable nalgebra matrix and vector statesnum-complex: Enable complex number statesndarray: Enable ndarray array statesfaer: Enable faer matrix statespolars: Enable convertingSolutionto a Polars DataFrame withSolution::to_polars()serde: Enable solution serialization and deserialization
§Example (ODE)
use differential_equations::prelude::*;
pub struct LinearEquation {
pub a: f64,
pub b: f64,
}
impl ODE for LinearEquation {
fn diff(&self, _t: f64, y: &f64, dydt: &mut f64) {
*dydt = self.a + self.b * *y;
}
}
fn main() {
let system = LinearEquation { a: 1.0, b: 2.0 };
let t0 = 0.0;
let tf = 1.0;
let y0 = 1.0;
let solver = ExplicitRungeKutta::dop853().rtol(1e-8).atol(1e-6);
let solution = match IVP::ode(&system, t0, tf, y0).method(solver).solve() {
Ok(sol) => sol,
Err(e) => panic!("Error: {:?}", e),
};
for (t, y) in solution.iter() {
println!("t: {:.4}, y: {:.4}", t, *y);
}
}Alternatively, for simple problems you can use a closure:
use differential_equations::prelude::*;
fn main() {
let t0 = 0.0;
let tf = 1.0;
let y0 = 1.0;
let solution = IVP::ode_from_fn(|t, y, dydt| *dydt = t * y, t0, tf, y0)
.method(ExplicitRungeKutta::dop853().rtol(1e-8).atol(1e-6))
.solve()
.unwrap();
}§License
Copyright 2025 Ryan D. Gast
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KINeither express or implied.
See the License for the specific language governing permissions and
limitations under the License.Modules§
- bvp
- Boundary value problem builder API.
- control
- Control flow flags used by solvers, events, and output callbacks.
- dae
- Differential Algebraic Equations (DAE) Module
- dde
- Delay Differential Equations (DDE) module.
- derive
- error
- Errors for Differential Equations Crate
- interpolate
- Interpolation utilities used by solvers and output handlers.
- ivp
- Unified builder for initial value problems.
- linalg
- Linear algebra types and utilities.
- methods
- Numerical Methods for Differential Equations
- ode
- Ordinary Differential Equations (ODE) module.
- prelude
- Library Prelude
- sde
- Stochastic Differential Equations (SDE) module.
- solout
- Solout trait and common implementations for controlling the output of differential equation solvers.
- solution
- Solution container for differential equation solvers.
- stats
- Statistics and performance tracking for Numerical methods
- status
- Status for solving differential equations
- tableau
- Butcher Tableau
- tolerance
- Tolerance enum for adaptive step size control
- traits
- Defines Generics for the library. Includes generics for the floating point numbers.
- utils
- Utility functions for the differential equation solvers
Macros§
- banded_
matrix - Create a banded matrix by specifying diagonals. Size and bands are inferred. Usage: banded_matrix!( 0 => [d0…], 1 => [d1…], -1 => [u1…], k => [..], … )
- matrix
- Create a full dense matrix from rows. Usage: