Skip to main content

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 log⁡∣E∣\log|\mathcal{E}| vs log⁡h\log h 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​

Activity: Three first-derivative rules

For y=cos⁡ty=\cos t, at given tt and hh, print

fd cd ed

each with 10 decimals — forward, central, and extrapolated

Ded=(8(y(t+h/4)−y(t−h/4))−(y(t+h/2)−y(t−h/2)))/(3h)D_{\mathrm{ed}}=\bigl(8(y(t+h/4)-y(t-h/4))-(y(t+h/2)-y(t-h/2))\bigr)/(3h).

Input: t h.

Write-ups​

0/3 solved
5.2b.W1

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”.

0 words/ 3 min

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.