Page 377 - Excel for Scientists and Engineers: Numerical Methods
P. 377

354                                        EXCEL: NUMERICAL METHODS



               Monte Carlo Integration
                   The Monte Carlo method can be used to integrate a function that is difficult
               or impossible to evaluate by direct methods.  Often the process of "integration" is
               the  determination  of  the  area  of  a  figure.  We'll  illustrate  the  technique  by
               determining the area of two figures: first, the area of a circle (from which we can
               evaluate n), and second, the area of an irregular figure.
                   The evaluation of x is a classic illustration of the determination of an area by
               the Monte Carlo method.  Two random numbers in the range -1  to +1  are used to
               determine the coordinates of a  point  in  the x,  y  plane.  The number  of points
               inside the circle, defined by the equation x2 + y2 = 1 , divided by the total number
               of points, gives the ratio of the circle to the circumscribing square.  Figure 15-14
               illustrates such a calculation, using 4000 points.
























                                Figure 15-14.  Estimation of 7c by using RAND.

                   This particular calculation gave 3.129 as the value of x.



               The Area of an Irregular Polygon
                   When  the  preceding  method  is  used  to  estimate  the  area  of  an  irregular
               figure, we need a general method to determine whether a given point is inside or
               outside the figure.  In the following, the figure must be a polygon, that is, a figure
               that  can  be  described  by  a  series  of  coordinates  connected  by  straight  lines.
               Since in an Excel chart, a curve can be approximated by a number of straight line
               segments, in theory a figure of any shape can be handled.
   372   373   374   375   376   377   378   379   380   381   382