drd.f 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. *DECK DRD
  2. DOUBLE PRECISION FUNCTION DRD (X, Y, Z, IER)
  3. C***BEGIN PROLOGUE DRD
  4. C***PURPOSE Compute the incomplete or complete elliptic integral of
  5. C the 2nd kind. For X and Y nonnegative, X+Y and Z positive,
  6. C DRD(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 DOUBLE 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. DRD
  30. C Evaluate an INCOMPLETE (or COMPLETE) ELLIPTIC INTEGRAL
  31. C of the second kind
  32. C Standard FORTRAN function routine
  33. C Double precision version
  34. C The routine calculates an approximation result to
  35. C DRD(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 DRD( X, Y, Z, IER )
  47. C
  48. C Parameters On Entry
  49. C Values assigned by the calling routine
  50. C
  51. C X - Double precision, nonnegative variable
  52. C
  53. C Y - Double precision, nonnegative variable
  54. C
  55. C X + Y is positive
  56. C
  57. C Z - Double precision, positive variable
  58. C
  59. C
  60. C
  61. C On Return (values assigned by the DRD routine)
  62. C
  63. C DRD - Double precision 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 DRD routine
  80. C
  81. C Value assigned Error message printed
  82. C IER = 1 MIN(X,Y) .LT. 0.0D0
  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.1D0 * ERRTOL / machine
  101. C minimum) ** (2/3), where ERRTOL is described below.
  102. C In the following table it is assumed that ERRTOL will
  103. C never be chosen smaller than 1.0D-5.
  104. C
  105. C
  106. C Acceptable values for: LOLIM UPLIM
  107. C IBM 360/370 SERIES : 6.0D-51 1.0D+48
  108. C CDC 6000/7000 SERIES : 5.0D-215 2.0D+191
  109. C UNIVAC 1100 SERIES : 1.0D-205 2.0D+201
  110. C CRAY : 3.0D-1644 1.69D+1640
  111. C VAX 11 SERIES : 1.0D-25 4.5D+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 integral
  126. C 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 truncation
  131. C error there will be round-off error, but in practice the
  132. C total error from both sources is usually less than the
  133. C 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.0D-3 4.0D-18
  141. C 3.0D-3 3.0D-15
  142. C 1.0D-2 4.0D-12
  143. C 3.0D-2 3.0D-9
  144. C 1.0D-1 4.0D-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 DRD Special Comments
  154. C
  155. C
  156. C
  157. C Check: DRD(X,Y,Z) + DRD(Y,Z,X) + DRD(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 DRD(X,Y,Z).
  164. C
  165. C
  166. C On Output:
  167. C
  168. C
  169. C X, Y, 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 double precision functions via DRD and DRF
  184. C
  185. C
  186. C Legendre form of ELLIPTIC INTEGRAL of 2nd kind
  187. C
  188. C -----------------------------------------
  189. C
  190. C
  191. C 2 2 2
  192. C E(PHI,K) = SIN(PHI) DRF(COS (PHI),1-K SIN (PHI),1) -
  193. C
  194. C 2 3 2 2 2
  195. C -(K/3) SIN (PHI) DRD(COS (PHI),1-K SIN (PHI),1)
  196. C
  197. C
  198. C 2 2 2
  199. C E(K) = DRF(0,1-K ,1) - (K/3) DRD(0,1-K ,1)
  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 Bulirsch form of ELLIPTIC INTEGRAL of 2nd kind
  206. C
  207. C -----------------------------------------
  208. C
  209. C 2 2 2
  210. C EL2(X,KC,A,B) = AX DRF(1,1+KC X ,1+X ) +
  211. C
  212. C 3 2 2 2
  213. C +(1/3)(B-A) X DRD(1,1+KC X ,1+X )
  214. C
  215. C
  216. C
  217. C
  218. C Legendre form of alternative ELLIPTIC INTEGRAL
  219. C of 2nd kind
  220. C
  221. C -----------------------------------------
  222. C
  223. C
  224. C
  225. C Q 2 2 2 -1/2
  226. C D(Q,K) = INT SIN P (1-K SIN P) DP
  227. C 0
  228. C
  229. C
  230. C
  231. C 3 2 2 2
  232. C D(Q,K) = (1/3) (SIN Q) DRD(COS Q,1-K SIN Q,1)
  233. C
  234. C
  235. C
  236. C
  237. C Lemniscate constant B
  238. C
  239. C -----------------------------------------
  240. C
  241. C
  242. C
  243. C
  244. C 1 2 4 -1/2
  245. C B = INT S (1-S ) DS
  246. C 0
  247. C
  248. C
  249. C B = (1/3) DRD (0,2,1)
  250. C
  251. C
  252. C Heuman's LAMBDA function
  253. C
  254. C -----------------------------------------
  255. C
  256. C
  257. C
  258. C (PI/2) LAMBDA0(A,B) =
  259. C
  260. C 2 2
  261. C = SIN(B) (DRF(0,COS (A),1)-(1/3) SIN (A) *
  262. C
  263. C 2 2 2 2
  264. C *DRD(0,COS (A),1)) DRF(COS (B),1-COS (A) SIN (B),1)
  265. C
  266. C 2 3 2
  267. C -(1/3) COS (A) SIN (B) DRF(0,COS (A),1) *
  268. C
  269. C 2 2 2
  270. C *DRD(COS (B),1-COS (A) SIN (B),1)
  271. C
  272. C
  273. C
  274. C Jacobi ZETA function
  275. C
  276. C -----------------------------------------
  277. C
  278. C 2 2 2 2
  279. C Z(B,K) = (K/3) SIN(B) DRF(COS (B),1-K SIN (B),1)
  280. C
  281. C
  282. C 2 2
  283. C *DRD(0,1-K ,1)/DRF(0,1-K ,1)
  284. C
  285. C 2 3 2 2 2
  286. C -(K /3) SIN (B) DRD(COS (B),1-K SIN (B),1)
  287. C
  288. C
  289. C ---------------------------------------------------------------------
  290. C
  291. C***REFERENCES B. C. Carlson and E. M. Notis, Algorithms for incomplete
  292. C elliptic integrals, ACM Transactions on Mathematical
  293. C Software 7, 3 (September 1981), pp. 398-403.
  294. C B. C. Carlson, Computing elliptic integrals by
  295. C duplication, Numerische Mathematik 33, (1979),
  296. C pp. 1-16.
  297. C B. C. Carlson, Elliptic integrals of the first kind,
  298. C SIAM Journal of Mathematical Analysis 8, (1977),
  299. C pp. 231-242.
  300. C***ROUTINES CALLED D1MACH, XERMSG
  301. C***REVISION HISTORY (YYMMDD)
  302. C 790801 DATE WRITTEN
  303. C 890531 Changed all specific intrinsics to generic. (WRB)
  304. C 890531 REVISION DATE from Version 3.2
  305. C 891214 Prologue converted to Version 4.0 format. (BAB)
  306. C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
  307. C 900326 Removed duplicate information from DESCRIPTION section.
  308. C (WRB)
  309. C 900510 Modify calls to XERMSG to put in standard form. (RWC)
  310. C 920501 Reformatted the REFERENCES section. (WRB)
  311. C***END PROLOGUE DRD
  312. CHARACTER*16 XERN3, XERN4, XERN5, XERN6
  313. INTEGER IER
  314. DOUBLE PRECISION LOLIM, TUPLIM, UPLIM, EPSLON, ERRTOL, D1MACH
  315. DOUBLE PRECISION C1, C2, C3, C4, EA, EB, EC, ED, EF, LAMDA
  316. DOUBLE PRECISION MU, POWER4, SIGMA, S1, S2, X, XN, XNDEV
  317. DOUBLE PRECISION XNROOT, Y, YN, YNDEV, YNROOT, Z, ZN, ZNDEV,
  318. * ZNROOT
  319. LOGICAL FIRST
  320. SAVE ERRTOL, LOLIM, UPLIM, C1, C2, C3, C4, FIRST
  321. DATA FIRST /.TRUE./
  322. C
  323. C***FIRST EXECUTABLE STATEMENT DRD
  324. IF (FIRST) THEN
  325. ERRTOL = (D1MACH(3)/3.0D0)**(1.0D0/6.0D0)
  326. LOLIM = 2.0D0/(D1MACH(2))**(2.0D0/3.0D0)
  327. TUPLIM = D1MACH(1)**(1.0E0/3.0E0)
  328. TUPLIM = (0.10D0*ERRTOL)**(1.0E0/3.0E0)/TUPLIM
  329. UPLIM = TUPLIM**2.0D0
  330. C
  331. C1 = 3.0D0/14.0D0
  332. C2 = 1.0D0/6.0D0
  333. C3 = 9.0D0/22.0D0
  334. C4 = 3.0D0/26.0D0
  335. ENDIF
  336. FIRST = .FALSE.
  337. C
  338. C CALL ERROR HANDLER IF NECESSARY.
  339. C
  340. DRD = 0.0D0
  341. IF( MIN(X,Y).LT.0.0D0) THEN
  342. IER = 1
  343. WRITE (XERN3, '(1PE15.6)') X
  344. WRITE (XERN4, '(1PE15.6)') Y
  345. CALL XERMSG ('SLATEC', 'DRD',
  346. * 'MIN(X,Y).LT.0 WHERE X = ' // XERN3 // ' AND Y = ' //
  347. * XERN4, 1, 1)
  348. RETURN
  349. ENDIF
  350. C
  351. IF (MAX(X,Y,Z).GT.UPLIM) THEN
  352. IER = 3
  353. WRITE (XERN3, '(1PE15.6)') X
  354. WRITE (XERN4, '(1PE15.6)') Y
  355. WRITE (XERN5, '(1PE15.6)') Z
  356. WRITE (XERN6, '(1PE15.6)') UPLIM
  357. CALL XERMSG ('SLATEC', 'DRD',
  358. * 'MAX(X,Y,Z).GT.UPLIM WHERE X = ' // XERN3 // ' Y = ' //
  359. * XERN4 // ' Z = ' // XERN5 // ' AND UPLIM = ' // XERN6,
  360. * 3, 1)
  361. RETURN
  362. ENDIF
  363. C
  364. IF (MIN(X+Y,Z).LT.LOLIM) THEN
  365. IER = 2
  366. WRITE (XERN3, '(1PE15.6)') X
  367. WRITE (XERN4, '(1PE15.6)') Y
  368. WRITE (XERN5, '(1PE15.6)') Z
  369. WRITE (XERN6, '(1PE15.6)') LOLIM
  370. CALL XERMSG ('SLATEC', 'DRD',
  371. * 'MIN(X+Y,Z).LT.LOLIM WHERE X = ' // XERN3 // ' Y = ' //
  372. * XERN4 // ' Z = ' // XERN5 // ' AND LOLIM = ' // XERN6,
  373. * 2, 1)
  374. RETURN
  375. ENDIF
  376. C
  377. IER = 0
  378. XN = X
  379. YN = Y
  380. ZN = Z
  381. SIGMA = 0.0D0
  382. POWER4 = 1.0D0
  383. C
  384. 30 MU = (XN+YN+3.0D0*ZN)*0.20D0
  385. XNDEV = (MU-XN)/MU
  386. YNDEV = (MU-YN)/MU
  387. ZNDEV = (MU-ZN)/MU
  388. EPSLON = MAX(ABS(XNDEV), ABS(YNDEV), ABS(ZNDEV))
  389. IF (EPSLON.LT.ERRTOL) GO TO 40
  390. XNROOT = SQRT(XN)
  391. YNROOT = SQRT(YN)
  392. ZNROOT = SQRT(ZN)
  393. LAMDA = XNROOT*(YNROOT+ZNROOT) + YNROOT*ZNROOT
  394. SIGMA = SIGMA + POWER4/(ZNROOT*(ZN+LAMDA))
  395. POWER4 = POWER4*0.250D0
  396. XN = (XN+LAMDA)*0.250D0
  397. YN = (YN+LAMDA)*0.250D0
  398. ZN = (ZN+LAMDA)*0.250D0
  399. GO TO 30
  400. C
  401. 40 EA = XNDEV*YNDEV
  402. EB = ZNDEV*ZNDEV
  403. EC = EA - EB
  404. ED = EA - 6.0D0*EB
  405. EF = ED + EC + EC
  406. S1 = ED*(-C1+0.250D0*C3*ED-1.50D0*C4*ZNDEV*EF)
  407. S2 = ZNDEV*(C2*EF+ZNDEV*(-C3*EC+ZNDEV*C4*EA))
  408. DRD = 3.0D0*SIGMA + POWER4*(1.0D0+S1+S2)/(MU*SQRT(MU))
  409. C
  410. RETURN
  411. END