Aligrator
A lightweight, dependency-free Rust library for numerical integration of ordinary differential equations (ODEs). Supports multiple Runge-Kutta multistage integrators and is easily extensible.
Features
- Forward Euler
- Rk4, Rk45, Rk89
- Adaptive time-stepping
Example: Solving a Simple Harmonic Oscillator
This example demonstrates how to use Aligrator to solve the initial value problem (IVP) for a simple 1D harmonic oscillator (SHO) with equation of motion:
x''(t) + \omega^2x(t) = 0
1. Define the ODE System
/// Simple Harmonic Oscillator (SHO) implementation.
- Note: Aligrator requires that you implement the
IvpFunctiontrait for your ODE system.
2. Set Initial Conditions
let x0 = ; // Initial position
let xdot0 = ; // Initial velocity
let t0 = 0.0; // Start time
let tf = 15.0; // End time
let dt = 1.0; // Initial time step
3. Choose and Configure the Integrator
let mut integrator = new; // Adaptive disabled (second argument)
- Here we use the high-order Runge-Kutta 8/9 method.
- For adaptive time-stepping, pass
Some(AdaptiveDt::new(Some(1e-6), None, None))as the second argument. Here the first argument is tolerance, the second is minimum time step, and the third is maximum time step.
4. Integrate the System
let = integrate;
- Solves the IVP from
t0totf. - Returns time points, positions, and velocities (not used here).
- Here we use the integrate function to manage the looping, but you can easily just call the
integrator.step(...)in your own integration loop.
The response should look like this:

If we check the accuracy, its consistent with what we expect from this integrator:

6. Run the Example
Build and run the example with:
License
MIT