dbesj.f 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. *DECK DBESJ
  2. SUBROUTINE DBESJ (X, ALPHA, N, Y, NZ)
  3. C***BEGIN PROLOGUE DBESJ
  4. C***PURPOSE Compute an N member sequence of J Bessel functions
  5. C J/SUB(ALPHA+K-1)/(X), K=1,...,N for non-negative ALPHA
  6. C and X.
  7. C***LIBRARY SLATEC
  8. C***CATEGORY C10A3
  9. C***TYPE DOUBLE PRECISION (BESJ-S, DBESJ-D)
  10. C***KEYWORDS J BESSEL FUNCTION, SPECIAL FUNCTIONS
  11. C***AUTHOR Amos, D. E., (SNLA)
  12. C Daniel, S. L., (SNLA)
  13. C Weston, M. K., (SNLA)
  14. C***DESCRIPTION
  15. C
  16. C Abstract **** a double precision routine ****
  17. C DBESJ computes an N member sequence of J Bessel functions
  18. C J/sub(ALPHA+K-1)/(X), K=1,...,N for non-negative ALPHA and X.
  19. C A combination of the power series, the asymptotic expansion
  20. C for X to infinity and the uniform asymptotic expansion for
  21. C NU to infinity are applied over subdivisions of the (NU,X)
  22. C plane. For values of (NU,X) not covered by one of these
  23. C formulae, the order is incremented or decremented by integer
  24. C values into a region where one of the formulae apply. Backward
  25. C recursion is applied to reduce orders by integer values except
  26. C where the entire sequence lies in the oscillatory region. In
  27. C this case forward recursion is stable and values from the
  28. C asymptotic expansion for X to infinity start the recursion
  29. C when it is efficient to do so. Leading terms of the series and
  30. C uniform expansion are tested for underflow. If a sequence is
  31. C requested and the last member would underflow, the result is
  32. C set to zero and the next lower order tried, etc., until a
  33. C member comes on scale or all members are set to zero.
  34. C Overflow cannot occur.
  35. C
  36. C The maximum number of significant digits obtainable
  37. C is the smaller of 14 and the number of digits carried in
  38. C double precision arithmetic.
  39. C
  40. C Description of Arguments
  41. C
  42. C Input X,ALPHA are double precision
  43. C X - X .GE. 0.0D0
  44. C ALPHA - order of first member of the sequence,
  45. C ALPHA .GE. 0.0D0
  46. C N - number of members in the sequence, N .GE. 1
  47. C
  48. C Output Y is double precision
  49. C Y - a vector whose first N components contain
  50. C values for J/sub(ALPHA+K-1)/(X), K=1,...,N
  51. C NZ - number of components of Y set to zero due to
  52. C underflow,
  53. C NZ=0 , normal return, computation completed
  54. C NZ .NE. 0, last NZ components of Y set to zero,
  55. C Y(K)=0.0D0, K=N-NZ+1,...,N.
  56. C
  57. C Error Conditions
  58. C Improper input arguments - a fatal error
  59. C Underflow - a non-fatal error (NZ .NE. 0)
  60. C
  61. C***REFERENCES D. E. Amos, S. L. Daniel and M. K. Weston, CDC 6600
  62. C subroutines IBESS and JBESS for Bessel functions
  63. C I(NU,X) and J(NU,X), X .GE. 0, NU .GE. 0, ACM
  64. C Transactions on Mathematical Software 3, (1977),
  65. C pp. 76-92.
  66. C F. W. J. Olver, Tables of Bessel Functions of Moderate
  67. C or Large Orders, NPL Mathematical Tables 6, Her
  68. C Majesty's Stationery Office, London, 1962.
  69. C***ROUTINES CALLED D1MACH, DASYJY, DJAIRY, DLNGAM, I1MACH, XERMSG
  70. C***REVISION HISTORY (YYMMDD)
  71. C 750101 DATE WRITTEN
  72. C 890531 Changed all specific intrinsics to generic. (WRB)
  73. C 890911 Removed unnecessary intrinsics. (WRB)
  74. C 890911 REVISION DATE from Version 3.2
  75. C 891214 Prologue converted to Version 4.0 format. (BAB)
  76. C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
  77. C 900326 Removed duplicate information from DESCRIPTION section.
  78. C (WRB)
  79. C 920501 Reformatted the REFERENCES section. (WRB)
  80. C***END PROLOGUE DBESJ
  81. EXTERNAL DJAIRY
  82. INTEGER I,IALP,IDALP,IFLW,IN,INLIM,IS,I1,I2,K,KK,KM,KT,N,NN,
  83. 1 NS,NZ
  84. INTEGER I1MACH
  85. DOUBLE PRECISION AK,AKM,ALPHA,ANS,AP,ARG,COEF,DALPHA,DFN,DTM,
  86. 1 EARG,ELIM1,ETX,FIDAL,FLGJY,FN,FNF,FNI,FNP1,FNU,
  87. 2 FNULIM,GLN,PDF,PIDT,PP,RDEN,RELB,RTTP,RTWO,RTX,RZDEN,
  88. 3 S,SA,SB,SXO2,S1,S2,T,TA,TAU,TB,TEMP,TFN,TM,TOL,
  89. 4 TOLLN,TRX,TX,T1,T2,WK,X,XO2,XO2L,Y,SLIM,RTOL
  90. SAVE RTWO, PDF, RTTP, PIDT, PP, INLIM, FNULIM
  91. DOUBLE PRECISION D1MACH, DLNGAM
  92. DIMENSION Y(*), TEMP(3), FNULIM(2), PP(4), WK(7)
  93. DATA RTWO,PDF,RTTP,PIDT / 1.34839972492648D+00,
  94. 1 7.85398163397448D-01, 7.97884560802865D-01, 1.57079632679490D+00/
  95. DATA PP(1), PP(2), PP(3), PP(4) / 8.72909153935547D+00,
  96. 1 2.65693932265030D-01, 1.24578576865586D-01, 7.70133747430388D-04/
  97. DATA INLIM / 150 /
  98. DATA FNULIM(1), FNULIM(2) / 100.0D0, 60.0D0 /
  99. C***FIRST EXECUTABLE STATEMENT DBESJ
  100. NZ = 0
  101. KT = 1
  102. NS=0
  103. C I1MACH(14) REPLACES I1MACH(11) IN A DOUBLE PRECISION CODE
  104. C I1MACH(15) REPLACES I1MACH(12) IN A DOUBLE PRECISION CODE
  105. TA = D1MACH(3)
  106. TOL = MAX(TA,1.0D-15)
  107. I1 = I1MACH(14) + 1
  108. I2 = I1MACH(15)
  109. TB = D1MACH(5)
  110. ELIM1 = -2.303D0*(I2*TB+3.0D0)
  111. RTOL=1.0D0/TOL
  112. SLIM=D1MACH(1)*RTOL*1.0D+3
  113. C TOLLN = -LN(TOL)
  114. TOLLN = 2.303D0*TB*I1
  115. TOLLN = MIN(TOLLN,34.5388D0)
  116. IF (N-1) 720, 10, 20
  117. 10 KT = 2
  118. 20 NN = N
  119. IF (X) 730, 30, 80
  120. 30 IF (ALPHA) 710, 40, 50
  121. 40 Y(1) = 1.0D0
  122. IF (N.EQ.1) RETURN
  123. I1 = 2
  124. GO TO 60
  125. 50 I1 = 1
  126. 60 DO 70 I=I1,N
  127. Y(I) = 0.0D0
  128. 70 CONTINUE
  129. RETURN
  130. 80 CONTINUE
  131. IF (ALPHA.LT.0.0D0) GO TO 710
  132. C
  133. IALP = INT(ALPHA)
  134. FNI = IALP + N - 1
  135. FNF = ALPHA - IALP
  136. DFN = FNI + FNF
  137. FNU = DFN
  138. XO2 = X*0.5D0
  139. SXO2 = XO2*XO2
  140. C
  141. C DECISION TREE FOR REGION WHERE SERIES, ASYMPTOTIC EXPANSION FOR X
  142. C TO INFINITY AND ASYMPTOTIC EXPANSION FOR NU TO INFINITY ARE
  143. C APPLIED.
  144. C
  145. IF (SXO2.LE.(FNU+1.0D0)) GO TO 90
  146. TA = MAX(20.0D0,FNU)
  147. IF (X.GT.TA) GO TO 120
  148. IF (X.GT.12.0D0) GO TO 110
  149. XO2L = LOG(XO2)
  150. NS = INT(SXO2-FNU) + 1
  151. GO TO 100
  152. 90 FN = FNU
  153. FNP1 = FN + 1.0D0
  154. XO2L = LOG(XO2)
  155. IS = KT
  156. IF (X.LE.0.50D0) GO TO 330
  157. NS = 0
  158. 100 FNI = FNI + NS
  159. DFN = FNI + FNF
  160. FN = DFN
  161. FNP1 = FN + 1.0D0
  162. IS = KT
  163. IF (N-1+NS.GT.0) IS = 3
  164. GO TO 330
  165. 110 ANS = MAX(36.0D0-FNU,0.0D0)
  166. NS = INT(ANS)
  167. FNI = FNI + NS
  168. DFN = FNI + FNF
  169. FN = DFN
  170. IS = KT
  171. IF (N-1+NS.GT.0) IS = 3
  172. GO TO 130
  173. 120 CONTINUE
  174. RTX = SQRT(X)
  175. TAU = RTWO*RTX
  176. TA = TAU + FNULIM(KT)
  177. IF (FNU.LE.TA) GO TO 480
  178. FN = FNU
  179. IS = KT
  180. C
  181. C UNIFORM ASYMPTOTIC EXPANSION FOR NU TO INFINITY
  182. C
  183. 130 CONTINUE
  184. I1 = ABS(3-IS)
  185. I1 = MAX(I1,1)
  186. FLGJY = 1.0D0
  187. CALL DASYJY(DJAIRY,X,FN,FLGJY,I1,TEMP(IS),WK,IFLW)
  188. IF(IFLW.NE.0) GO TO 380
  189. GO TO (320, 450, 620), IS
  190. 310 TEMP(1) = TEMP(3)
  191. KT = 1
  192. 320 IS = 2
  193. FNI = FNI - 1.0D0
  194. DFN = FNI + FNF
  195. FN = DFN
  196. IF(I1.EQ.2) GO TO 450
  197. GO TO 130
  198. C
  199. C SERIES FOR (X/2)**2.LE.NU+1
  200. C
  201. 330 CONTINUE
  202. GLN = DLNGAM(FNP1)
  203. ARG = FN*XO2L - GLN
  204. IF (ARG.LT.(-ELIM1)) GO TO 400
  205. EARG = EXP(ARG)
  206. 340 CONTINUE
  207. S = 1.0D0
  208. IF (X.LT.TOL) GO TO 360
  209. AK = 3.0D0
  210. T2 = 1.0D0
  211. T = 1.0D0
  212. S1 = FN
  213. DO 350 K=1,17
  214. S2 = T2 + S1
  215. T = -T*SXO2/S2
  216. S = S + T
  217. IF (ABS(T).LT.TOL) GO TO 360
  218. T2 = T2 + AK
  219. AK = AK + 2.0D0
  220. S1 = S1 + FN
  221. 350 CONTINUE
  222. 360 CONTINUE
  223. TEMP(IS) = S*EARG
  224. GO TO (370, 450, 610), IS
  225. 370 EARG = EARG*FN/XO2
  226. FNI = FNI - 1.0D0
  227. DFN = FNI + FNF
  228. FN = DFN
  229. IS = 2
  230. GO TO 340
  231. C
  232. C SET UNDERFLOW VALUE AND UPDATE PARAMETERS
  233. C UNDERFLOW CAN ONLY OCCUR FOR NS=0 SINCE THE ORDER MUST BE LARGER
  234. C THAN 36. THEREFORE, NS NEE NOT BE TESTED.
  235. C
  236. 380 Y(NN) = 0.0D0
  237. NN = NN - 1
  238. FNI = FNI - 1.0D0
  239. DFN = FNI + FNF
  240. FN = DFN
  241. IF (NN-1) 440, 390, 130
  242. 390 KT = 2
  243. IS = 2
  244. GO TO 130
  245. 400 Y(NN) = 0.0D0
  246. NN = NN - 1
  247. FNP1 = FN
  248. FNI = FNI - 1.0D0
  249. DFN = FNI + FNF
  250. FN = DFN
  251. IF (NN-1) 440, 410, 420
  252. 410 KT = 2
  253. IS = 2
  254. 420 IF (SXO2.LE.FNP1) GO TO 430
  255. GO TO 130
  256. 430 ARG = ARG - XO2L + LOG(FNP1)
  257. IF (ARG.LT.(-ELIM1)) GO TO 400
  258. GO TO 330
  259. 440 NZ = N - NN
  260. RETURN
  261. C
  262. C BACKWARD RECURSION SECTION
  263. C
  264. 450 CONTINUE
  265. IF(NS.NE.0) GO TO 451
  266. NZ = N - NN
  267. IF (KT.EQ.2) GO TO 470
  268. C BACKWARD RECUR FROM INDEX ALPHA+NN-1 TO ALPHA
  269. Y(NN) = TEMP(1)
  270. Y(NN-1) = TEMP(2)
  271. IF (NN.EQ.2) RETURN
  272. 451 CONTINUE
  273. TRX = 2.0D0/X
  274. DTM = FNI
  275. TM = (DTM+FNF)*TRX
  276. AK=1.0D0
  277. TA=TEMP(1)
  278. TB=TEMP(2)
  279. IF(ABS(TA).GT.SLIM) GO TO 455
  280. TA=TA*RTOL
  281. TB=TB*RTOL
  282. AK=TOL
  283. 455 CONTINUE
  284. KK=2
  285. IN=NS-1
  286. IF(IN.EQ.0) GO TO 690
  287. IF(NS.NE.0) GO TO 670
  288. K=NN-2
  289. DO 460 I=3,NN
  290. S=TB
  291. TB = TM*TB - TA
  292. TA=S
  293. Y(K)=TB*AK
  294. DTM = DTM - 1.0D0
  295. TM = (DTM+FNF)*TRX
  296. K = K - 1
  297. 460 CONTINUE
  298. RETURN
  299. 470 Y(1) = TEMP(2)
  300. RETURN
  301. C
  302. C ASYMPTOTIC EXPANSION FOR X TO INFINITY WITH FORWARD RECURSION IN
  303. C OSCILLATORY REGION X.GT.MAX(20, NU), PROVIDED THE LAST MEMBER
  304. C OF THE SEQUENCE IS ALSO IN THE REGION.
  305. C
  306. 480 CONTINUE
  307. IN = INT(ALPHA-TAU+2.0D0)
  308. IF (IN.LE.0) GO TO 490
  309. IDALP = IALP - IN - 1
  310. KT = 1
  311. GO TO 500
  312. 490 CONTINUE
  313. IDALP = IALP
  314. IN = 0
  315. 500 IS = KT
  316. FIDAL = IDALP
  317. DALPHA = FIDAL + FNF
  318. ARG = X - PIDT*DALPHA - PDF
  319. SA = SIN(ARG)
  320. SB = COS(ARG)
  321. COEF = RTTP/RTX
  322. ETX = 8.0D0*X
  323. 510 CONTINUE
  324. DTM = FIDAL + FIDAL
  325. DTM = DTM*DTM
  326. TM = 0.0D0
  327. IF (FIDAL.EQ.0.0D0 .AND. ABS(FNF).LT.TOL) GO TO 520
  328. TM = 4.0D0*FNF*(FIDAL+FIDAL+FNF)
  329. 520 CONTINUE
  330. TRX = DTM - 1.0D0
  331. T2 = (TRX+TM)/ETX
  332. S2 = T2
  333. RELB = TOL*ABS(T2)
  334. T1 = ETX
  335. S1 = 1.0D0
  336. FN = 1.0D0
  337. AK = 8.0D0
  338. DO 530 K=1,13
  339. T1 = T1 + ETX
  340. FN = FN + AK
  341. TRX = DTM - FN
  342. AP = TRX + TM
  343. T2 = -T2*AP/T1
  344. S1 = S1 + T2
  345. T1 = T1 + ETX
  346. AK = AK + 8.0D0
  347. FN = FN + AK
  348. TRX = DTM - FN
  349. AP = TRX + TM
  350. T2 = T2*AP/T1
  351. S2 = S2 + T2
  352. IF (ABS(T2).LE.RELB) GO TO 540
  353. AK = AK + 8.0D0
  354. 530 CONTINUE
  355. 540 TEMP(IS) = COEF*(S1*SB-S2*SA)
  356. IF(IS.EQ.2) GO TO 560
  357. FIDAL = FIDAL + 1.0D0
  358. DALPHA = FIDAL + FNF
  359. IS = 2
  360. TB = SA
  361. SA = -SB
  362. SB = TB
  363. GO TO 510
  364. C
  365. C FORWARD RECURSION SECTION
  366. C
  367. 560 IF (KT.EQ.2) GO TO 470
  368. S1 = TEMP(1)
  369. S2 = TEMP(2)
  370. TX = 2.0D0/X
  371. TM = DALPHA*TX
  372. IF (IN.EQ.0) GO TO 580
  373. C
  374. C FORWARD RECUR TO INDEX ALPHA
  375. C
  376. DO 570 I=1,IN
  377. S = S2
  378. S2 = TM*S2 - S1
  379. TM = TM + TX
  380. S1 = S
  381. 570 CONTINUE
  382. IF (NN.EQ.1) GO TO 600
  383. S = S2
  384. S2 = TM*S2 - S1
  385. TM = TM + TX
  386. S1 = S
  387. 580 CONTINUE
  388. C
  389. C FORWARD RECUR FROM INDEX ALPHA TO ALPHA+N-1
  390. C
  391. Y(1) = S1
  392. Y(2) = S2
  393. IF (NN.EQ.2) RETURN
  394. DO 590 I=3,NN
  395. Y(I) = TM*Y(I-1) - Y(I-2)
  396. TM = TM + TX
  397. 590 CONTINUE
  398. RETURN
  399. 600 Y(1) = S2
  400. RETURN
  401. C
  402. C BACKWARD RECURSION WITH NORMALIZATION BY
  403. C ASYMPTOTIC EXPANSION FOR NU TO INFINITY OR POWER SERIES.
  404. C
  405. 610 CONTINUE
  406. C COMPUTATION OF LAST ORDER FOR SERIES NORMALIZATION
  407. AKM = MAX(3.0D0-FN,0.0D0)
  408. KM = INT(AKM)
  409. TFN = FN + KM
  410. TA = (GLN+TFN-0.9189385332D0-0.0833333333D0/TFN)/(TFN+0.5D0)
  411. TA = XO2L - TA
  412. TB = -(1.0D0-1.5D0/TFN)/TFN
  413. AKM = TOLLN/(-TA+SQRT(TA*TA-TOLLN*TB)) + 1.5D0
  414. IN = KM + INT(AKM)
  415. GO TO 660
  416. 620 CONTINUE
  417. C COMPUTATION OF LAST ORDER FOR ASYMPTOTIC EXPANSION NORMALIZATION
  418. GLN = WK(3) + WK(2)
  419. IF (WK(6).GT.30.0D0) GO TO 640
  420. RDEN = (PP(4)*WK(6)+PP(3))*WK(6) + 1.0D0
  421. RZDEN = PP(1) + PP(2)*WK(6)
  422. TA = RZDEN/RDEN
  423. IF (WK(1).LT.0.10D0) GO TO 630
  424. TB = GLN/WK(5)
  425. GO TO 650
  426. 630 TB=(1.259921049D0+(0.1679894730D0+0.0887944358D0*WK(1))*WK(1))
  427. 1 /WK(7)
  428. GO TO 650
  429. 640 CONTINUE
  430. TA = 0.5D0*TOLLN/WK(4)
  431. TA=((0.0493827160D0*TA-0.1111111111D0)*TA+0.6666666667D0)*TA*WK(6)
  432. IF (WK(1).LT.0.10D0) GO TO 630
  433. TB = GLN/WK(5)
  434. 650 IN = INT(TA/TB+1.5D0)
  435. IF (IN.GT.INLIM) GO TO 310
  436. 660 CONTINUE
  437. DTM = FNI + IN
  438. TRX = 2.0D0/X
  439. TM = (DTM+FNF)*TRX
  440. TA = 0.0D0
  441. TB = TOL
  442. KK = 1
  443. AK=1.0D0
  444. 670 CONTINUE
  445. C
  446. C BACKWARD RECUR UNINDEXED
  447. C
  448. DO 680 I=1,IN
  449. S = TB
  450. TB = TM*TB - TA
  451. TA = S
  452. DTM = DTM - 1.0D0
  453. TM = (DTM+FNF)*TRX
  454. 680 CONTINUE
  455. C NORMALIZATION
  456. IF (KK.NE.1) GO TO 690
  457. S=TEMP(3)
  458. SA=TA/TB
  459. TA=S
  460. TB=S
  461. IF(ABS(S).GT.SLIM) GO TO 685
  462. TA=TA*RTOL
  463. TB=TB*RTOL
  464. AK=TOL
  465. 685 CONTINUE
  466. TA=TA*SA
  467. KK = 2
  468. IN = NS
  469. IF (NS.NE.0) GO TO 670
  470. 690 Y(NN) = TB*AK
  471. NZ = N - NN
  472. IF (NN.EQ.1) RETURN
  473. K = NN - 1
  474. S=TB
  475. TB = TM*TB - TA
  476. TA=S
  477. Y(K)=TB*AK
  478. IF (NN.EQ.2) RETURN
  479. DTM = DTM - 1.0D0
  480. TM = (DTM+FNF)*TRX
  481. K=NN-2
  482. C
  483. C BACKWARD RECUR INDEXED
  484. C
  485. DO 700 I=3,NN
  486. S=TB
  487. TB = TM*TB - TA
  488. TA=S
  489. Y(K)=TB*AK
  490. DTM = DTM - 1.0D0
  491. TM = (DTM+FNF)*TRX
  492. K = K - 1
  493. 700 CONTINUE
  494. RETURN
  495. C
  496. C
  497. C
  498. 710 CONTINUE
  499. CALL XERMSG ('SLATEC', 'DBESJ', 'ORDER, ALPHA, LESS THAN ZERO.',
  500. + 2, 1)
  501. RETURN
  502. 720 CONTINUE
  503. CALL XERMSG ('SLATEC', 'DBESJ', 'N LESS THAN ONE.', 2, 1)
  504. RETURN
  505. 730 CONTINUE
  506. CALL XERMSG ('SLATEC', 'DBESJ', 'X LESS THAN ZERO.', 2, 1)
  507. RETURN
  508. END