Skip to content

feat: Dormand-Prince RK45 adaptive ODE solver #32

Description

@bwyard

Context

rk4_step uses fixed step size. Stiff systems and rapidly-changing dynamics need adaptive step-size control to maintain accuracy without wasting evaluations.

Proposed API

pub fn rk45_adaptive(
    state: f32, t0: f32, t_end: f32, dt_initial: f32, tol: f32,
    f: impl Fn(f32, f32) -> f32,
) -> (f32, f32, u32)  // (final_state, final_time, steps_taken)

Dormand-Prince method with embedded 4th/5th order error estimate. Step size adjusted by dt *= 0.9 * (tol/error)^0.2.

Thesis alignment

  • Pure: (state, t0, t_end, dt, tol, f) -> (state, t, steps)
  • ADVANCE-EXCEPTION: while loop bounded by max_steps
  • No &mut in public API

Tests needed

  • dy/dt = -y gives exp(-t) within tolerance
  • Oscillator energy conservation
  • Step count is reasonable (fewer than fixed-step for same accuracy)
  • Deterministic

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions