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

138                                        EXCEL: NUMERICAL METHODS



                                                  1
                                            b-u  jF((b-a)z+(b+U)                  (7-1 1)
                                                             2
                                              2
                                                 -1
               and equation 7-9 becomes


                                                        (b - U)Z, + (b + U)       (7-12)
                                                                2

               which permits integration over any range.
                   The code shown in Figure 7-12 performs Gaussian quadrature using equation
               7-12  and  a  tenth-order  Legendre  polynomial.  Some  results  returned  by  the
               function are shown in Figure 7- 13.


                   3ption Explicit
                   ............................................................
                   Function Integrate(expression, variable, from-lower,  to-upper,  Optional -
                    tolerance)
                   3m  Formulastring As String, XAddress As String
                   3m  result As Double
                   -ormulaString = expression.Formula
                   Wddress = variable.Address  'Default is absolute
                   'ormulaString  = Application.ConvertFormula(FormulaString, xlAl, xlAl , -
                    xl Absolute)
                   Call GaussLeGendrel O(FormulaString, XAddress, from-lower,  to-upper,  -
                    tolerance, result)
                   Integrate = result
                   End Function
                   .............................................................
                   Sub GaussLeGendrel O(expression, XRef, from-lower,  to-upper,  tolerance,
                     result)
                   'Uses ten-point Gauss-Legendre quadrature formula.
                   Adapted from Shoup, p.203
                   Dim XJ As Variant, AJ As Variant
                   Dim TotalArea As Double, OldArea As Double, area As Double

                   Dim T As String, temp As String
                   Dim I  As Integer, J As Integer, K As Integer, JJ As Integer
                   Dim N As Integer, NRepl As Integer
                   Dim A As Double, 6 As Double, C As Double, D As Double, F As Double
                   Dim H As Double
                   XJ = Array(-0.97390652851 71 72, -0.865063366688984, -0.679409568299024, -
                     0.433395394129247, -0.148874338981631,0.973906528517172,
   156   157   158   159   160   161   162   163   164   165   166