Page 162 - Excel for Scientists and Engineers: Numerical Methods
P. 162
CHAPTER 7 INTEGRATION 139
0.865063366688984,0.679409568299024,0.433395394129247.
0.148874338981 631)
AJ = Array(0.066671344308688,0.149451349915058,0.219086362515982,
0.26926671 9309996,0.295524224714753,0.066671344308688,
0.149451349915058,0.219086362515982,0.269266719309996,
0.29552422471 4753)
If IsMissing(to1erance) Then tolerance = 0.0000000001
OldArea = 0
N=l
For K = 1 To 10 'increments divided by 1,2,4,8,16,32,64,128,256,512
area = 0
H = (to-upper - from-lower) / N
For I = 1 To N
A = from-lower + (I - 1) H
B=A+H
C = (B + A) / 2
D = (B - A) / 2
For J = 1 To 10
T = expression
NRepl = (Lenv) - Len(Application.Substitute(T, XRef, "'I))) I Len(XRef)
For JJ = NRepl To 1 Step -1
temp = Application.Substitute(T, XRef, C + D * XJ(J) & " 'I, JJ)
If IsError( Evaluate(temp)) Then GoTo ptl
T = temp
ptl: Next JJ
F = Evaluatev)
area = area + AJ(J) * F
Next J
Next I
area = area * D
If Abs((area - OldArea) / area) < tolerance Then GoTo AllDone
OldArea = area
N=2*N
Next K
AIIDone:
result = area
End Sub
Figure 7-12. Integrate custom function.
(folder 'Chapter 07 Examples', workbook 'Integration', module 'Legendrehtegration')