Page 159 - Excel for Scientists and Engineers: Numerical Methods
P. 159
136 EXCEL: NUMERICAL METHODS
T = Application.ConvertForrnula(FormulaString, xlAl I xlAl , xlAbsolute)
For J = NRepl To 1 Step -1
temp = Application.Substitute(T, XRef, from-lower + X + H & " 'I, J)
If IsError(Evaluate(temp)) Then GoTo pt2
T = temp
pt2: Next J
Y1 = Evaluatefl)
T = Application.ConvertFormula(FormulaString, xlAl , xlAl, xlAbsolute)
For J = NRepl To 1 Step -1
temp = Application.Substitutefl, XRef, from-lower + X + 2 * H & " ", J)
If IsError(Evaluate(temp)) Then GoTo pt3
T = temp
pt3: Next J
Y2 = Evaluatefl)
area = area + H * (YO + 4 * Y1 + Y2) I3
Next K
Integrates = area
End Function
Figure 7-9. VBA function procedure to integrate a worksheet formula
by Simpson's method.
(folder 'Chapter 07 Examples', workbook 'Integration', module 'Simplehtegration')
Some results returned by the IntegrateT and Integrates functions are shown
in Figures 7-10 and 7-1 1, respectively. In general, results are more accurate
when using the Simpson's method function.
Figure 7-10. Some results returned by the IntegrateT custom function.
(folder 'Chapter 07 Examples', workbook 'Integration', sheet 'Trapezoidal Integration Fn')