5.7b Variance-reduction labs
Source: Lab ideas from Computational Physics (Landau, Páez, Bordeianu), §5.7. Rewritten as original drills. Continues 5.7 Monte Carlo variance reduction.
Control variate on for , , . Exact value . Use the chapter LCG only.
r ← (1103515245 * r + 12345) % 2**31, then uniform r / 2**31. Default seed 1. Advance the state before each draw.
Formula refresh
Warm up: pick the matching equation among lookalikes (same walk as the theory lesson).
Labs
Estimate by with , with the chapter LCG, seed , . Print with 10 decimals.
No input.
Write-ups
Using “peak”, “zero”, and “waste”, explain:
Why does a peaked integrand waste uniform Monte Carlo samples?
Minimum 3 words. Your answer must include: “peak”, “zero”, “waste”.
Meet the writing requirements, then you can open the model answer.
Explorers
# control_variate.py — original sketch (not a textbook listing)
M = 2**31
def plain_and_cv(N, seed=1):
r, s_f, s_res = seed, 0.0, 0.0
for _ in range(N):
r = (1103515245 * r + 12345) % M
x = r / M
fx = __import__('math').exp(-x)
s_f += fx
s_res += fx - (1.0 - x)
return s_f / N, s_res / N + 0.5
Next: 5.8 Importance sampling.