Post · 2 min read· p. 116

Exercises

Exercises

  1. ② 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 diagram where diagram.)
  2. ① 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 diagram.
  3. ② The algorithm for sampling the linear interpolation function in Section 2.3.2 implicitly assumes that diagram and that thus diagram. If diagram is negative, then the importance sampling PDF should be proportional to diagram. Generalize SampleLinear() and the associated PDF and inversion functions to handle the case where diagram is always negative as well as the case where it crosses zero due to diagram and diagram having different signs.