differential_equations/lib.rs
1//! # differential-equations
2//!
3//! A Rust library for solving various types of differential equations.
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 different classes of differential equations:
11//!
12//! - **[Ordinary Differential Equations (ODE)](crate::ode)**
13//! - Initial value problems (ODEProblem)
14//! - Fixed and adaptive step methods
15//! - Event detection
16//! - Customizable output control
17//!
18//! - **[Delay Differential Equations (DDE)](crate::dde)**
19//! - Constant delays
20//! - State-dependent delays
21//! - Same features as ODEs
22//!
23//! - **[Stochastic Differential Equations (SDE)](crate::sde)**
24//! - Drift-diffusion equations
25//! - User controlled random number generation
26//! - Same features as ODEs
27//!
28//! ## Feature Flags
29//!
30//! - `polars`: Enable converting Solution to Polars DataFrame using `Solution.to_polars()`
31//!
32//! ## Example (ODE)
33//!
34//!```rust
35//! use differential_equations::prelude::*;
36//! use nalgebra::{SVector, vector};
37//!
38//! pub struct LinearEquation {
39//! pub a: f64,
40//! pub b: f64,
41//! }
42//!
43//! impl ODE<f64, SVector<f64, 1>> for LinearEquation {
44//! fn diff(&self, _t: f64, y: &SVector<f64, 1>, dydt: &mut SVector<f64, 1>) {
45//! dydt[0] = self.a + self.b * y[0];
46//! }
47//! }
48//!
49//! fn main() {
50//! let system = LinearEquation { a: 1.0, b: 2.0 };
51//! let t0 = 0.0;
52//! let tf = 1.0;
53//! let y0 = vector![1.0];
54//! let problem = ODEProblem::new(system, t0, tf, y0);
55//! let mut solver = DOP853::new().rtol(1e-8).atol(1e-6);
56//! let solution = match problem.solve(&mut solver) {
57//! Ok(sol) => sol,
58//! Err(e) => panic!("Error: {:?}", e),
59//! };
60//!
61//! for (t, y) in solution.iter() {
62//! println!("t: {:.4}, y: {:.4}", t, y[0]);
63//! }
64//! }
65//!```
66//!
67//! # License
68//!
69//! ```text
70//! Copyright 2025 Ryan D. Gast
71//!
72//! Licensed under the Apache License, Version 2.0 (the "License");
73//! you may not use this file except in compliance with the License.
74//! You may obtain a copy of the License at
75//!
76//! http://www.apache.org/licenses/LICENSE-2.0
77//!
78//! Unless required by applicable law or agreed to in writing, software
79//! distributed under the License is distributed on an "AS IS" BASIS,
80//! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
81//! See the License for the specific language governing permissions and
82//! limitations under the License.
83//! ```
84
85// -- Prelude Module & Recommended Imports for Users --
86
87pub mod prelude;
88
89// -- Types of Differential Equations --
90
91// Ordinary Differential Equations (ODE) Module
92pub mod ode;
93
94// Delay Differential Equations (DDE) Module
95pub mod dde;
96
97// Stochastic Differential Equations (SDE) Module
98pub mod sde;
99
100// -- Solution Output Control --
101
102// Numerous implementations of the Solout trait are contained in this module
103pub mod solout;
104pub use solout::{
105 // Solout Trait for controlling output of the solver
106 Solout,
107};
108
109// -- Shared items not specific to a Differential Equation Type --
110
111// Error for Differential Equations NumericalMethods
112mod error;
113pub use error::Error;
114
115// Status of Differential Equations NumericalMethods
116mod status;
117pub use status::Status;
118
119// Solution of a solved differential equation
120mod solution;
121pub use solution::Solution;
122
123// Control Flow
124mod control;
125pub use control::ControlFlag;
126
127// Traits for Floating Point Types
128pub mod traits;
129
130// Interpolation Functions
131pub mod interpolate;
132
133// Shared Utility Functions
134pub mod utils;
135
136// Linear Algebra Functions
137pub mod linalg;
138
139// Alias for primative types for readability
140pub mod alias;
141
142// Derive Macros for Differential Equations
143pub mod derive {
144 pub use differential_equations_derive::State;
145}