# Chapter 22 notebook: Ordinary Differential Equations: Choosing and Checking Time Integrators

**Goal:** Separate time-integrator stability from accuracy and verify the quantities the application needs.

**Start with:** Rules 22.1.1, 22.2.3, 22.3.1. Use a calculator or the optional Python lab. Programming is optional for the workbook; the Jupyter version requires a Python 3 kernel. All lab numbers are constructed practice inputs, not observed data.

**Source:** [Finished Chapter 22](../skills/math-thumb-ode/references/chapter.md) from *Mathematical Rules of Thumb*. Numbered rules, classifications, and the decision path come from the book. The lab, exercises, answer key, and worksheet prompts are companion additions.

## 1. Frame your decision

Write a question in which an answer would change something you do. Gather: ODE and initial state; state/time units; shortest important timescale; stiffness clues; component tolerances; events and invariants.

- My question and intended decision:
- Known inputs and units:
- Required accuracy or threshold:
- What I expect before calculating:
- What I still need to find out:

Use the lab as a worked starting point if you do not yet have your own problem. For notation or prerequisites, ask the chapter skill to explain only the concept blocking the next step.

## 2. Choose a route

- **Are accepted explicit steps far smaller than output accuracy seems to require?** Inspect Jacobian scales and solver statistics; test a stiff method at the same tolerances.
- **Is the system strongly dissipative and large?** Try BDF with sparse Jacobians. If it is Hamiltonian and long-time geometry matters, choose a symplectic method instead.
- **Does the solution oscillate?** Set a starting maximum step from the shortest important period, then verify phase and amplitude under refinement.
- **Are state scales heterogeneous or near zero?** Choose componentwise absolute tolerances and a dimensionless relative tolerance before judging cost.
- **Does the model switch, impact, or cross a threshold?** Define a smooth event function and localize a bracketed root; do not shrink the display grid as a substitute.
- **Is the method explicit?** Check its full stability region against relevant modes, not only its formal order.
- **Can the exact solution be avoided?** Use three-level refinement, invariant drift, and balance checks as independent evidence.
- **Do implicit solves dominate?** Expose sparsity and escalate to appropriate sparse or matrix-free linear solvers.

**Chapter-specific stop check:** Formal order and local error estimates do not replace stability, event, phase, or invariant checks. Use the stability region of the actual integrator.

## 3. Work the lab

For y'=-10y, explicit Euler has amplification 1-10h. Absolute stability requires |1-10h|<=1, or 0<=h<=0.2, and damping needs the strict upper inequality. At h=0.1 the factor is zero, so Euler wipes out the state in one step although the exact one-step factor is exp(-1)≈0.3679. Stability alone does not guarantee useful accuracy. At h=0.25 the factor is -1.5 and errors grow.

Predict the sign and scale before running the code. Then change one input and explain why the result moves. The code checks the constructed example; it does not prove the rule for every possible input. Code assertions may describe the example's chosen regime, so inspect them before changing that regime.

```python
import math
decay_rate = 10.0
for step_size in (0.05, 0.1, 0.2, 0.25):
    amplification = 1-decay_rate*step_size
    exact_factor = math.exp(-decay_rate*step_size)
    print(f"h={step_size:.2f}; Euler factor={amplification:.3f}; exact factor={exact_factor:.6f}; damped={abs(amplification)<1}")
```

**My prediction, observed result, and explanation:**

_Record your work here._

## 4. Practise without the answers

### Exercise 1

RK4 global errors on two steps are 0.0016 and 0.0001 after halving h. Is the ratio consistent with fourth order?

**My approach, assumptions, calculation, and check:**

_Write your attempt here._

### Exercise 2

An oscillation has period 0.2 s. What starting maximum step gives 20 steps per period?

**My approach, assumptions, calculation, and check:**

_Write your attempt here._

### Exercise 3

A state crosses a threshold between saved output times. Does making the output table denser guarantee correct event location?

**My approach, assumptions, calculation, and check:**

_Write your attempt here._

**Coaching prompt:** “Use the Chapter 22 skill to help me with Exercise 2. Ask for my attempt, give one useful hint if I need it, and help me check the assumptions before showing the answer.”

## 5. Answer key and reasoning

Read this after attempting the exercises, or use it immediately if you prefer a complete walkthrough. An answer is complete only when its assumptions and stopping point are clear.

