5.4b Gaussian quadrature labs
Source: Lab ideas from Computational Physics (Landau, P áez, Bordeianu), §5.4. Rewritten as original drills. Continues 5.4 Gaussian quadrature.
Use the four-point Gauss–Legendre table from the theory lesson (do not call a black-box integrator). Stubs fail until filled in.
Formula refresh
Warm up: pick the matching equation among lookalikes (same walk as the theory lesson).
Labs
Hard-code the four-point Gauss–Legendre set on from the theory table (both signs). Print four lines
y w
sorted by increasing , each with 12 decimals. No input.
Write-ups
Using “2N-1 ”, “exact”, and “polynomial”, explain:
What degree of polynomial is an N-point Gauss–Legendre rule exact for (ignoring round-off)?
Minimum 3 words. Your answer must include: “2N-1”, “exact”, “polynomial”.
Meet the writing requirements, then you can open the model answer.
Explorers
# gauss_ref.py — four-point table + affine map (original sketch)
Y1, W1 = 0.339981043584856, 0.652145154862546
Y2, W2 = 0.861136311594053, 0.347854845137454
def gauss4():
return [(-Y2, W2), (-Y1, W1), (Y1, W1), (Y2, W2)]
def map_ab(a, b, y, w):
mid, half = 0.5 * (a + b), 0.5 * (b - a)
return mid + half * y, half * w
Next: 5.5 Monte Carlo integration.