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