home *** CD-ROM | disk | FTP | other *** search
- DEF FNtrapzd(A,B,N%)
- REM :
- REM This routine computes the N%th stage of refinement of an
- REM extended trapezoidal rule. Programs calling FNtrapzd must
- REM provide a function FNarg(X) which is to be integrated between
- REM limits A and B. When called with N%=1, the routine returns
- REM the crudest estimate of the integral. Subsequent calls with
- REM N%=2,3,... (in that sequential order) will improve the accuracy
- REM of S by adding 2^(N%-2) additional interior points. S should
- REM not be modified between subsequent calls. Note S must not
- REM be local - so be careful. - Modified, from Numerical Recipes p111
- REM :
- LOCAL X, SM, DL, J%
- REM :
- IF N%=1 THEN
- S=0.5*(B-A)*(FNarg(A)+FNarg(B))
- ELSE
- IT% = 2^(N%-2) :REM IT% is number of points to be added NEXT call.
- DL=(B-A)/IT% :REM This is the spacing of the points to be added.
- X=A+0.5*DL
- SM=0
- FOR J% = 1 TO IT%
- SM = SM + FNarg(X)
- X = X + DL
- NEXT J%
- S=0.5*(S+(B-A)*SM/IT%):REM This replaces S by its refined value.
- ENDIF
- =S
-
- ******* Must have FNarg attached
-