All published worksheets from http://sagenb.org
Image: ubuntu2004
Sections 5.1 and 5.2
Let's take a look at a joint continuous distribution for to random variables, problem 5.5 on page 233 of your text. The region of the plane looks like
The probability we wish to compute can be computed using symbolic calculus techniques (antidifferentiation).
We can also compute this integral using the Monte Carlo method. Here is the idea. The integral we wish to compute is the volume of a solid in 3-space. Bound that volume in a rectangular solid, whose sides are parallel to the coordinate planes, and compute the volume of that solid (I bounded the volume in the rectangular solid , which has volume 3).
Next, pick a bunch of points randomly in the rectangular solid. Count the number of them that lie inside the volume you wish to compute; call this number (for "success"). Then, the volume we wish to compute is approximately the proportion of randomly chosen points falling in the volume, times the volume of the rectangular solid. (That is, the volume we wish to compute is a fraction of the volume of the rectangular solid. How big a fraction? The proportion of randomly chosen points inside the volume of interest should tell you!)
Let's try out the Monte Carlo method on a known, and simple, integral, for comparison purposes:
The actual value is 1/3, so this was not too bad!
What is the benefit to using Monte Carlo methods? First, they work very well when antiderivatives are difficult to compute. Generally, logical conditions describing a region are much easier to write down than a string of computations computing an integral. Second, Monte Carlo methods for computing integrals can be used as a sort of "benchmark test" for computing. They are BDAs (Big Dumb Algorithms) and generally slow (my 100000 data point sample did not even get the third decimal place correct here, and so we might have to choose a much larger sample), but... it's really, really easy to code Monte Carlo. So, MC is often used as a reality check against more sophisticated techniques (or used when we don't have a more sophisticated technique).
Section 5.7 -- Covariance
First, a plot of the function