| Crates.io | aligrator |
| lib.rs | aligrator |
| version | 0.1.2 |
| created_at | 2025-06-27 09:52:48.903121+00 |
| updated_at | 2025-07-01 08:27:48.904911+00 |
| description | A lightweight numerical integration library. |
| homepage | |
| repository | https://github.com/alexlovric/aligrator |
| max_upload_size | |
| id | 1728400 |
| size | 128,297 |
A lightweight, dependency-free Rust library for numerical integration of ordinary differential equations (ODEs). Supports multiple Runge-Kutta multistage integrators and is easily extensible.
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
/// Simple Harmonic Oscillator (SHO) implementation.
struct SimpleHarmonicOscillator {
omega: f64,
}
impl IvpFunction<1> for SimpleHarmonicOscillator {
fn compute(&mut self, t: &f64, x: &[f64; 1], xdot: &[f64; 1]) -> [f64; 1] {
// x''(t) = -ω²x(t)
[-self.omega.powi(2) * x[0]]
}
}
IvpFunction trait for your ODE system.let x0 = [1.0]; // Initial position
let xdot0 = [0.0]; // Initial velocity
let t0 = 0.0; // Start time
let tf = 15.0; // End time
let dt = 1.0; // Initial time step
let mut integrator = Rk89::new(dt, None); // Adaptive disabled (second argument)
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.let (times, positions, _) = integrate(
&mut integrator,
&mut SimpleHarmonicOscillator { omega: 1.0 },
x0,
xdot0,
t0,
tf,
);
t0 to tf.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:

Build and run the example with:
cargo run --example sho_response
MIT