② Write a program that compares Monte Carlo and one or more
alternative numerical integration techniques. Structure this program so
that it is easy to replace the particular function being integrated.
Verify that the different techniques compute the same result (given a
sufficient number of samples for each of them). Modify your program so
that it draws samples from distributions other than the uniform
distribution for the Monte Carlo estimate, and verify that it still computes
the correct result when the correct estimator,
Equation (2.7), is used. (Make sure that any alternative
distributions you use have nonzero probability of choosing any value of
where .)
① Write a program that computes unbiased Monte Carlo estimates of the
integral of a given function. Compute an estimate of the variance of the
estimates by performing a series of trials with successively more samples
and computing the mean squared error for each one. Demonstrate numerically
that variance decreases at a rate of .
② The algorithm for sampling the linear interpolation
function in Section 2.3.2 implicitly assumes that and that thus . If is negative, then the importance
sampling PDF should be proportional to . Generalize
SampleLinear() and the associated PDF and inversion functions to
handle the case where is always negative as well as the case
where it crosses zero due to and having different signs.