Skip to content

SakigamiYang/numerical-ode-solvers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Numerical ODE Solvers from Scratch

This repository contains a collection of numerical solvers for ordinary differential equations (ODEs), implemented from scratch for educational and research-oriented purposes.

The goal of this project is to study the connection between mathematical models, numerical time integration methods, and their practical behavior in terms of stability, accuracy, and convergence.


Mathematical Problem

We consider initial value problems (IVPs) of the form

$$ \frac{dy}{dt} = f(t, y), \quad y(t_0) = y_0, $$

where $ y(t) \in \mathbb{R}^n $.

Implemented in v0.1:

  • RK4 (fixed step size)
  • Dormand–Prince RK45 (adaptive step size)
  • Convergence experiments and basic test suite

Docs:

  • docs/theory.md
  • docs/error_analysis.md

Quickstart (uv)

uv venv
uv pip install -e ".[dev]"
pytest -q
python experiments/convergence_test.py --method RK4
python experiments/convergence_test.py --method RK45
python experiments/dopri5_fixed_convergence.py --h0 0.4 --kmax 7 --t1 10

Plots will be saved to plots/.


Implemented Methods

  • Explicit Runge–Kutta methods

    • Classical RK4 (fixed step size)
    • Dormand–Prince RK45 (adaptive step size)
  • Implicit methods

    • Implicit Euler method (for stiff problems)

Adaptive step size control is implemented based on embedded error estimation and relative/absolute tolerances.


Numerical Experiments

The following aspects are investigated numerically:

  • Convergence order with respect to step size
  • Stability behavior for stiff and non-stiff problems
  • Comparison between explicit and implicit methods
  • Influence of adaptive step size control

Representative test problems include:

  • Harmonic oscillator
  • Damped oscillator
  • Logistic growth equation

Error and Convergence Analysis

For problems with analytical solutions, numerical errors are computed and compared against theoretical convergence rates. For more complex problems, reference solutions with very small step sizes are used.

Detailed discussions can be found in docs/error_analysis.md.


Project Motivation

This project was developed to gain a deeper understanding of numerical methods for differential equations beyond black-box library usage. It reflects my interest in Scientific Computing, where mathematical analysis, numerical algorithms, and implementation are tightly connected.


License

BSD 3-Clause License.


References

  • Hairer, E., Nørsett, S. P., Wanner, G. Solving Ordinary Differential Equations I
  • Butcher, J. C. Numerical Methods for Ordinary Differential Equations

About

Numerical ODE solvers implemented from scratch (RK4, RK45, DoPri5), with convergence and error analysis for Scientific Computing.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages