5.2b Extrapolated-difference labs
Source: Lab ideas from Computational Physics (Landau, Páez, Bordeianu), §5.2. Rewritten as original drills. Continues 5.2 Extrapolated difference.
Implement FD / CD / ED and the two second-derivative forms. Print relative errors and watch vs in the explorers. Stubs fail until filled in.
Formula refresh
Warm up: pick the matching equation among lookalikes (same walk as the theory lesson).
Labs
For , at given and , print
fd cd ed
each with 10 decimals — forward, central, and extrapolated
.
Input: t h.
Write-ups
Using “Richardson”, “h2”, and “cancel”, explain:
In one sentence: what does the extrapolated difference cancel that plain central difference still has?
Minimum 3 words. Your answer must include: “Richardson”, “h2”, “cancel”.
Meet the writing requirements, then you can open the model answer.
Explorers
# diff_ref.py
import math
def fd(y, t, h):
return (y(t + h) - y(t)) / h
def cd(y, t, h):
return (y(t + h / 2) - y(t - h / 2)) / h
def ed(y, t, h):
return (8 * (y(t + h / 4) - y(t - h / 4)) - (y(t + h / 2) - y(t - h / 2))) / (3 * h)
def d2(y, t, h):
return (y(t + h) - 2 * y(t) + y(t - h)) / (h * h)
Next: 5.3 Integration algorithms.