There are several ways to calculate integrals. The most direct way is to find the anti derivative and evaluate it. Another way is to use an approximation technique. One technique to find a double integral is to evaluate random points on a given area (circle, rectangle, etc) and use the average in its calculations.
With the Monte Carlo method, we are at mercy of the random numbers selected. Hence to improve our chances of getting a more accurate result, we have to use a large amount of random points for the calculation. The flip side is that the Monte Carlo method, similar to the Romberg sum and Simpsons Method, finding the antiderivatve is not required.
The program MONTEINT calculates the double integral
∫ ∫ f(x,y) dx dy
over a circular area with center (X, Y) and radius R. Please be sure the function is continuous and exists over the entire circular region. In order to help with the calculation time is that the program runs the calculations several times and averages the results. You enter the number of batches (B, number of times the calculation is made) and the number of sample points of each batch (N).
|A first for me: this is the first diagram I drew and posted using Microsoft Paint 3D!|
HP Prime Monte Carlo Double Integral Program: MONTEINT
// 2018-12-11 EWS
// ‘Z(X,Y)’, center X,
// center Y, radius,
// number of batches,
// batch size
FOR K FROM 1 TO B DO
FOR I FROM 1 TO N DO
IF (X-C)^2+(Y-D)^2≤R^2 THEN
// for EVAL() to work,
// X and Y must be global
Note: Enter f(X,Y) in single quotes.
TI 84 Plus Monte Carlo Double Integral Program: MONTEINT
Input “Z(X,Y) AS A STRING:”,Y₀
Input “CENTER X: “,C
Input “CENTER Y: “,D
Input “RADIUS: “,R
Input “BATCHES: “,B
Input “SAMPLE SIZE: “,N
“SUM, TRUE COUNT”
Disp “APPROX DOUBLE”,”INTEGRAL:”,V
Note: I put code that shows progress since the TI-84 Plus CE has a slower processor than the HP Prime.
Full decimal answers will vary.
f(X,Y) = √(LN(X + Y)) over a circle with center (5,5) of radius 1. 20 batches of 50 points each.
The value is approximately 4.76.
Example 2 – A Cautionary Tale:
f(X,Y) = X^2 + X*Y + Y^3 over a circle with center (0,0) of radius 2. 20 batches of 50 points each.
To illustrate how the Monte Carlo method is at the mercy of random points, the results vary between 11.3 to 13.1.
I am going to increase the number of batches to 30 with 100 points each. Thankfully with the HP Prime’s processing speed, this won’t increase the calculation by a large amount. The TI-84 Plus CE will require a longer wait.
After five trials, I get values between 12.07 and 13.15.
Increasing the number of points per batch to 200, I get results of 11.3 to 12.6. The function f(X,Y) = X^2 + X*Y + Y^3 may not be a good function for the Monte Carlo method.
CAUTION: The Monte Carlo is a method to calculate double integrals but it’s only for approximate values only. Several evaluations may be necessary to get a satisfactory approximation.
Ward Cheney and David Kincaid. Numerical Mathematics and Computing Sixth Edition Thomson Brooks/Cole: Belmont, CA 2008 ISBN-13 978-0-495-11475-8
All original content copyright, © 2011-2018. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. Please contact the author if you have questions.