qawse.f 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. *DECK QAWSE
  2. SUBROUTINE QAWSE (F, A, B, ALFA, BETA, INTEGR, EPSABS, EPSREL,
  3. + LIMIT, RESULT, ABSERR, NEVAL, IER, ALIST, BLIST, RLIST, ELIST,
  4. + IORD, LAST)
  5. C***BEGIN PROLOGUE QAWSE
  6. C***PURPOSE The routine calculates an approximation result to a given
  7. C definite integral I = Integral of F*W over (A,B),
  8. C (where W shows a singular behaviour at the end points,
  9. C see parameter INTEGR).
  10. C Hopefully satisfying following claim for accuracy
  11. C ABS(I-RESULT).LE.MAX(EPSABS,EPSREL*ABS(I)).
  12. C***LIBRARY SLATEC (QUADPACK)
  13. C***CATEGORY H2A2A1
  14. C***TYPE SINGLE PRECISION (QAWSE-S, DQAWSE-D)
  15. C***KEYWORDS ALGEBRAIC-LOGARITHMIC END POINT SINGULARITIES,
  16. C AUTOMATIC INTEGRATOR, CLENSHAW-CURTIS METHOD, QUADPACK,
  17. C QUADRATURE, SPECIAL-PURPOSE
  18. C***AUTHOR Piessens, Robert
  19. C Applied Mathematics and Programming Division
  20. C K. U. Leuven
  21. C de Doncker, Elise
  22. C Applied Mathematics and Programming Division
  23. C K. U. Leuven
  24. C***DESCRIPTION
  25. C
  26. C Integration of functions having algebraico-logarithmic
  27. C end point singularities
  28. C Standard fortran subroutine
  29. C Real version
  30. C
  31. C PARAMETERS
  32. C ON ENTRY
  33. C F - Real
  34. C Function subprogram defining the integrand
  35. C function F(X). The actual name for F needs to be
  36. C declared E X T E R N A L in the driver program.
  37. C
  38. C A - Real
  39. C Lower limit of integration
  40. C
  41. C B - Real
  42. C Upper limit of integration, B.GT.A
  43. C If B.LE.A, the routine will end with IER = 6.
  44. C
  45. C ALFA - Real
  46. C Parameter in the WEIGHT function, ALFA.GT.(-1)
  47. C If ALFA.LE.(-1), the routine will end with
  48. C IER = 6.
  49. C
  50. C BETA - Real
  51. C Parameter in the WEIGHT function, BETA.GT.(-1)
  52. C If BETA.LE.(-1), the routine will end with
  53. C IER = 6.
  54. C
  55. C INTEGR - Integer
  56. C Indicates which WEIGHT function is to be used
  57. C = 1 (X-A)**ALFA*(B-X)**BETA
  58. C = 2 (X-A)**ALFA*(B-X)**BETA*LOG(X-A)
  59. C = 3 (X-A)**ALFA*(B-X)**BETA*LOG(B-X)
  60. C = 4 (X-A)**ALFA*(B-X)**BETA*LOG(X-A)*LOG(B-X)
  61. C If INTEGR.LT.1 or INTEGR.GT.4, the routine
  62. C will end with IER = 6.
  63. C
  64. C EPSABS - Real
  65. C Absolute accuracy requested
  66. C EPSREL - Real
  67. C Relative accuracy requested
  68. C If EPSABS.LE.0
  69. C and EPSREL.LT.MAX(50*REL.MACH.ACC.,0.5D-28),
  70. C the routine will end with IER = 6.
  71. C
  72. C LIMIT - Integer
  73. C Gives an upper bound on the number of subintervals
  74. C in the partition of (A,B), LIMIT.GE.2
  75. C If LIMIT.LT.2, the routine will end with IER = 6.
  76. C
  77. C ON RETURN
  78. C RESULT - Real
  79. C Approximation to the integral
  80. C
  81. C ABSERR - Real
  82. C Estimate of the modulus of the absolute error,
  83. C which should equal or exceed ABS(I-RESULT)
  84. C
  85. C NEVAL - Integer
  86. C Number of integrand evaluations
  87. C
  88. C IER - Integer
  89. C IER = 0 Normal and reliable termination of the
  90. C routine. It is assumed that the requested
  91. C accuracy has been achieved.
  92. C IER.GT.0 Abnormal termination of the routine
  93. C the estimates for the integral and error
  94. C are less reliable. It is assumed that the
  95. C requested accuracy has not been achieved.
  96. C ERROR MESSAGES
  97. C = 1 Maximum number of subdivisions allowed
  98. C has been achieved. One can allow more
  99. C subdivisions by increasing the value of
  100. C LIMIT. However, if this yields no
  101. C improvement, it is advised to analyze the
  102. C integrand in order to determine the
  103. C integration difficulties which prevent the
  104. C requested tolerance from being achieved.
  105. C In case of a jump DISCONTINUITY or a local
  106. C SINGULARITY of algebraico-logarithmic type
  107. C at one or more interior points of the
  108. C integration range, one should proceed by
  109. C splitting up the interval at these
  110. C points and calling the integrator on the
  111. C subranges.
  112. C = 2 The occurrence of roundoff error is
  113. C detected, which prevents the requested
  114. C tolerance from being achieved.
  115. C = 3 Extremely bad integrand behaviour occurs
  116. C at some points of the integration
  117. C interval.
  118. C = 6 The input is invalid, because
  119. C B.LE.A or ALFA.LE.(-1) or BETA.LE.(-1), or
  120. C INTEGR.LT.1 or INTEGR.GT.4, or
  121. C (EPSABS.LE.0 and
  122. C EPSREL.LT.MAX(50*REL.MACH.ACC.,0.5D-28),
  123. C or LIMIT.LT.2.
  124. C RESULT, ABSERR, NEVAL, RLIST(1), ELIST(1),
  125. C IORD(1) and LAST are set to zero. ALIST(1)
  126. C and BLIST(1) are set to A and B
  127. C respectively.
  128. C
  129. C ALIST - Real
  130. C Vector of dimension at least LIMIT, the first
  131. C LAST elements of which are the left
  132. C end points of the subintervals in the partition
  133. C of the given integration range (A,B)
  134. C
  135. C BLIST - Real
  136. C Vector of dimension at least LIMIT, the first
  137. C LAST elements of which are the right
  138. C end points of the subintervals in the partition
  139. C of the given integration range (A,B)
  140. C
  141. C RLIST - Real
  142. C Vector of dimension at least LIMIT, the first
  143. C LAST elements of which are the integral
  144. C approximations on the subintervals
  145. C
  146. C ELIST - Real
  147. C Vector of dimension at least LIMIT, the first
  148. C LAST elements of which are the moduli of the
  149. C absolute error estimates on the subintervals
  150. C
  151. C IORD - Integer
  152. C Vector of dimension at least LIMIT, the first K
  153. C of which are pointers to the error
  154. C estimates over the subintervals, so that
  155. C ELIST(IORD(1)), ..., ELIST(IORD(K)) with K = LAST
  156. C If LAST.LE.(LIMIT/2+2), and K = LIMIT+1-LAST
  157. C otherwise form a decreasing sequence
  158. C
  159. C LAST - Integer
  160. C Number of subintervals actually produced in
  161. C the subdivision process
  162. C
  163. C***REFERENCES (NONE)
  164. C***ROUTINES CALLED QC25S, QMOMO, QPSRT, R1MACH
  165. C***REVISION HISTORY (YYMMDD)
  166. C 800101 DATE WRITTEN
  167. C 890531 Changed all specific intrinsics to generic. (WRB)
  168. C 890831 Modified array declarations. (WRB)
  169. C 890831 REVISION DATE from Version 3.2
  170. C 891214 Prologue converted to Version 4.0 format. (BAB)
  171. C***END PROLOGUE QAWSE
  172. C
  173. REAL A,ABSERR,ALFA,ALIST,AREA,AREA1,AREA12,
  174. 1 AREA2,A1,A2,B,BETA,BLIST,B1,B2,CENTRE,
  175. 2 R1MACH,ELIST,EPMACH,EPSABS,EPSREL,ERRBND,ERRMAX,
  176. 3 ERROR1,ERRO12,ERROR2,ERRSUM,F,RESAS1,RESAS2,RESULT,RG,RH,RI,RJ,
  177. 4 RLIST,UFLOW
  178. INTEGER IER,INTEGR,IORD,IROFF1,IROFF2,K,LAST,
  179. 1 LIMIT,MAXERR,NEV,NEVAL,NRMAX
  180. C
  181. EXTERNAL F
  182. C
  183. DIMENSION ALIST(*),BLIST(*),RLIST(*),ELIST(*),
  184. 1 IORD(*),RI(25),RJ(25),RH(25),RG(25)
  185. C
  186. C LIST OF MAJOR VARIABLES
  187. C -----------------------
  188. C
  189. C ALIST - LIST OF LEFT END POINTS OF ALL SUBINTERVALS
  190. C CONSIDERED UP TO NOW
  191. C BLIST - LIST OF RIGHT END POINTS OF ALL SUBINTERVALS
  192. C CONSIDERED UP TO NOW
  193. C RLIST(I) - APPROXIMATION TO THE INTEGRAL OVER
  194. C (ALIST(I),BLIST(I))
  195. C ELIST(I) - ERROR ESTIMATE APPLYING TO RLIST(I)
  196. C MAXERR - POINTER TO THE INTERVAL WITH LARGEST
  197. C ERROR ESTIMATE
  198. C ERRMAX - ELIST(MAXERR)
  199. C AREA - SUM OF THE INTEGRALS OVER THE SUBINTERVALS
  200. C ERRSUM - SUM OF THE ERRORS OVER THE SUBINTERVALS
  201. C ERRBND - REQUESTED ACCURACY MAX(EPSABS,EPSREL*
  202. C ABS(RESULT))
  203. C *****1 - VARIABLE FOR THE LEFT SUBINTERVAL
  204. C *****2 - VARIABLE FOR THE RIGHT SUBINTERVAL
  205. C LAST - INDEX FOR SUBDIVISION
  206. C
  207. C
  208. C MACHINE DEPENDENT CONSTANTS
  209. C ---------------------------
  210. C
  211. C EPMACH IS THE LARGEST RELATIVE SPACING.
  212. C UFLOW IS THE SMALLEST POSITIVE MAGNITUDE.
  213. C
  214. C***FIRST EXECUTABLE STATEMENT QAWSE
  215. EPMACH = R1MACH(4)
  216. UFLOW = R1MACH(1)
  217. C
  218. C TEST ON VALIDITY OF PARAMETERS
  219. C ------------------------------
  220. C
  221. IER = 6
  222. NEVAL = 0
  223. LAST = 0
  224. RLIST(1) = 0.0E+00
  225. ELIST(1) = 0.0E+00
  226. IORD(1) = 0
  227. RESULT = 0.0E+00
  228. ABSERR = 0.0E+00
  229. IF (B.LE.A.OR.(EPSABS.EQ.0.0E+00.AND.
  230. 1 EPSREL.LT.MAX(0.5E+02*EPMACH,0.5E-14)).OR.ALFA.LE.(-0.1E+01)
  231. 2 .OR.BETA.LE.(-0.1E+01).OR.INTEGR.LT.1.OR.INTEGR.GT.4.OR.
  232. 3 LIMIT.LT.2) GO TO 999
  233. IER = 0
  234. C
  235. C COMPUTE THE MODIFIED CHEBYSHEV MOMENTS.
  236. C
  237. CALL QMOMO(ALFA,BETA,RI,RJ,RG,RH,INTEGR)
  238. C
  239. C INTEGRATE OVER THE INTERVALS (A,(A+B)/2)
  240. C AND ((A+B)/2,B).
  241. C
  242. CENTRE = 0.5E+00*(B+A)
  243. CALL QC25S(F,A,B,A,CENTRE,ALFA,BETA,RI,RJ,RG,RH,AREA1,
  244. 1 ERROR1,RESAS1,INTEGR,NEV)
  245. NEVAL = NEV
  246. CALL QC25S(F,A,B,CENTRE,B,ALFA,BETA,RI,RJ,RG,RH,AREA2,
  247. 1 ERROR2,RESAS2,INTEGR,NEV)
  248. LAST = 2
  249. NEVAL = NEVAL+NEV
  250. RESULT = AREA1+AREA2
  251. ABSERR = ERROR1+ERROR2
  252. C
  253. C TEST ON ACCURACY.
  254. C
  255. ERRBND = MAX(EPSABS,EPSREL*ABS(RESULT))
  256. C
  257. C INITIALIZATION
  258. C --------------
  259. C
  260. IF(ERROR2.GT.ERROR1) GO TO 10
  261. ALIST(1) = A
  262. ALIST(2) = CENTRE
  263. BLIST(1) = CENTRE
  264. BLIST(2) = B
  265. RLIST(1) = AREA1
  266. RLIST(2) = AREA2
  267. ELIST(1) = ERROR1
  268. ELIST(2) = ERROR2
  269. GO TO 20
  270. 10 ALIST(1) = CENTRE
  271. ALIST(2) = A
  272. BLIST(1) = B
  273. BLIST(2) = CENTRE
  274. RLIST(1) = AREA2
  275. RLIST(2) = AREA1
  276. ELIST(1) = ERROR2
  277. ELIST(2) = ERROR1
  278. 20 IORD(1) = 1
  279. IORD(2) = 2
  280. IF(LIMIT.EQ.2) IER = 1
  281. IF(ABSERR.LE.ERRBND.OR.IER.EQ.1) GO TO 999
  282. ERRMAX = ELIST(1)
  283. MAXERR = 1
  284. NRMAX = 1
  285. AREA = RESULT
  286. ERRSUM = ABSERR
  287. IROFF1 = 0
  288. IROFF2 = 0
  289. C
  290. C MAIN DO-LOOP
  291. C ------------
  292. C
  293. DO 60 LAST = 3,LIMIT
  294. C
  295. C BISECT THE SUBINTERVAL WITH LARGEST ERROR ESTIMATE.
  296. C
  297. A1 = ALIST(MAXERR)
  298. B1 = 0.5E+00*(ALIST(MAXERR)+BLIST(MAXERR))
  299. A2 = B1
  300. B2 = BLIST(MAXERR)
  301. C
  302. CALL QC25S(F,A,B,A1,B1,ALFA,BETA,RI,RJ,RG,RH,AREA1,
  303. 1 ERROR1,RESAS1,INTEGR,NEV)
  304. NEVAL = NEVAL+NEV
  305. CALL QC25S(F,A,B,A2,B2,ALFA,BETA,RI,RJ,RG,RH,AREA2,
  306. 1 ERROR2,RESAS2,INTEGR,NEV)
  307. NEVAL = NEVAL+NEV
  308. C
  309. C IMPROVE PREVIOUS APPROXIMATIONS INTEGRAL AND ERROR
  310. C AND TEST FOR ACCURACY.
  311. C
  312. AREA12 = AREA1+AREA2
  313. ERRO12 = ERROR1+ERROR2
  314. ERRSUM = ERRSUM+ERRO12-ERRMAX
  315. AREA = AREA+AREA12-RLIST(MAXERR)
  316. IF(A.EQ.A1.OR.B.EQ.B2) GO TO 30
  317. IF(RESAS1.EQ.ERROR1.OR.RESAS2.EQ.ERROR2) GO TO 30
  318. C
  319. C TEST FOR ROUNDOFF ERROR.
  320. C
  321. IF(ABS(RLIST(MAXERR)-AREA12).LT.0.1E-04*ABS(AREA12)
  322. 1 .AND.ERRO12.GE.0.99E+00*ERRMAX) IROFF1 = IROFF1+1
  323. IF(LAST.GT.10.AND.ERRO12.GT.ERRMAX) IROFF2 = IROFF2+1
  324. 30 RLIST(MAXERR) = AREA1
  325. RLIST(LAST) = AREA2
  326. C
  327. C TEST ON ACCURACY.
  328. C
  329. ERRBND = MAX(EPSABS,EPSREL*ABS(AREA))
  330. IF(ERRSUM.LE.ERRBND) GO TO 35
  331. C
  332. C SET ERROR FLAG IN THE CASE THAT THE NUMBER OF INTERVAL
  333. C BISECTIONS EXCEEDS LIMIT.
  334. C
  335. IF(LAST.EQ.LIMIT) IER = 1
  336. C
  337. C
  338. C SET ERROR FLAG IN THE CASE OF ROUNDOFF ERROR.
  339. C
  340. IF(IROFF1.GE.6.OR.IROFF2.GE.20) IER = 2
  341. C
  342. C SET ERROR FLAG IN THE CASE OF BAD INTEGRAND BEHAVIOUR
  343. C AT INTERIOR POINTS OF INTEGRATION RANGE.
  344. C
  345. IF(MAX(ABS(A1),ABS(B2)).LE.(0.1E+01+0.1E+03*EPMACH)*
  346. 1 (ABS(A2)+0.1E+04*UFLOW)) IER = 3
  347. C
  348. C APPEND THE NEWLY-CREATED INTERVALS TO THE LIST.
  349. C
  350. 35 IF(ERROR2.GT.ERROR1) GO TO 40
  351. ALIST(LAST) = A2
  352. BLIST(MAXERR) = B1
  353. BLIST(LAST) = B2
  354. ELIST(MAXERR) = ERROR1
  355. ELIST(LAST) = ERROR2
  356. GO TO 50
  357. 40 ALIST(MAXERR) = A2
  358. ALIST(LAST) = A1
  359. BLIST(LAST) = B1
  360. RLIST(MAXERR) = AREA2
  361. RLIST(LAST) = AREA1
  362. ELIST(MAXERR) = ERROR2
  363. ELIST(LAST) = ERROR1
  364. C
  365. C CALL SUBROUTINE QPSRT TO MAINTAIN THE DESCENDING ORDERING
  366. C IN THE LIST OF ERROR ESTIMATES AND SELECT THE
  367. C SUBINTERVAL WITH LARGEST ERROR ESTIMATE (TO BE
  368. C BISECTED NEXT).
  369. C
  370. 50 CALL QPSRT(LIMIT,LAST,MAXERR,ERRMAX,ELIST,IORD,NRMAX)
  371. C ***JUMP OUT OF DO-LOOP
  372. IF (IER.NE.0.OR.ERRSUM.LE.ERRBND) GO TO 70
  373. 60 CONTINUE
  374. C
  375. C COMPUTE FINAL RESULT.
  376. C ---------------------
  377. C
  378. 70 RESULT = 0.0E+00
  379. DO 80 K=1,LAST
  380. RESULT = RESULT+RLIST(K)
  381. 80 CONTINUE
  382. ABSERR = ERRSUM
  383. 999 RETURN
  384. END