rd.f 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. *DECK RD
  2. REAL FUNCTION RD (X, Y, Z, IER)
  3. C***BEGIN PROLOGUE RD
  4. C***PURPOSE Compute the incomplete or complete elliptic integral of the
  5. C 2nd kind. For X and Y nonnegative, X+Y and Z positive,
  6. C RD(X,Y,Z) = Integral from zero to infinity of
  7. C -1/2 -1/2 -3/2
  8. C (3/2)(t+X) (t+Y) (t+Z) dt.
  9. C If X or Y is zero, the integral is complete.
  10. C***LIBRARY SLATEC
  11. C***CATEGORY C14
  12. C***TYPE SINGLE PRECISION (RD-S, DRD-D)
  13. C***KEYWORDS COMPLETE ELLIPTIC INTEGRAL, DUPLICATION THEOREM,
  14. C INCOMPLETE ELLIPTIC INTEGRAL, INTEGRAL OF THE SECOND 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. RD
  30. C Evaluate an INCOMPLETE (or COMPLETE) ELLIPTIC INTEGRAL
  31. C of the second kind
  32. C Standard FORTRAN function routine
  33. C Single precision version
  34. C The routine calculates an approximation result to
  35. C RD(X,Y,Z) = Integral from zero to infinity of
  36. C -1/2 -1/2 -3/2
  37. C (3/2)(t+X) (t+Y) (t+Z) dt,
  38. C where X and Y are nonnegative, X + Y is positive, and Z is
  39. C positive. If X or Y is zero, the integral is COMPLETE.
  40. C The duplication theorem is iterated until the variables are
  41. C nearly equal, and the function is then expanded in Taylor
  42. C series to fifth order.
  43. C
  44. C 2. Calling Sequence
  45. C
  46. C RD( X, Y, Z, 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 X + Y is positive
  56. C
  57. C Z - Real, positive variable
  58. C
  59. C
  60. C
  61. C On Return (values assigned by the RD routine)
  62. C
  63. C RD - Real approximation to the integral
  64. C
  65. C
  66. C IER - Integer
  67. C
  68. C IER = 0 Normal and reliable termination of the
  69. C routine. It is assumed that the requested
  70. C accuracy has been achieved.
  71. C
  72. C IER > 0 Abnormal termination of the routine
  73. C
  74. C
  75. C X, Y, Z are unaltered.
  76. C
  77. C 3. Error Messages
  78. C
  79. C Value of IER assigned by the RD routine
  80. C
  81. C Value Assigned Error Message Printed
  82. C IER = 1 MIN(X,Y) .LT. 0.0E0
  83. C = 2 MIN(X + Y, Z ) .LT. LOLIM
  84. C = 3 MAX(X,Y,Z) .GT. UPLIM
  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 LOLIM and UPLIM determine the valid range of X, Y, and Z
  93. C
  94. C LOLIM - Lower limit of valid arguments
  95. C
  96. C Not less than 2 / (machine maximum) ** (2/3).
  97. C
  98. C UPLIM - Upper limit of valid arguments
  99. C
  100. C Not greater than (0.1E0 * ERRTOL / machine
  101. C minimum) ** (2/3), where ERRTOL is described below.
  102. C In the following table it is assumed that ERRTOL
  103. C will never be chosen smaller than 1.0E-5.
  104. C
  105. C
  106. C Acceptable Values For: LOLIM UPLIM
  107. C IBM 360/370 SERIES : 6.0E-51 1.0E+48
  108. C CDC 6000/7000 SERIES : 5.0E-215 2.0E+191
  109. C UNIVAC 1100 SERIES : 1.0E-25 2.0E+21
  110. C CRAY : 3.0E-1644 1.69E+1640
  111. C VAX 11 SERIES : 1.0E-25 4.5E+21
  112. C
  113. C
  114. C ERRTOL determines the accuracy of the answer
  115. C
  116. C The value assigned by the routine will result
  117. C in solution precision within 1-2 decimals of
  118. C "machine precision".
  119. C
  120. C ERRTOL Relative error due to truncation is less than
  121. C 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
  138. C Sample Choices: ERRTOL Relative Truncation
  139. C error less than
  140. C 1.0E-3 4.0E-18
  141. C 3.0E-3 3.0E-15
  142. C 1.0E-2 4.0E-12
  143. C 3.0E-2 3.0E-9
  144. C 1.0E-1 4.0E-6
  145. C
  146. C
  147. C Decreasing ERRTOL by a factor of 10 yields six more
  148. C decimal digits of accuracy at the expense of one or
  149. C two more iterations of the duplication theorem.
  150. C
  151. C *Long Description:
  152. C
  153. C RD Special Comments
  154. C
  155. C
  156. C
  157. C Check: RD(X,Y,Z) + RD(Y,Z,X) + RD(Z,X,Y)
  158. C = 3 / SQRT(X * Y * Z), where X, Y, and Z are positive.
  159. C
  160. C
  161. C On Input:
  162. C
  163. C X, Y, and Z are the variables in the integral RD(X,Y,Z).
  164. C
  165. C
  166. C On Output:
  167. C
  168. C
  169. C X, Y, and Z are unaltered.
  170. C
  171. C
  172. C
  173. C ********************************************************
  174. C
  175. C WARNING: Changes in the program may improve speed at the
  176. C expense of robustness.
  177. C
  178. C
  179. C
  180. C -------------------------------------------------------------------
  181. C
  182. C
  183. C Special Functions via RD and RF
  184. C
  185. C
  186. C Legendre form of ELLIPTIC INTEGRAL of 2nd kind
  187. C ----------------------------------------------
  188. C
  189. C
  190. C 2 2 2
  191. C E(PHI,K) = SIN(PHI) RF(COS (PHI),1-K SIN (PHI),1) -
  192. C
  193. C 2 3 2 2 2
  194. C -(K/3) SIN (PHI) RD(COS (PHI),1-K SIN (PHI),1)
  195. C
  196. C
  197. C 2 2 2
  198. C E(K) = RF(0,1-K ,1) - (K/3) RD(0,1-K ,1)
  199. C
  200. C
  201. C PI/2 2 2 1/2
  202. C = INT (1-K SIN (PHI) ) D PHI
  203. C 0
  204. C
  205. C
  206. C
  207. C Bulirsch form of ELLIPTIC INTEGRAL of 2nd kind
  208. C ----------------------------------------------
  209. C
  210. C 2 2 2
  211. C EL2(X,KC,A,B) = AX RF(1,1+KC X ,1+X ) +
  212. C
  213. C 3 2 2 2
  214. C +(1/3)(B-A) X RD(1,1+KC X ,1+X )
  215. C
  216. C
  217. C
  218. C Legendre form of alternative ELLIPTIC INTEGRAL of 2nd
  219. C -----------------------------------------------------
  220. C kind
  221. C ----
  222. C
  223. C Q 2 2 2 -1/2
  224. C D(Q,K) = INT SIN P (1-K SIN P) DP
  225. C 0
  226. C
  227. C
  228. C
  229. C 3 2 2 2
  230. C D(Q,K) =(1/3)(SIN Q) RD(COS Q,1-K SIN Q,1)
  231. C
  232. C
  233. C
  234. C
  235. C
  236. C Lemniscate constant B
  237. C ---------------------
  238. C
  239. C
  240. C
  241. C 1 2 4 -1/2
  242. C B = INT S (1-S ) DS
  243. C 0
  244. C
  245. C
  246. C B =(1/3)RD (0,2,1)
  247. C
  248. C
  249. C
  250. C
  251. C Heuman's LAMBDA function
  252. C ------------------------
  253. C
  254. C
  255. C
  256. C (PI/2) LAMBDA0(A,B) =
  257. C
  258. C 2 2
  259. C = SIN(B) (RF(0,COS (A),1)-(1/3) SIN (A) *
  260. C
  261. C 2 2 2 2
  262. C *RD(0,COS (A),1)) RF(COS (B),1-COS (A) SIN (B),1)
  263. C
  264. C 2 3 2
  265. C -(1/3) COS (A) SIN (B) RF(0,COS (A),1) *
  266. C
  267. C 2 2 2
  268. C *RD(COS (B),1-COS (A) SIN (B),1)
  269. C
  270. C
  271. C
  272. C Jacobi ZETA function
  273. C --------------------
  274. C
  275. C
  276. C 2 2 2 2
  277. C Z(B,K) = (K/3) SIN(B) RF(COS (B),1-K SIN (B),1)
  278. C
  279. C
  280. C 2 2
  281. C *RD(0,1-K ,1)/RF(0,1-K ,1)
  282. C
  283. C 2 3 2 2 2
  284. C -(K /3) SIN (B) RD(COS (B),1-K SIN (B),1)
  285. C
  286. C
  287. C -------------------------------------------------------------------
  288. C
  289. C***REFERENCES B. C. Carlson and E. M. Notis, Algorithms for incomplete
  290. C elliptic integrals, ACM Transactions on Mathematical
  291. C Software 7, 3 (September 1981), pp. 398-403.
  292. C B. C. Carlson, Computing elliptic integrals by
  293. C duplication, Numerische Mathematik 33, (1979),
  294. C pp. 1-16.
  295. C B. C. Carlson, Elliptic integrals of the first kind,
  296. C SIAM Journal of Mathematical Analysis 8, (1977),
  297. C pp. 231-242.
  298. C***ROUTINES CALLED R1MACH, XERMSG
  299. C***REVISION HISTORY (YYMMDD)
  300. C 790801 DATE WRITTEN
  301. C 890531 Changed all specific intrinsics to generic. (WRB)
  302. C 890531 REVISION DATE from Version 3.2
  303. C 891214 Prologue converted to Version 4.0 format. (BAB)
  304. C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
  305. C 900326 Removed duplicate information from DESCRIPTION section.
  306. C (WRB)
  307. C 900510 Modify calls to XERMSG to put in standard form. (RWC)
  308. C 920501 Reformatted the REFERENCES section. (WRB)
  309. C***END PROLOGUE RD
  310. CHARACTER*16 XERN3, XERN4, XERN5, XERN6
  311. INTEGER IER
  312. REAL LOLIM, UPLIM, EPSLON, ERRTOL
  313. REAL C1, C2, C3, C4, EA, EB, EC, ED, EF, LAMDA
  314. REAL MU, POWER4, SIGMA, S1, S2, X, XN, XNDEV
  315. REAL XNROOT, Y, YN, YNDEV, YNROOT, Z, ZN, ZNDEV, ZNROOT
  316. LOGICAL FIRST
  317. SAVE ERRTOL, LOLIM, UPLIM, C1, C2, C3, C4, FIRST
  318. DATA FIRST /.TRUE./
  319. C
  320. C***FIRST EXECUTABLE STATEMENT RD
  321. IF (FIRST) THEN
  322. ERRTOL = (R1MACH(3)/3.0E0)**(1.0E0/6.0E0)
  323. LOLIM = 2.0E0/(R1MACH(2))**(2.0E0/3.0E0)
  324. TUPLIM = R1MACH(1)**(1.0E0/3.0E0)
  325. TUPLIM = (0.10E0*ERRTOL)**(1.0E0/3.0E0)/TUPLIM
  326. UPLIM = TUPLIM**2.0E0
  327. C
  328. C1 = 3.0E0/14.0E0
  329. C2 = 1.0E0/6.0E0
  330. C3 = 9.0E0/22.0E0
  331. C4 = 3.0E0/26.0E0
  332. ENDIF
  333. FIRST = .FALSE.
  334. C
  335. C CALL ERROR HANDLER IF NECESSARY.
  336. C
  337. RD = 0.0E0
  338. IF( MIN(X,Y).LT.0.0E0) THEN
  339. IER = 1
  340. WRITE (XERN3, '(1PE15.6)') X
  341. WRITE (XERN4, '(1PE15.6)') Y
  342. CALL XERMSG ('SLATEC', 'RD',
  343. * 'MIN(X,Y).LT.0 WHERE X = ' // XERN3 // ' AND Y = ' //
  344. * XERN4, 1, 1)
  345. RETURN
  346. ENDIF
  347. C
  348. IF (MAX(X,Y,Z).GT.UPLIM) THEN
  349. IER = 3
  350. WRITE (XERN3, '(1PE15.6)') X
  351. WRITE (XERN4, '(1PE15.6)') Y
  352. WRITE (XERN5, '(1PE15.6)') Z
  353. WRITE (XERN6, '(1PE15.6)') UPLIM
  354. CALL XERMSG ('SLATEC', 'RD',
  355. * 'MAX(X,Y,Z).GT.UPLIM WHERE X = ' // XERN3 // ' Y = ' //
  356. * XERN4 // ' Z = ' // XERN5 // ' AND UPLIM = ' // XERN6,
  357. * 3, 1)
  358. RETURN
  359. ENDIF
  360. C
  361. IF (MIN(X+Y,Z).LT.LOLIM) THEN
  362. IER = 2
  363. WRITE (XERN3, '(1PE15.6)') X
  364. WRITE (XERN4, '(1PE15.6)') Y
  365. WRITE (XERN5, '(1PE15.6)') Z
  366. WRITE (XERN6, '(1PE15.6)') LOLIM
  367. CALL XERMSG ('SLATEC', 'RD',
  368. * 'MIN(X+Y,Z).LT.LOLIM WHERE X = ' // XERN3 // ' Y = ' //
  369. * XERN4 // ' Z = ' // XERN5 // ' AND LOLIM = ' // XERN6,
  370. * 2, 1)
  371. RETURN
  372. ENDIF
  373. C
  374. IER = 0
  375. XN = X
  376. YN = Y
  377. ZN = Z
  378. SIGMA = 0.0E0
  379. POWER4 = 1.0E0
  380. C
  381. 30 MU = (XN+YN+3.0E0*ZN)*0.20E0
  382. XNDEV = (MU-XN)/MU
  383. YNDEV = (MU-YN)/MU
  384. ZNDEV = (MU-ZN)/MU
  385. EPSLON = MAX(ABS(XNDEV), ABS(YNDEV), ABS(ZNDEV))
  386. IF (EPSLON.LT.ERRTOL) GO TO 40
  387. XNROOT = SQRT(XN)
  388. YNROOT = SQRT(YN)
  389. ZNROOT = SQRT(ZN)
  390. LAMDA = XNROOT*(YNROOT+ZNROOT) + YNROOT*ZNROOT
  391. SIGMA = SIGMA + POWER4/(ZNROOT*(ZN+LAMDA))
  392. POWER4 = POWER4*0.250E0
  393. XN = (XN+LAMDA)*0.250E0
  394. YN = (YN+LAMDA)*0.250E0
  395. ZN = (ZN+LAMDA)*0.250E0
  396. GO TO 30
  397. C
  398. 40 EA = XNDEV*YNDEV
  399. EB = ZNDEV*ZNDEV
  400. EC = EA - EB
  401. ED = EA - 6.0E0*EB
  402. EF = ED + EC + EC
  403. S1 = ED*(-C1+0.250E0*C3*ED-1.50E0*C4*ZNDEV*EF)
  404. S2 = ZNDEV*(C2*EF+ZNDEV*(-C3*EC+ZNDEV*C4*EA))
  405. RD = 3.0E0*SIGMA + POWER4*(1.0E0+S1+S2)/(MU* SQRT(MU))
  406. C
  407. RETURN
  408. END