Crates.io | ordinary-diffeq |
lib.rs | ordinary-diffeq |
version | 0.2.3 |
created_at | 2025-08-12 20:07:31.860496+00 |
updated_at | 2025-08-12 20:55:21.52722+00 |
description | A library for solving differential equations based on the DifferentialEquations.jl julia library. |
homepage | |
repository | https://gitlab.rcjohnstone.com/connor/differential-equations |
max_upload_size | |
id | 1792721 |
size | 62,240 |
A library, written in Rust, for integrating ordinary differential equations. For now, this is relatively simple, but it does have key features that are needed for orbit propagation, ray tracing, and field line tracing:
A relatively efficient Dormand Prince 5th(4th) order integration algorithm, which is effective for non-stiff problems
A PI-controller for adaptive time stepping
The ability to define "callback events" and stop or change the integator or underlying ODE if certain conditions are met (zero crossings)
A fourth order interpolator for the Domand Prince algorithm
Parameters in the derivative and callback functions
DifferentialEquations.jl
For now, here is a simple example of using the propagator to solve a simple second-order system (the pendulum problem):
use nalgebra::Vector2;
use differential_equations::prelude::*;
use std::f64::consts::PI;
// Define the system (parameters, derivative, and initial state)
type Params = (f64, f64); // Gravity and Length of Pendulum
let params = (9.81, 1.0);
fn derivative(_t: f64, y: Vector2<f64>, p: &Params) -> Vector2<f64> {
let &(g, l) = p;
let theta = y[0];
let d_theta = y[1];
Vector2::new( d_theta, -(g/l) * theta.sin() )
}
let y0 = Vector2::new(0.0, PI/2.0);
// Set up the problem (ODE, Integrator, Controller, and Callbacks)
let ode = ODE::new(&derivative, 0.0, 6.3, y0, params);
let dp45 = DormandPrince45::new().a_tol(1e-12).r_tol(1e-6);
let controller = PIController::default();
let value_too_high = Callback {
event: &|t: f64, _y: Vector2<f64>, _p: &Params| { 5.0 - t },
effect: &stop,
};
// Solve the problem
let mut problem = Problem::new(ode, dp45, controller).with_callback(value_too_high);
let solution = problem.solve();
// Can interpolate solutions to whatever you want
let _interpolated_answer = solution.interpolate(4.4);