### Answer 1

Yes: 0.0016/0.0001=16=2^4. Use a third resolution and control other errors to strengthen the order check.

### Answer 2

h<=0.2/20=0.01 s. Refine and compare phase and amplitude; 20 is a starting choice, not a universal accuracy guarantee.

### Answer 3

No. Use an event function and root localization tied to the solver's continuous representation or bracket. Output spacing is not the same as the integrator's internal step.

## 6. Build the complete chapter toolkit

The new lab samples the chapter; the following checklist covers all 12 rules. Study one thematic group at a time. A large group can take several sessions.

- **Match the Integrator to the Dynamics:** work with rules 22.1.1, 22.1.2, 22.1.3, 22.1.4, 22.1.5.
- **Control Error Without Missing Events:** work with rules 22.2.1, 22.2.2, 22.2.3.
- **Verify Stability, Convergence, and Structure:** work with rules 22.3.1, 22.3.2, 22.3.3, 22.3.4.

For each selected rule, read its equation, explanation, and worked use in the source. Reproduce that example; change one input; then change one assumption so the rule is no longer justified. Record the result and what check catches the failure. Historical examples remain labeled and qualified as in the source.

Read each complete numbered profile in the [chapter reference](../skills/math-thumb-ode/references/chapter.md) before applying it. The cues below abbreviate the graph metadata; they are not complete conditions. Change the status only after doing the practice described below.

| Rule | Book role | First assumptions to inspect | Practice status |
|---|---|---|---|
| 22.1.1: Suspect stiffness when stability, not accuracy, dictates tiny steps | Workflow | well posed initial value problem;  solver model compatibility | new |
| 22.1.2: Use BDF for large dissipative stiff systems | Workflow | well posed initial value problem;  solver model compatibility | new |
| 22.1.3: Use symplectic integrators for long Hamiltonian trajectories | Workflow | well posed initial value problem;  solver model compatibility | new |
| 22.1.4: Remember that local ODE error is one power higher than global error | Independent | well posed initial value problem;  solver model compatibility | new |
| 22.1.5: Resolve oscillations with several steps per shortest period | Independent | well posed initial value problem;  solver model compatibility | new |
| 22.2.1: Scale ODE error with atol plus rtol times state magnitude | Workflow | meaningful component scales;  reliable local error estimate | new |
| 22.2.2: Change adaptive ODE steps with the error-order power | Specialized | well posed initial value problem;  solver model compatibility | new |
| 22.2.3: Locate ODE events with root finding, not output sampling | Workflow | continuous event function;  bracketed event | new |
| 22.3.1: Check explicit Euler against the stability disk | Workflow | well posed initial value problem;  solver model compatibility | new |
| 22.3.2: Expect RK4 global error to fall by sixteen on step halving | Workflow | well posed initial value problem;  solver model compatibility | new |
| 22.3.3: Monitor invariants as an independent ODE error check | Workflow | well posed initial value problem;  solver model compatibility | new |
| 22.3.4: Provide Jacobian sparsity to stiff ODE solvers | Workflow | stable jacobian sparsity pattern;  large stiff system | new |

For a completed row, record: **rule number / my new input / mathematical claim type / verified assumptions / calculation / check / valid use / rejected use / next step**. “Practised” means you worked an example. “Demonstrated” means you can explain a valid use, transfer it, and reject a misuse without the answer key.

## 7. Apply it to your own problem

Return to your opening question. Choose the smallest rule set that can settle it. Use the book's independent/workflow/specialized classification separately from the claim type (exact, approximate, bound, diagnostic, or heuristic).

- Selected rule number(s) and reason:
- Assumptions that hold, fail, or remain uncertain:
- Substitution with units:
- Result and error, uncertainty, or bound:
- Independent check or limiting case:
- Decision this supports:
- Stop here, do a named next calculation, or gather missing information:

## 8. Transfer and continue

Useful nearby chapters: Chapter 7: linear algebra; Chapter 20: numerical methods; Chapter 23: pde. Bring the question, units, assumptions, result type, and uncertainty to the next chapter. Choose a bridge only when it supplies an operation you actually need.

**Completion check:** Explain this chapter's lab in your own words; solve one changed-input exercise; reject one invalid use; and produce a decision record for your own problem. If one check fails, revisit that part of the chapter rather than marking every rule complete.
