Michael Corral: Vector Calculus
Michael Corral: Vector Calculus
Michael Corral: Vector Calculus
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
114 CHAPTER 3. MULTIPLE INTEGRALS<br />
with the sums taken over the N random points (x 1 ,y 1 ),..., (x N ,y N ). The±“error term”<br />
in formula (3.15) does not really provide hard bounds on the approximation. It represents<br />
a single standard deviation from the expected value of the integral. That is, it<br />
provides a likely bound on the error. Due to its use of random points, the Monte Carlo<br />
method is an example of a probabilistic method (as opposed to deterministic methods<br />
such as Newton’s method, which use a specific formula for generating points).<br />
For example, we can use formula (3.15) to approximate the volume V under the<br />
plane z=8x+6y over the rectangle R=[0,1]×[0,2]. In Example 3.1 in Section 3.1,<br />
we showed that the actual volume is 20. Below is a code listing (montecarlo.java) for<br />
a Java program that calculates the volume, using a number of points N that is passed<br />
on the command line as a parameter.<br />
//Program to approximate the double integral of f (x,y)=8x+6y<br />
//over the rectangle [0 ,1]x[0 ,2].<br />
public class montecarlo {<br />
public static void main(String [] args) {<br />
//Get the number N of random points as a command−line parameter<br />
int N = Integer . parseInt(args [0]);<br />
double x = 0; //x−coordinate of a random point<br />
double y = 0; //y−coordinate of a random point<br />
double f = 0.0; //Value of f at a random point<br />
double mf = 0.0; //Mean of the values of f<br />
double mf2 = 0.0; //Mean of the values of f^2<br />
for (int i=0;i