drf.f 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. *DECK DRF
  2. DOUBLE PRECISION FUNCTION DRF (X, Y, Z, IER)
  3. C***BEGIN PROLOGUE DRF
  4. C***PURPOSE Compute the incomplete or complete elliptic integral of the
  5. C 1st kind. For X, Y, and Z non-negative and at most one of
  6. C them zero, RF(X,Y,Z) = Integral from zero to infinity of
  7. C -1/2 -1/2 -1/2
  8. C (1/2)(t+X) (t+Y) (t+Z) dt.
  9. C If X, Y or Z is zero, the integral is complete.
  10. C***LIBRARY SLATEC
  11. C***CATEGORY C14
  12. C***TYPE DOUBLE PRECISION (RF-S, DRF-D)
  13. C***KEYWORDS COMPLETE ELLIPTIC INTEGRAL, DUPLICATION THEOREM,
  14. C INCOMPLETE ELLIPTIC INTEGRAL, INTEGRAL OF THE FIRST 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. DRF
  30. C Evaluate an INCOMPLETE (or COMPLETE) ELLIPTIC INTEGRAL
  31. C of the first kind
  32. C Standard FORTRAN function routine
  33. C Double precision version
  34. C The routine calculates an approximation result to
  35. C DRF(X,Y,Z) = Integral from zero to infinity of
  36. C
  37. C -1/2 -1/2 -1/2
  38. C (1/2)(t+X) (t+Y) (t+Z) dt,
  39. C
  40. C where X, Y, and Z are nonnegative and at most one of them
  41. C is zero. If one of them is zero, the integral is COMPLETE.
  42. C The duplication theorem is iterated until the variables are
  43. C nearly equal, and the function is then expanded in Taylor
  44. C series to fifth order.
  45. C
  46. C 2. Calling sequence
  47. C DRF( X, Y, Z, IER )
  48. C
  49. C Parameters On entry
  50. C Values assigned by the calling routine
  51. C
  52. C X - Double precision, nonnegative variable
  53. C
  54. C Y - Double precision, nonnegative variable
  55. C
  56. C Z - Double precision, nonnegative variable
  57. C
  58. C
  59. C
  60. C On Return (values assigned by the DRF routine)
  61. C
  62. C DRF - Double 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 X, Y, Z are unaltered.
  73. C
  74. C
  75. C 3. Error Messages
  76. C
  77. C
  78. C Value of IER assigned by the DRF routine
  79. C
  80. C Value assigned Error Message Printed
  81. C IER = 1 MIN(X,Y,Z) .LT. 0.0D0
  82. C = 2 MIN(X+Y,X+Z,Y+Z) .LT. LOLIM
  83. C = 3 MAX(X,Y,Z) .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 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 5 * (machine minimum).
  97. C
  98. C UPLIM - Upper limit of valid arguments
  99. C
  100. C Not greater than (machine maximum) / 5.
  101. C
  102. C
  103. C Acceptable values for: LOLIM UPLIM
  104. C IBM 360/370 SERIES : 3.0D-78 1.0D+75
  105. C CDC 6000/7000 SERIES : 1.0D-292 1.0D+321
  106. C UNIVAC 1100 SERIES : 1.0D-307 1.0D+307
  107. C CRAY : 2.3D-2466 1.09D+2465
  108. C VAX 11 SERIES : 1.5D-38 3.0D+37
  109. C
  110. C
  111. C
  112. C ERRTOL determines the accuracy of the answer
  113. C
  114. C The value assigned by the routine will result
  115. C in solution precision within 1-2 decimals of
  116. C "machine precision".
  117. C
  118. C
  119. C
  120. C ERRTOL - Relative error due to truncation is less than
  121. C ERRTOL ** 6 / (4 * (1-ERRTOL) .
  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
  139. C Sample choices: ERRTOL Relative Truncation
  140. C error less than
  141. C 1.0D-3 3.0D-19
  142. C 3.0D-3 2.0D-16
  143. C 1.0D-2 3.0D-13
  144. C 3.0D-2 2.0D-10
  145. C 1.0D-1 3.0D-7
  146. C
  147. C
  148. C Decreasing ERRTOL by a factor of 10 yields six more
  149. C decimal digits of accuracy at the expense of one or
  150. C two more iterations of the duplication theorem.
  151. C
  152. C *Long Description:
  153. C
  154. C DRF Special Comments
  155. C
  156. C
  157. C
  158. C Check by addition theorem: DRF(X,X+Z,X+W) + DRF(Y,Y+Z,Y+W)
  159. C = DRF(0,Z,W), where X,Y,Z,W are positive and X * Y = Z * W.
  160. C
  161. C
  162. C On Input:
  163. C
  164. C X, Y, and Z are the variables in the integral DRF(X,Y,Z).
  165. C
  166. C
  167. C On Output:
  168. C
  169. C
  170. C X, Y, Z are unaltered.
  171. C
  172. C
  173. C
  174. C ********************************************************
  175. C
  176. C WARNING: Changes in the program may improve speed at the
  177. C expense of robustness.
  178. C
  179. C
  180. C
  181. C Special double precision functions via DRF
  182. C
  183. C
  184. C
  185. C
  186. C Legendre form of ELLIPTIC INTEGRAL of 1st kind
  187. C
  188. C -----------------------------------------
  189. C
  190. C
  191. C
  192. C 2 2 2
  193. C F(PHI,K) = SIN(PHI) DRF(COS (PHI),1-K SIN (PHI),1)
  194. C
  195. C
  196. C 2
  197. C K(K) = DRF(0,1-K ,1)
  198. C
  199. C
  200. C PI/2 2 2 -1/2
  201. C = INT (1-K SIN (PHI) ) D PHI
  202. C 0
  203. C
  204. C
  205. C
  206. C Bulirsch form of ELLIPTIC INTEGRAL of 1st kind
  207. C
  208. C -----------------------------------------
  209. C
  210. C
  211. C 2 2 2
  212. C EL1(X,KC) = X DRF(1,1+KC X ,1+X )
  213. C
  214. C
  215. C Lemniscate constant A
  216. C
  217. C -----------------------------------------
  218. C
  219. C
  220. C 1 4 -1/2
  221. C A = INT (1-S ) DS = DRF(0,1,2) = DRF(0,2,1)
  222. C 0
  223. C
  224. C
  225. C
  226. C -------------------------------------------------------------------
  227. C
  228. C***REFERENCES B. C. Carlson and E. M. Notis, Algorithms for incomplete
  229. C elliptic integrals, ACM Transactions on Mathematical
  230. C Software 7, 3 (September 1981), pp. 398-403.
  231. C B. C. Carlson, Computing elliptic integrals by
  232. C duplication, Numerische Mathematik 33, (1979),
  233. C pp. 1-16.
  234. C B. C. Carlson, Elliptic integrals of the first kind,
  235. C SIAM Journal of Mathematical Analysis 8, (1977),
  236. C pp. 231-242.
  237. C***ROUTINES CALLED D1MACH, XERMSG
  238. C***REVISION HISTORY (YYMMDD)
  239. C 790801 DATE WRITTEN
  240. C 890531 Changed all specific intrinsics to generic. (WRB)
  241. C 891009 Removed unreferenced statement labels. (WRB)
  242. C 891009 REVISION DATE from Version 3.2
  243. C 891214 Prologue converted to Version 4.0 format. (BAB)
  244. C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
  245. C 900326 Removed duplicate information from DESCRIPTION section.
  246. C (WRB)
  247. C 900510 Changed calls to XERMSG to standard form, and some
  248. C editorial changes. (RWC))
  249. C 920501 Reformatted the REFERENCES section. (WRB)
  250. C***END PROLOGUE DRF
  251. CHARACTER*16 XERN3, XERN4, XERN5, XERN6
  252. INTEGER IER
  253. DOUBLE PRECISION LOLIM, UPLIM, EPSLON, ERRTOL, D1MACH
  254. DOUBLE PRECISION C1, C2, C3, E2, E3, LAMDA
  255. DOUBLE PRECISION MU, S, X, XN, XNDEV
  256. DOUBLE PRECISION XNROOT, Y, YN, YNDEV, YNROOT, Z, ZN, ZNDEV,
  257. * ZNROOT
  258. LOGICAL FIRST
  259. SAVE ERRTOL,LOLIM,UPLIM,C1,C2,C3,FIRST
  260. DATA FIRST /.TRUE./
  261. C
  262. C***FIRST EXECUTABLE STATEMENT DRF
  263. C
  264. IF (FIRST) THEN
  265. ERRTOL = (4.0D0*D1MACH(3))**(1.0D0/6.0D0)
  266. LOLIM = 5.0D0 * D1MACH(1)
  267. UPLIM = D1MACH(2)/5.0D0
  268. C
  269. C1 = 1.0D0/24.0D0
  270. C2 = 3.0D0/44.0D0
  271. C3 = 1.0D0/14.0D0
  272. ENDIF
  273. FIRST = .FALSE.
  274. C
  275. C CALL ERROR HANDLER IF NECESSARY.
  276. C
  277. DRF = 0.0D0
  278. IF (MIN(X,Y,Z).LT.0.0D0) THEN
  279. IER = 1
  280. WRITE (XERN3, '(1PE15.6)') X
  281. WRITE (XERN4, '(1PE15.6)') Y
  282. WRITE (XERN5, '(1PE15.6)') Z
  283. CALL XERMSG ('SLATEC', 'DRF',
  284. * 'MIN(X,Y,Z).LT.0 WHERE X = ' // XERN3 // ' Y = ' // XERN4 //
  285. * ' AND Z = ' // XERN5, 1, 1)
  286. RETURN
  287. ENDIF
  288. C
  289. IF (MAX(X,Y,Z).GT.UPLIM) THEN
  290. IER = 3
  291. WRITE (XERN3, '(1PE15.6)') X
  292. WRITE (XERN4, '(1PE15.6)') Y
  293. WRITE (XERN5, '(1PE15.6)') Z
  294. WRITE (XERN6, '(1PE15.6)') UPLIM
  295. CALL XERMSG ('SLATEC', 'DRF',
  296. * 'MAX(X,Y,Z).GT.UPLIM WHERE X = ' // XERN3 // ' Y = ' //
  297. * XERN4 // ' Z = ' // XERN5 // ' AND UPLIM = ' // XERN6, 3, 1)
  298. RETURN
  299. ENDIF
  300. C
  301. IF (MIN(X+Y,X+Z,Y+Z).LT.LOLIM) THEN
  302. IER = 2
  303. WRITE (XERN3, '(1PE15.6)') X
  304. WRITE (XERN4, '(1PE15.6)') Y
  305. WRITE (XERN5, '(1PE15.6)') Z
  306. WRITE (XERN6, '(1PE15.6)') LOLIM
  307. CALL XERMSG ('SLATEC', 'DRF',
  308. * 'MIN(X+Y,X+Z,Y+Z).LT.LOLIM WHERE X = ' // XERN3 //
  309. * ' Y = ' // XERN4 // ' Z = ' // XERN5 // ' AND LOLIM = ' //
  310. * XERN6, 2, 1)
  311. RETURN
  312. ENDIF
  313. C
  314. IER = 0
  315. XN = X
  316. YN = Y
  317. ZN = Z
  318. C
  319. 30 MU = (XN+YN+ZN)/3.0D0
  320. XNDEV = 2.0D0 - (MU+XN)/MU
  321. YNDEV = 2.0D0 - (MU+YN)/MU
  322. ZNDEV = 2.0D0 - (MU+ZN)/MU
  323. EPSLON = MAX(ABS(XNDEV),ABS(YNDEV),ABS(ZNDEV))
  324. IF (EPSLON.LT.ERRTOL) GO TO 40
  325. XNROOT = SQRT(XN)
  326. YNROOT = SQRT(YN)
  327. ZNROOT = SQRT(ZN)
  328. LAMDA = XNROOT*(YNROOT+ZNROOT) + YNROOT*ZNROOT
  329. XN = (XN+LAMDA)*0.250D0
  330. YN = (YN+LAMDA)*0.250D0
  331. ZN = (ZN+LAMDA)*0.250D0
  332. GO TO 30
  333. C
  334. 40 E2 = XNDEV*YNDEV - ZNDEV*ZNDEV
  335. E3 = XNDEV*YNDEV*ZNDEV
  336. S = 1.0D0 + (C1*E2-0.10D0-C2*E3)*E2 + C3*E3
  337. DRF = S/SQRT(MU)
  338. C
  339. RETURN
  340. END