home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / maths / progs / programs / Maths2 / Brian / trapzd < prev    next >
Encoding:
Text File  |  1990-04-08  |  1.1 KB  |  31 lines

  1. DEF FNtrapzd(A,B,N%)
  2. REM :
  3. REM This routine computes the N%th stage of refinement of an
  4. REM extended trapezoidal rule.  Programs calling FNtrapzd must
  5. REM provide a function FNarg(X) which is to be integrated between
  6. REM limits A and B.  When called with N%=1, the routine returns
  7. REM the crudest estimate of the integral.  Subsequent calls with 
  8. REM N%=2,3,... (in that sequential order) will improve the accuracy
  9. REM of S by adding 2^(N%-2) additional interior points.  S should 
  10. REM not be modified between subsequent calls.  Note S must not 
  11. REM be local - so be careful. - Modified, from Numerical Recipes p111
  12. REM :
  13. LOCAL X, SM, DL, J%
  14. REM :
  15. IF N%=1 THEN
  16.    S=0.5*(B-A)*(FNarg(A)+FNarg(B))
  17. ELSE
  18.    IT% = 2^(N%-2) :REM IT% is number of points to be added NEXT call.
  19.    DL=(B-A)/IT% :REM This is the spacing of the points to be added.
  20.    X=A+0.5*DL
  21.    SM=0
  22.    FOR J% = 1 TO IT%
  23.       SM = SM + FNarg(X)
  24.       X = X + DL
  25.    NEXT J%
  26.    S=0.5*(S+(B-A)*SM/IT%):REM This replaces S by its refined value.
  27. ENDIF
  28. =S                                                                     
  29.  
  30. ******* Must have FNarg attached
  31.