1Demonstration 1 of 4
Three answers from one model
Does the same model give the same answer under every solver?
Each solver turns the same rate into a change over one step in a different way. When the rate changes a lot across a step, the solvers disagree; at a sixteenth of the step they agree.
The quantity starts at 1 and grows at rate 2.6 x level x (1 - level / 100), toward a capacity of 100, for twenty periods. The step is the time advanced per calculation.
Predict first. At a step of 1.0, which solver ends above the capacity of 100, and which ends far below it?
Choose an example
Constructed example: the chapter's first table, rate 2.6, capacity 100, step 1.0, recomputed with the pack's integrate function.
Calculated values
- Solver
- Euler
- Step
- 1.0000
- Final value
- 113.40
- Highest value reached
- 123.35
- Final value minus capacity
- 13.40
Euler's first step is 1 + 1.0000 x 2.6 x 1 x (1 - 1/100) = 1 + 1.0000 x 2.574 = 3.5740. Repeating that for 20 steps ends at 113.40 after reaching 123.35, so the final value minus the capacity is 113.40 - 100 = 13.40. That is 13.40 above the capacity, a conservation violation made by the solver alone.
Use the idea
Before comparing two runs of a model, check that they used the same solver and step.
Where the conclusion applies
One growth model, a start of 1, twenty periods, and the pack's three solvers. The conclusion fails for a model whose rate is nearly constant across a step, where all three agree.
Check your understanding: At a step of 0.0625, how far from 100 do the three solvers end, to two decimals?
Chapter 19 source: section "Three answers from one model". Demonstration C19-D01.
2Demonstration 2 of 4
What Euler assumes about the rate
Why does Euler overshoot a limit, and how does the step change it?
The rate is largest when the level is far from the capacity, so the start-of-step rate is too high for the rest of the step. The error grows with the rate and the step, so a smaller step or a gentler rate shrinks it.
The rate is growth rate x level x (1 - level / 100). Euler reads it once at the start of each step and multiplies by the step. The exact curve is the closed-form logistic.
Predict first. At growth rate 2.6, does halving the step from 1.0 to 0.5 remove the overshoot above 100?
Choose an example
Constructed example: the chapter's logistic with rate and step values chosen for this reader, Euler from the pack, exact curve by the closed form.
Calculated values
- Growth rate
- 2.6
- Step
- 1.00
- Rate used for the first step
- 2.574
- Euler value after one step
- 3.5740
- Exact value at that time
- 11.9716
- Highest Euler value
- 123.35
- Final Euler value
- 113.40
Euler reads the rate once at the start of a step: 2.6 x 1 x (1 - 1/100) = 2.574, and assumes it holds for the whole step, so the first step adds 1.00 x 2.574 = 2.5740 to give 3.5740, while the exact curve is 11.9716 at that time. The path breaches the capacity: 123.35 - 100 = 23.35 above it. The final value is 113.40.
Use the idea
Choose the step small relative to the fastest change in the model, then confirm by halving it.
Where the conclusion applies
Euler only, a start of 1 and twenty periods. At a step of 0.5 the path still peaks at 101.14, above the capacity, so a settled endpoint alone does not clear the step.
Check your understanding: At growth rate 1.5 and a step of 0.5, does Euler ever exceed 100?
Chapter 19 source: section "What Euler assumes". Demonstration C19-D02.
3Demonstration 3 of 4
Sequential update is a different model
When two stocks exchange a quantity, does the update order change the total?
Simultaneous update reads both flows from the old state, so what leaves one stock enters the other. Sequential update lets B's flow see A's new value, so the transfer is no longer closed.
A and B are stocks, starting at 100 and 0. k is the fraction of the gap that moves per step. The step is 1, so the flow from B to A is k x (B - A).
Predict first. With k = 0.3, how many units vanish if A is written before B's flow is computed?
Choose an example
Constructed example: the chapter's closed transfer from 100 and 0, with k values chosen for this reader, run through the pack's two update functions.
Calculated values
- Update rule
- simultaneous
- Stock A after one step
- 70.0
- Stock B after one step
- 30.0
- Total after one step
- 100.0
- Quantity created or lost
- 0.0
Both flows are read at the start: k x (0 - 100) = 0.3 x (-100) = (-30.0) for A, so A = 100 + (-30.0) = 70.0 and B = 0 + 30.0 = 30.0. Total 70.0 + 30.0 = 100.0, nothing created or lost.
Use the idea
Test a runtime with the invariant that a closed transfer conserves its total, not with a trajectory.
Where the conclusion applies
A closed two-stock transfer, one step, and k between 0.1 and 0.5. With k = 0 nothing moves and both updates agree.
Check your understanding: With k = 0.5 and sequential update, what is the total after one step?
Chapter 19 source: section "Simultaneous update, again". Demonstration C19-D03.
4Demonstration 4 of 4
The refinement test
Three runs at halved steps: has the answer settled?
Convergence means the last halving moved the endpoint by less than the tolerance. A sequence that keeps moving by a similar amount at every halving has not settled, however small the tolerance.
Each run ends at period 20 for steps 1, 0.5 and 0.25 (or three runs of a made-up sequence). The tolerance is the largest last gap still called converged.
Predict first. With a tolerance of 0.1, does the sequence 50, 70, 90 count as converged?
Choose an example
Constructed example: the chapter's refinement test on its growth model and the sequence 50, 70, 90, run through the pack's step_refinement and converged functions.
Calculated values
- Runs
- Euler endpoints at steps 1, 0.5, 0.25
- First gap
- 13.40
- Last gap
- 0.00
- Tolerance
- 0.10
- Verdict
- converged
First gap |100.00 - 113.40| = 13.40. Last gap |100.00 - 100.00| = 0.00, compared with the tolerance 0.10: 0.00 < 0.10, so the verdict is converged. The last halving moved the endpoint by less than the tolerance, so the sequence is called converged. That is a statement about the endpoint only; the path and the invariants still need checking.
Use the idea
Record the three endpoints beside the model so a later reader can judge the step.
Where the conclusion applies
Only the last gap is tested, as the pack does. A settled endpoint does not clear the path, and a large tolerance can call a sequence settled that is still moving.
Check your understanding: For the sequence 50, 70, 90, what is the smallest tolerance that would call it converged?
Chapter 19 source: section "The refinement test". Demonstration C19-D04.