differential_equations/lib.rs
1//! # differential-equations
2//!
3//! A Rust library for solving ODE, DAE, DDE, and SDE initial value problems.
4//!
5//! [](https://github.com/Ryan-D-Gast/differential-equations)
6//! [](https://docs.rs/differential-equations)
7//!
8//! ## Overview
9//!
10//! This library provides numerical solvers for:
11//!
12//! - **[Ordinary Differential Equations (ODE)](crate::ode)**: initial value problems, fixed/adaptive step, event detection, flexible output
13//! - **[Boundary Value Problems (BVP)](crate::bvp)**: problems with boundary conditions at both ends of the interval
14//! - **[Differential Algebraic Equations (DAE)](crate::dae)**: equations in the form M f' = f(t,y) where M can be singular
15//! - **[Delay Differential Equations (DDE)](crate::dde)**: constant/state-dependent delays, same features as ODE
16//! - **[Stochastic Differential Equations (SDE)](crate::sde)**: drift-diffusion, user RNG, same features as ODE
17//!
18//! ## Feature Flags
19//!
20//! - `nalgebra`: Enable nalgebra matrix and vector states
21//! - `num-complex`: Enable complex number states
22//! - `ndarray`: Enable ndarray array states
23//! - `faer`: Enable faer matrix states
24//! - `polars`: Enable converting `Solution` to a Polars DataFrame with `Solution::to_polars()`
25//! - `serde`: Enable solution serialization and deserialization
26//!
27//! ## Example (ODE)
28//!
29//! ```rust
30//! use differential_equations::prelude::*;
31//!
32//! pub struct LinearEquation {
33//! pub a: f64,
34//! pub b: f64,
35//! }
36//!
37//! impl ODE for LinearEquation {
38//! fn diff(&self, _t: f64, y: &f64, dydt: &mut f64) {
39//! *dydt = self.a + self.b * *y;
40//! }
41//! }
42//!
43//! fn main() {
44//! let system = LinearEquation { a: 1.0, b: 2.0 };
45//! let t0 = 0.0;
46//! let tf = 1.0;
47//! let y0 = 1.0;
48//! let solver = ExplicitRungeKutta::dop853().rtol(1e-8).atol(1e-6);
49//! let solution = match IVP::ode(&system, t0, tf, y0).method(solver).solve() {
50//! Ok(sol) => sol,
51//! Err(e) => panic!("Error: {:?}", e),
52//! };
53//!
54//! for (t, y) in solution.iter() {
55//! println!("t: {:.4}, y: {:.4}", t, *y);
56//! }
57//! }
58//! ```
59//!
60//! Alternatively, for simple problems you can use a closure:
61//!
62//! ```rust
63//! use differential_equations::prelude::*;
64//!
65//! fn main() {
66//! let t0 = 0.0;
67//! let tf = 1.0;
68//! let y0 = 1.0;
69//!
70//! let solution = IVP::ode_from_fn(|t, y, dydt| *dydt = t * y, t0, tf, y0)
71//! .method(ExplicitRungeKutta::dop853().rtol(1e-8).atol(1e-6))
72//! .solve()
73//! .unwrap();
74//! }
75//! ```
76//!
77//! ## License
78//!
79//! ```text
80//! Copyright 2025 Ryan D. Gast
81//!
82//! Licensed under the Apache License, Version 2.0 (the "License");
83//! you may not use this file except in compliance with the License.
84//! You may obtain a copy of the License at
85//!
86//! http://www.apache.org/licenses/LICENSE-2.0
87//!
88//! Unless required by applicable law or agreed to in writing, software
89//! distributed under the License is distributed on an "AS IS" BASIS,
90//! WITHOUT WARRANTIES OR CONDITIONS OF ANY KINeither express or implied.
91//! See the License for the specific language governing permissions and
92//! limitations under the License.
93//! ```
94
95// Prelude & User-Facing API
96pub mod prelude;
97
98// Numerical Methods
99pub mod methods;
100pub mod tableau;
101
102// Differential Equations
103pub mod bvp;
104pub mod dae;
105pub mod dde;
106pub mod ivp;
107pub mod ode;
108pub mod sde;
109
110// Output Control
111pub mod solout;
112
113// Core Structures
114pub mod control;
115pub mod error;
116pub mod solution;
117pub mod stats;
118pub mod status;
119pub mod tolerance;
120
121// Shared Traits & Utilities
122pub mod interpolate;
123pub mod linalg;
124pub mod traits;
125pub mod utils;
126
127// Derive Macros
128pub mod derive {
129 pub use differential_equations_derive::State;
130}