Expand description
§differential-equations
A Rust library for solving various types of differential equations.
§Overview
This library provides numerical solvers for different classes of differential equations:
- Ordinary Differential Equations (ODE): Stable
- Initial value problems (IVP)
- Fixed and adaptive step methods
- Event detection
- Customizable output control
§Feature Flags
polars: Enable converting Solution to Polars DataFrame usingSolution.to_polars()
§Example (ODE)
use differential_equations::ode::*;
use nalgebra::{SVector, vector};
pub struct LinearEquation {
pub a: f64,
pub b: f64,
}
impl ODE<f64, 1, 1> for LinearEquation {
fn diff(&self, _t: f64, y: &SVector<f64, 1>, dydt: &mut SVector<f64, 1>) {
dydt[0] = self.a + self.b * y[0];
}
}
fn main() {
let system = LinearEquation { a: 1.0, b: 2.0 };
let t0 = 0.0;
let tf = 1.0;
let y0 = vector![1.0];
let ivp = IVP::new(system, t0, tf, y0);
let mut solver = DOP853::new().rtol(1e-8).atol(1e-6);
let solution = match ivp.solve(&mut solver) {
Ok(sol) => sol,
Err(e) => panic!("Error: {:?}", e),
};
for (t, y) in solution.iter() {
println!("t: {:.4}, y: {:.4}", t, y[0]);
}
}§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 KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.Modules§
- interpolate
- Interpolation Methods for the IVP struct when solving the system.
- ode
- Ordinary Differential Equations (ODE) Module
- traits
- Defines Generics for the library. Includes generics for the floating point numbers and state vectors.
Macros§
- adaptive_
dense_ runge_ kutta_ method - Macro to create a Runge-Kutta solver with dense output capabilities
- adaptive_
runge_ kutta_ method - Macro to create an adaptive Runge-Kutta solver with embedded error estimation and interpolation vs cubic Hermite interpolation.
- matrix
- Construct a fixed-size matrix directly from data.
- runge_
kutta_ method - Macro to create a Runge-Kutta solver from a Butcher tableau with fixed-size arrays
- vector
- Construct a fixed-size column vector directly from data.