Skip to main content

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​

Activity: Four-point nodes

Hard-code the four-point Gauss–Legendre set on [−1,1][-1,1] from the theory table (both signs). Print four lines

y w

sorted by increasing yy, each with 12 decimals. No input.

Write-ups​

0/4 solved
5.4b.W1

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

0 words/ 3 min

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.