differential_equations/
lib.rs

1//! # differential-equations
2//!
3//! A Rust library for solving various types of differential equations.
4//!
5//! [![GitHub](https://img.shields.io/badge/GitHub-differential--equations-blue)](https://github.com/Ryan-D-Gast/differential-equations)
6//! [![Documentation](https://docs.rs/differential-equations/badge.svg)](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, 1, 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// -- Shared items not specific to a Differential Equation Type --
81
82// Error for Differential Equations NumericalMethods
83mod error;
84pub use error::Error;
85
86// Status of Differential Equations NumericalMethods
87mod status;
88pub use status::Status;
89
90// Solution of a solved differential equation
91mod solution;
92pub use solution::Solution;
93
94// Control Flow 
95mod control;
96pub use control::ControlFlag;
97
98// Traits for Floating Point Types
99pub mod traits;
100
101// Interpolation Functions
102pub mod interpolate;
103
104// -- Shared items for re-exporting to differential equation type modules --
105mod shared {
106    pub use crate::error::Error;
107    pub use crate::status::Status;
108    pub use crate::control::ControlFlag;
109    pub use crate::solution::Solution;
110}