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

358                                        EXCEL: NUMERICAL METHODS


                   =50*RAND()

               and
                   =35*RAND()
               and the formula in C17 contains the custom function
                   =Inside($A$6:$A$14 ,$ B$6:$B$14 ,A1 7, B 1 7)
                   The formulas were filled down to fill 2000 cells.  The formulas to calculate
               the area are:
                 in cell D7:  =COUNTA($C$I 7:$C$2016)  (total number of points)
                 in cell E7:   {=SUM(($C$17:$C$2016)*1)}  (number of points inside polygon)
                 in cell E9:  =E7/D7                     (fraction of points inside)
                 in cell D11:  =35*50                    (area of the "box")
                 in cell El 1 :  =E9*D11                 (area of polygon)


                   To plot only the points that lie within the polygon, the formula
                   =IF($C17,A17,"")
               in cell D17 and the formula
                   =I F( $C 1 7, B 1 7 ,"")
               in cell El7 would seem to be suitable.  These formulas, w.,en  filleL down, yield
               the  spreadsheet  shown  in  Figure  15-19.  But  null-string  values  are  plotted  as
               zeros in a chart,  so the chart doesn't turn out the way we want.  Instead we use
               the NA() worksheet function; cells containing #NA! values are not plotted.

                   =IF($CI 7,A17,NA())
   376   377   378   379   380   381   382   383   384   385   386