kangwonlee / kangwonlee/nmisp

Pedagogy: add interactive method comparison to 50_ode/30_Runge_Kutta with detailed explanations

Open
#381 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
12
Forks
76
PR merge metrics
No merged PRs in 30d

Description

Add an interactive comparison to `50_ode/30_Runge_Kutta.ipynb` that lets learners select a step size and an ODE, then plots Forward Euler, Heun (RK2), and RK4 side by side against the reference solution — with a log-error subplot showing the order-of-accuracy slopes.

## Code scope

- Slider for `h` (log scale).
- Optional: dropdown for ODE choice (linear decay, harmonic oscillator, mildly stiff).
- Three trajectories overlaid + reference.
- Log-log error vs `h` subplot showing slopes 1, 2, 4 (the orders of accuracy).

## Explanation scope (the deliverable)

- **What "order of accuracy" actually means** — error scales as `O(hᵖ)`; doubling `p` doesn't double accuracy, it *squares* the rate at which accuracy improves as `h` shrinks.
- **Per-step cost vs convergence trade-off** — RK4 costs 4 function evaluations per step but its error is `O(h⁴)`. For a target error, the total work (steps × evals) is dramatically lower than Forward Euler. This is the practical reason RK4 is the workhorse.
- **Why halving the step doesn't help equally for all methods** — shows up directly on the log-error plot as different slopes.
- **What this notebook is *not*** — adaptive step control, embedded RK pairs, dense output. Those are why production code uses `solve_ivp` (`11`); this notebook is about the underlying methods.

## Why this framing

Comparison-by-table loses the visual punch of slope difference on a log-log plot. The slider lets the learner discover the order-of-accuracy directly. The explanation is what turns "neat plot" into "I understand why we use RK4 in practice."

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.