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

  1. DEF FNqtrap(A,B)
  2. REM Returns the integral of the function FNarg(X) from A to B. 
  3. REM The parameter EPS can be set to the desired fractional accuracy
  4. REM and JMAX% so that 2^(JMAX%-1) is the maximum allowed number of
  5. REM steps.  Integration is performed by the trapezoidal rule.
  6. REM :
  7. LOCAL EPS, JMAX%, OLDS, I%, DONE%
  8. EPS = 1E-6: JMAX% = 20
  9. OLDS=-1E30            :REM any number unlikely to be the mean of the
  10. REM                        function at its endpoints will do here.
  11. FOR I%=1 TO JMAX%
  12.    S = FNtrapzd(A,B,I%)
  13.    IF ABS(S-OLDS) < EPS*ABS(OLDS) THEN DONE% = TRUE: I%=JMAX%
  14.    OLDS=S
  15. NEXT I%
  16. IF DONE% = TRUE THEN =S
  17. PRINT "Too many steps": STOP
  18.  
  19. *******Must append FNtrapzd 
  20.        -- to which FNarg must be attached.