One of the first sophisticated uses of the electronic comput

One of the first sophisticated uses of the electronic computer was to perform simulations of a complex physical process by using random numbers The approach is called Monte Carlo and is illustrated using the following simple example. For example, consider a square of side length 1/2 placed inside a bigger square of side 1. It is obvious that the ratio of areas A_2/A_1 = (1/2)^2/1^2 = 1/4 = 0.25 This ratio is equivalent to the probability of a randomly, uniformly selected point from the larger square to also belong to the smaller square. One may write a computer program to estimate such probability. Here, a random point (x, y) is generated whose coordinates are uniformly selected such that 0 lessthanorequalto x lessthanorequalto 1 and 0 lessthanorequalto y lessthanorequalto 1. If the point also belongs to the inner square, we would increment a counter a by 1. The process is repeated many, many times, say m = 1000,000 times Then the desired probability is estimated as n/m. This is the basis for the Monte Carlo method Problem: Employ the Monte Carlo method and Matlab to estimate the ratio of the gray area to the area of the equilateral triangle of side 2. shown in the following figure The gray area is defined by the region bounded by the three arcs of radius Squareroot 2 that are centered at the three verities of the triangle, respectively. Also, report the time it takes to execute your Matlab function on our laptop.

Solution

The theory of the Monte Carlo simulation which we describe is, I presume, that if you enclose a triangle completely in a square of known area, the area of the triangle can be estimated by multiplying the area of the square by the fraction of the random points within the square which happen to land inside the triangle.

With the triangle you have specified with vertices (0,0), (0,1), (1,0), it is very easy to do this, and in fact you have done just that in your code.

Writing x = r and and y = r and will fill the unit square with vertices at (0,0), (1,0), (1,1), and (0,1) uniformly. Since x and y are non-negative, the only test you need for being inside your triangle is for the hypotenuse, whether or not x+y <=1, and that is what your \'count\' is recording. That means code as we have shown it is almost done. Multiply the known area of the square by the fraction count/tries and you have your estimate for the area. You were almost there!

The simulation is a little more challenging with an arbitrary triangle. We have to define a square which is guaranteed to completely enclose it and then generate a large number of random points that are distributed uniformly in the square. Each of these points is tested to see if it does or does not lie within the triangle. The fraction that do lie within it is to be multiplied by the area of the square to give an estimate of the triangle\'s area.

             

 One of the first sophisticated uses of the electronic computer was to perform simulations of a complex physical process by using random numbers The approach is

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site