introduction to monte carlo simulation

8
Introduction to Monte Carlo Simulation For Summer 1997 Envision-It! Workshop A technique which has had a great impact in many different fields of computational science is a technique called "Monte Carlo Simulation." This technique derives its name from the casinos in Monte Carlo - a Monte Carlo simulation uses random numbers to model some sort of a process. This technique works particularly well when the process is one where the underlying probabilities are known but the results are more difficult to determine. A great deal of the CPU time on some of the fastest computers in the world is spent performing Monte Carlo simulations because we can write down some of the fundamental laws of physics but cannot analytically solve them for problems of interest. An example of how a Monte Carlo simulation can be used in everyday life is a project one of my students did in a FORTRAN class - he wanted to find the best strategy for winning money at blackjack. The conventional approach (using just statistics) would be to write down the probability of having a particular combination (such as having an Ace and a Five with the dealer showing a Jack) and then calculating the expected payoff from each possible scenario (hit or no hit, but then you must calculate what to do if you get a seven after a hit). If you start thinking about all of the possible it quickly becomes overwhelming. This problem, however, works very well as a Monte Carlo

Upload: phydisc

Post on 10-Nov-2015

4 views

Category:

Documents


0 download

DESCRIPTION

Monte carlo

TRANSCRIPT

Introduction to Monte Carlo SimulationFor Summer 1997Envision-It!Workshop

A technique which has had a great impact in many different fields of computational science is a technique called "Monte Carlo Simulation." This technique derives its name from the casinos in Monte Carlo - a Monte Carlo simulation uses random numbers to model some sort of a process. This technique works particularly well when the process is one where the underlying probabilities are known but the results are more difficult to determine. A great deal of the CPU time on some of the fastest computers in the world is spent performing Monte Carlo simulations because we can write down some of the fundamental laws of physics but cannot analytically solve them for problems of interest.An example of how a Monte Carlo simulation can be used in everyday life is a project one of my students did in a FORTRAN class - he wanted to find the best strategy for winning money at blackjack. The conventional approach (using just statistics) would be to write down the probability of having a particular combination (such as having an Ace and a Five with the dealer showing a Jack) and then calculating the expected payoff from each possible scenario (hit or no hit, but then you must calculate what to do if you get a seven after a hit). If you start thinking about all of the possible it quickly becomes overwhelming. This problem, however, works very well as a Monte Carlo simulation. We know the underlying probabilities (drawing any particular card out a deck is 1/52 or if there are 5 decks in a shoe it is 1/5*52) and so all we need are the "rules" to use. In this case, the student wrote a program which would randomly generate a shoe of 5 decks of cards. It would then "deal" the cards to him and the "dealer." The "dealer" always followed the standard rules (hit on 16 and stay on 17) and the student programmed in the betting stratagy he wanted to test (on what combinations he would hit or stay, double, split, etc.). Then he would run the program and have it generate several hundred shoes and keep track of the winnings (or losings) and print the results at the end (this would take about an hour on a PC). One can then test various stratagies and see how they will actually work out in the long run.Let us do a simple example of a Monte Carlo simulation to illustrate the technique. First, let us consider the following problem, we want to make a simulation that will allow us to find the value of pi. We will do this in the following way: consider a square that has one corner at the origin of a coordinate system and has sides of length 1 - it will obviously have an area of 1. Now consider inscribing a quarter of a circle inside of this with a radius of 1 - we know that its area is pi/4. We can a Monte Carlo simulation to find the relative area of the circle and square and then multiply the circle's area by 4 to find pi. In particular, the way we will find the area of the circle is to note the following: for a point (X,Y) to be inside of a circle of radius 1, its distance from the origin (X2+Y2) will be less than or equal to 1. We can generate thousands of random (X,Y) positions and determine whether each of them are inside of the circle. Each time it is inside of the circle, we will add one to a counter. After generating a large number of points, the ratio of the number of points inside the circle to the total number of points generated will approach the ratio of the area of the circle to the area of the square. Thus the value of pi would simply bepi is approximately 4*(Number of Points inside circle)/ (Total Points Generated)Thus we can find an approximation to pi using simple math.Theprogrambelow can be used to find an approximation of pi

% pimc.m % Matlab Program to Find Pi using Random Numbers % Tom Huber, June 15, 1996 Nrand = input('How Many Random Numbers '); NInside = 0; for nloops=1:Nrand Xrand = rand; % Generate Random XY Point Yrand = rand; Rrand = Xrand^2 + Yrand^2; % Find its distance from origin if (Rrand