rj.f 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. *DECK RJ
  2. REAL FUNCTION RJ (X, Y, Z, P, IER)
  3. C***BEGIN PROLOGUE RJ
  4. C***PURPOSE Compute the incomplete or complete (X or Y or Z is zero)
  5. C elliptic integral of the 3rd kind. For X, Y, and Z non-
  6. C negative, at most one of them zero, and P positive,
  7. C RJ(X,Y,Z,P) = Integral from zero to infinity of
  8. C -1/2 -1/2 -1/2 -1
  9. C (3/2)(t+X) (t+Y) (t+Z) (t+P) dt.
  10. C***LIBRARY SLATEC
  11. C***CATEGORY C14
  12. C***TYPE SINGLE PRECISION (RJ-S, DRJ-D)
  13. C***KEYWORDS COMPLETE ELLIPTIC INTEGRAL, DUPLICATION THEOREM,
  14. C INCOMPLETE ELLIPTIC INTEGRAL, INTEGRAL OF THE THIRD KIND,
  15. C TAYLOR SERIES
  16. C***AUTHOR Carlson, B. C.
  17. C Ames Laboratory-DOE
  18. C Iowa State University
  19. C Ames, IA 50011
  20. C Notis, E. M.
  21. C Ames Laboratory-DOE
  22. C Iowa State University
  23. C Ames, IA 50011
  24. C Pexton, R. L.
  25. C Lawrence Livermore National Laboratory
  26. C Livermore, CA 94550
  27. C***DESCRIPTION
  28. C
  29. C 1. RJ
  30. C Standard FORTRAN function routine
  31. C Single precision version
  32. C The routine calculates an approximation result to
  33. C RJ(X,Y,Z,P) = Integral from zero to infinity of
  34. C
  35. C -1/2 -1/2 -1/2 -1
  36. C (3/2)(t+X) (t+Y) (t+Z) (t+P) dt,
  37. C
  38. C where X, Y, and Z are nonnegative, at most one of them is
  39. C zero, and P is positive. If X or Y or Z is zero, the
  40. C integral is COMPLETE. The duplication theorem is iterated
  41. C until the variables are nearly equal, and the function is
  42. C then expanded in Taylor series to fifth order.
  43. C
  44. C
  45. C 2. Calling Sequence
  46. C RJ( X, Y, Z, P, IER )
  47. C
  48. C Parameters On Entry
  49. C Values assigned by the calling routine
  50. C
  51. C X - Single precision, nonnegative variable
  52. C
  53. C Y - Single precision, nonnegative variable
  54. C
  55. C Z - Single precision, nonnegative variable
  56. C
  57. C P - Single precision, positive variable
  58. C
  59. C
  60. C On Return (values assigned by the RJ routine)
  61. C
  62. C RJ - Single precision approximation to the integral
  63. C
  64. C IER - Integer
  65. C
  66. C IER = 0 Normal and reliable termination of the
  67. C routine. It is assumed that the requested
  68. C accuracy has been achieved.
  69. C
  70. C IER > 0 Abnormal termination of the routine
  71. C
  72. C
  73. C X, Y, Z, P are unaltered.
  74. C
  75. C
  76. C 3. Error Messages
  77. C
  78. C Value of IER assigned by the RJ routine
  79. C
  80. C Value Assigned Error Message Printed
  81. C IER = 1 MIN(X,Y,Z) .LT. 0.0E0
  82. C = 2 MIN(X+Y,X+Z,Y+Z,P) .LT. LOLIM
  83. C = 3 MAX(X,Y,Z,P) .GT. UPLIM
  84. C
  85. C
  86. C
  87. C 4. Control Parameters
  88. C
  89. C Values of LOLIM, UPLIM, and ERRTOL are set by the
  90. C routine.
  91. C
  92. C
  93. C LOLIM and UPLIM determine the valid range of X Y, Z, and P
  94. C
  95. C LOLIM is not less than the cube root of the value
  96. C of LOLIM used in the routine for RC.
  97. C
  98. C UPLIM is not greater than 0.3 times the cube root of
  99. C the value of UPLIM used in the routine for RC.
  100. C
  101. C
  102. C Acceptable Values For: LOLIM UPLIM
  103. C IBM 360/370 SERIES : 2.0E-26 3.0E+24
  104. C CDC 6000/7000 SERIES : 5.0E-98 3.0E+106
  105. C UNIVAC 1100 SERIES : 5.0E-13 6.0E+11
  106. C CRAY : 1.32E-822 1.4E+821
  107. C VAX 11 SERIES : 2.5E-13 9.0E+11
  108. C
  109. C
  110. C
  111. C ERRTOL determines the accuracy of the answer
  112. C
  113. C The value assigned by the routine will result
  114. C in solution precision within 1-2 decimals of
  115. C "machine precision".
  116. C
  117. C
  118. C
  119. C
  120. C Relative error due to truncation of the series for RJ
  121. C is less than 3 * ERRTOL ** 6 / (1 - ERRTOL) ** 3/2.
  122. C
  123. C
  124. C
  125. C The accuracy of the computed approximation to the inte-
  126. C gral can be controlled by choosing the value of ERRTOL.
  127. C Truncation of a Taylor series after terms of fifth order
  128. C Introduces an error less than the amount shown in the
  129. C second column of the following table for each value of
  130. C ERRTOL in the first column. In addition to the trunca-
  131. C tion error there will be round-off error, but in prac-
  132. C tice the total error from both sources is usually less
  133. C than the amount given in the table.
  134. C
  135. C
  136. C
  137. C Sample choices: ERRTOL Relative Truncation
  138. C error less than
  139. C 1.0E-3 4.0E-18
  140. C 3.0E-3 3.0E-15
  141. C 1.0E-2 4.0E-12
  142. C 3.0E-2 3.0E-9
  143. C 1.0E-1 4.0E-6
  144. C
  145. C Decreasing ERRTOL by a factor of 10 yields six more
  146. C decimal digits of accuracy at the expense of one or
  147. C two more iterations of the duplication theorem.
  148. C
  149. C *Long Description:
  150. C
  151. C RJ Special Comments
  152. C
  153. C
  154. C Check by addition theorem: RJ(X,X+Z,X+W,X+P)
  155. C + RJ(Y,Y+Z,Y+W,Y+P) + (A-B) * RJ(A,B,B,A) + 3 / SQRT(A)
  156. C = RJ(0,Z,W,P), where X,Y,Z,W,P are positive and X * Y
  157. C = Z * W, A = P * P * (X+Y+Z+W), B = P * (P+X) * (P+Y),
  158. C and B - A = P * (P-Z) * (P-W). The sum of the third and
  159. C fourth terms on the left side is 3 * RC(A,B).
  160. C
  161. C
  162. C On Input:
  163. C
  164. C X, Y, Z, and P are the variables in the integral RJ(X,Y,Z,P).
  165. C
  166. C
  167. C On Output:
  168. C
  169. C
  170. C X, Y, Z, and P are unaltered.
  171. C
  172. C ********************************************************
  173. C
  174. C Warning: Changes in the program may improve speed at the
  175. C expense of robustness.
  176. C
  177. C ------------------------------------------------------------
  178. C
  179. C
  180. C Special Functions via RJ and RF
  181. C
  182. C
  183. C Legendre form of ELLIPTIC INTEGRAL of 3rd kind
  184. C ----------------------------------------------
  185. C
  186. C
  187. C PHI 2 -1
  188. C P(PHI,K,N) = INT (1+N SIN (THETA) ) *
  189. C 0
  190. C
  191. C 2 2 -1/2
  192. C *(1-K SIN (THETA) ) D THETA
  193. C
  194. C
  195. C 2 2 2
  196. C = SIN (PHI) RF(COS (PHI), 1-K SIN (PHI),1)
  197. C
  198. C 3 2 2 2
  199. C -(N/3) SIN (PHI) RJ(COS (PHI),1-K SIN (PHI),
  200. C
  201. C 2
  202. C 1,1+N SIN (PHI))
  203. C
  204. C
  205. C
  206. C Bulirsch form of ELLIPTIC INTEGRAL of 3rd kind
  207. C ----------------------------------------------
  208. C
  209. C
  210. C 2 2 2
  211. C EL3(X,KC,P) = X RF(1,1+KC X ,1+X ) +
  212. C
  213. C 3 2 2 2 2
  214. C +(1/3)(1-P) X RJ(1,1+KC X ,1+X ,1+PX )
  215. C
  216. C
  217. C 2
  218. C CEL(KC,P,A,B) = A RF(0,KC ,1) +
  219. C
  220. C 2
  221. C +(1/3)(B-PA) RJ(0,KC ,1,P)
  222. C
  223. C
  224. C
  225. C
  226. C Heuman's LAMBDA function
  227. C ------------------------
  228. C
  229. C
  230. C 2 2 2 1/2
  231. C L(A,B,P) = (COS(A)SIN(B)COS(B)/(1-COS (A)SIN (B)) )
  232. C
  233. C 2 2 2
  234. C *(SIN(P) RF(COS (P),1-SIN (A) SIN (P),1)
  235. C
  236. C 2 3 2 2
  237. C +(SIN (A) SIN (P)/(3(1-COS (A) SIN (B))))
  238. C
  239. C 2 2 2
  240. C *RJ(COS (P),1-SIN (A) SIN (P),1,1-
  241. C
  242. C 2 2 2 2
  243. C -SIN (A) SIN (P)/(1-COS (A) SIN (B))))
  244. C
  245. C
  246. C
  247. C
  248. C (PI/2) LAMBDA0(A,B) =L(A,B,PI/2) =
  249. C
  250. C
  251. C 2 2 2 -1/2
  252. C = COS (A) SIN(B) COS(B) (1-COS (A) SIN (B))
  253. C
  254. C 2 2 2
  255. C *RF(0,COS (A),1) + (1/3) SIN (A) COS (A)
  256. C
  257. C 2 2 -3/2
  258. C *SIN(B) COS(B) (1-COS (A) SIN (B))
  259. C
  260. C 2 2 2 2 2
  261. C *RJ(0,COS (A),1,COS (A) COS (B)/(1-COS (A) SIN (B)))
  262. C
  263. C
  264. C
  265. C Jacobi ZETA function
  266. C --------------------
  267. C
  268. C
  269. C 2 2 2 1/2
  270. C Z(B,K) = (K/3) SIN(B) COS(B) (1-K SIN (B))
  271. C
  272. C
  273. C 2 2 2 2
  274. C *RJ(0,1-K ,1,1-K SIN (B)) / RF (0,1-K ,1)
  275. C
  276. C
  277. C -------------------------------------------------------------------
  278. C
  279. C***REFERENCES B. C. Carlson and E. M. Notis, Algorithms for incomplete
  280. C elliptic integrals, ACM Transactions on Mathematical
  281. C Software 7, 3 (September 1981), pp. 398-403.
  282. C B. C. Carlson, Computing elliptic integrals by
  283. C duplication, Numerische Mathematik 33, (1979),
  284. C pp. 1-16.
  285. C B. C. Carlson, Elliptic integrals of the first kind,
  286. C SIAM Journal of Mathematical Analysis 8, (1977),
  287. C pp. 231-242.
  288. C***ROUTINES CALLED R1MACH, RC, XERMSG
  289. C***REVISION HISTORY (YYMMDD)
  290. C 790801 DATE WRITTEN
  291. C 890531 Changed all specific intrinsics to generic. (WRB)
  292. C 891009 Removed unreferenced statement labels. (WRB)
  293. C 891009 REVISION DATE from Version 3.2
  294. C 891214 Prologue converted to Version 4.0 format. (BAB)
  295. C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
  296. C 900326 Removed duplicate information from DESCRIPTION section.
  297. C (WRB)
  298. C 900510 Changed calls to XERMSG to standard form, and some
  299. C editorial changes. (RWC)).
  300. C 920501 Reformatted the REFERENCES section. (WRB)
  301. C***END PROLOGUE RJ
  302. CHARACTER*16 XERN3, XERN4, XERN5, XERN6, XERN7
  303. INTEGER IER
  304. REAL ALFA, BETA, C1, C2, C3, C4, EA, EB, EC, E2, E3
  305. REAL LOLIM, UPLIM, EPSLON, ERRTOL
  306. REAL LAMDA, MU, P, PN, PNDEV
  307. REAL POWER4, RC, SIGMA, S1, S2, S3, X, XN, XNDEV
  308. REAL XNROOT, Y, YN, YNDEV, YNROOT, Z, ZN, ZNDEV,
  309. * ZNROOT
  310. LOGICAL FIRST
  311. SAVE ERRTOL,LOLIM,UPLIM,C1,C2,C3,C4,FIRST
  312. DATA FIRST /.TRUE./
  313. C
  314. C***FIRST EXECUTABLE STATEMENT RJ
  315. IF (FIRST) THEN
  316. ERRTOL = (R1MACH(3)/3.0E0)**(1.0E0/6.0E0)
  317. LOLIM = (5.0E0 * R1MACH(1))**(1.0E0/3.0E0)
  318. UPLIM = 0.30E0*( R1MACH(2) / 5.0E0)**(1.0E0/3.0E0)
  319. C
  320. C1 = 3.0E0/14.0E0
  321. C2 = 1.0E0/3.0E0
  322. C3 = 3.0E0/22.0E0
  323. C4 = 3.0E0/26.0E0
  324. ENDIF
  325. FIRST = .FALSE.
  326. C
  327. C CALL ERROR HANDLER IF NECESSARY.
  328. C
  329. RJ = 0.0E0
  330. IF (MIN(X,Y,Z).LT.0.0E0) THEN
  331. IER = 1
  332. WRITE (XERN3, '(1PE15.6)') X
  333. WRITE (XERN4, '(1PE15.6)') Y
  334. WRITE (XERN5, '(1PE15.6)') Z
  335. CALL XERMSG ('SLATEC', 'RJ',
  336. * 'MIN(X,Y,Z).LT.0 WHERE X = ' // XERN3 // ' Y = ' // XERN4 //
  337. * ' AND Z = ' // XERN5, 1, 1)
  338. RETURN
  339. ENDIF
  340. C
  341. IF (MAX(X,Y,Z,P).GT.UPLIM) THEN
  342. IER = 3
  343. WRITE (XERN3, '(1PE15.6)') X
  344. WRITE (XERN4, '(1PE15.6)') Y
  345. WRITE (XERN5, '(1PE15.6)') Z
  346. WRITE (XERN6, '(1PE15.6)') P
  347. WRITE (XERN7, '(1PE15.6)') UPLIM
  348. CALL XERMSG ('SLATEC', 'RJ',
  349. * 'MAX(X,Y,Z,P).GT.UPLIM WHERE X = ' // XERN3 // ' Y = ' //
  350. * XERN4 // ' Z = ' // XERN5 // ' P = ' // XERN6 //
  351. * ' AND UPLIM = ' // XERN7, 3, 1)
  352. RETURN
  353. ENDIF
  354. C
  355. IF (MIN(X+Y,X+Z,Y+Z,P).LT.LOLIM) THEN
  356. IER = 2
  357. WRITE (XERN3, '(1PE15.6)') X
  358. WRITE (XERN4, '(1PE15.6)') Y
  359. WRITE (XERN5, '(1PE15.6)') Z
  360. WRITE (XERN6, '(1PE15.6)') P
  361. WRITE (XERN7, '(1PE15.6)') LOLIM
  362. CALL XERMSG ('SLATEC', 'RJ',
  363. * 'MIN(X+Y,X+Z,Y+Z,P).LT.LOLIM WHERE X = ' // XERN3 //
  364. * ' Y = ' // XERN4 // ' Z = ' // XERN5 // ' P = ' // XERN6 //
  365. * ' AND LOLIM = ', 2, 1)
  366. RETURN
  367. ENDIF
  368. C
  369. IER = 0
  370. XN = X
  371. YN = Y
  372. ZN = Z
  373. PN = P
  374. SIGMA = 0.0E0
  375. POWER4 = 1.0E0
  376. C
  377. 30 MU = (XN+YN+ZN+PN+PN)*0.20E0
  378. XNDEV = (MU-XN)/MU
  379. YNDEV = (MU-YN)/MU
  380. ZNDEV = (MU-ZN)/MU
  381. PNDEV = (MU-PN)/MU
  382. EPSLON = MAX(ABS(XNDEV), ABS(YNDEV), ABS(ZNDEV), ABS(PNDEV))
  383. IF (EPSLON.LT.ERRTOL) GO TO 40
  384. XNROOT = SQRT(XN)
  385. YNROOT = SQRT(YN)
  386. ZNROOT = SQRT(ZN)
  387. LAMDA = XNROOT*(YNROOT+ZNROOT) + YNROOT*ZNROOT
  388. ALFA = PN*(XNROOT+YNROOT+ZNROOT) + XNROOT*YNROOT*ZNROOT
  389. ALFA = ALFA*ALFA
  390. BETA = PN*(PN+LAMDA)*(PN+LAMDA)
  391. SIGMA = SIGMA + POWER4*RC(ALFA,BETA,IER)
  392. POWER4 = POWER4*0.250E0
  393. XN = (XN+LAMDA)*0.250E0
  394. YN = (YN+LAMDA)*0.250E0
  395. ZN = (ZN+LAMDA)*0.250E0
  396. PN = (PN+LAMDA)*0.250E0
  397. GO TO 30
  398. C
  399. 40 EA = XNDEV*(YNDEV+ZNDEV) + YNDEV*ZNDEV
  400. EB = XNDEV*YNDEV*ZNDEV
  401. EC = PNDEV*PNDEV
  402. E2 = EA - 3.0E0*EC
  403. E3 = EB + 2.0E0*PNDEV*(EA-EC)
  404. S1 = 1.0E0 + E2*(-C1+0.750E0*C3*E2-1.50E0*C4*E3)
  405. S2 = EB*(0.50E0*C2+PNDEV*(-C3-C3+PNDEV*C4))
  406. S3 = PNDEV*EA*(C2-PNDEV*C3) - C2*PNDEV*EC
  407. RJ = 3.0E0*SIGMA + POWER4*(S1+S2+S3)/(MU* SQRT(MU))
  408. RETURN
  409. END