drc.f 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. *DECK DRC
  2. DOUBLE PRECISION FUNCTION DRC (X, Y, IER)
  3. C***BEGIN PROLOGUE DRC
  4. C***PURPOSE Calculate a double precision approximation to
  5. C DRC(X,Y) = Integral from zero to infinity of
  6. C -1/2 -1
  7. C (1/2)(t+X) (t+Y) dt,
  8. C where X is nonnegative and Y is positive.
  9. C***LIBRARY SLATEC
  10. C***CATEGORY C14
  11. C***TYPE DOUBLE PRECISION (RC-S, DRC-D)
  12. C***KEYWORDS DUPLICATION THEOREM, ELEMENTARY FUNCTIONS,
  13. C ELLIPTIC INTEGRAL, TAYLOR SERIES
  14. C***AUTHOR Carlson, B. C.
  15. C Ames Laboratory-DOE
  16. C Iowa State University
  17. C Ames, IA 50011
  18. C Notis, E. M.
  19. C Ames Laboratory-DOE
  20. C Iowa State University
  21. C Ames, IA 50011
  22. C Pexton, R. L.
  23. C Lawrence Livermore National Laboratory
  24. C Livermore, CA 94550
  25. C***DESCRIPTION
  26. C
  27. C 1. DRC
  28. C Standard FORTRAN function routine
  29. C Double precision version
  30. C The routine calculates an approximation result to
  31. C DRC(X,Y) = integral from zero to infinity of
  32. C
  33. C -1/2 -1
  34. C (1/2)(t+X) (t+Y) dt,
  35. C
  36. C where X is nonnegative and Y is positive. The duplication
  37. C theorem is iterated until the variables are nearly equal,
  38. C and the function is then expanded in Taylor series to fifth
  39. C order. Logarithmic, inverse circular, and inverse hyper-
  40. C bolic functions can be expressed in terms of DRC.
  41. C
  42. C 2. Calling Sequence
  43. C DRC( X, Y, IER )
  44. C
  45. C Parameters On Entry
  46. C Values assigned by the calling routine
  47. C
  48. C X - Double precision, nonnegative variable
  49. C
  50. C Y - Double precision, positive variable
  51. C
  52. C
  53. C
  54. C On Return (values assigned by the DRC routine)
  55. C
  56. C DRC - Double precision approximation to the integral
  57. C
  58. C IER - Integer to indicate normal or abnormal termination.
  59. C
  60. C IER = 0 Normal and reliable termination of the
  61. C routine. It is assumed that the requested
  62. C accuracy has been achieved.
  63. C
  64. C IER > 0 Abnormal termination of the routine
  65. C
  66. C X and Y are unaltered.
  67. C
  68. C 3. Error messages
  69. C
  70. C Value of IER assigned by the DRC routine
  71. C
  72. C Value assigned Error message printed
  73. C IER = 1 X.LT.0.0D0.OR.Y.LE.0.0D0
  74. C = 2 X+Y.LT.LOLIM
  75. C = 3 MAX(X,Y) .GT. UPLIM
  76. C
  77. C 4. Control parameters
  78. C
  79. C Values of LOLIM, UPLIM, and ERRTOL are set by the
  80. C routine.
  81. C
  82. C LOLIM and UPLIM determine the valid range of X and Y
  83. C
  84. C LOLIM - Lower limit of valid arguments
  85. C
  86. C Not less than 5 * (machine minimum) .
  87. C
  88. C UPLIM - Upper limit of valid arguments
  89. C
  90. C Not greater than (machine maximum) / 5 .
  91. C
  92. C
  93. C Acceptable values for: LOLIM UPLIM
  94. C IBM 360/370 SERIES : 3.0D-78 1.0D+75
  95. C CDC 6000/7000 SERIES : 1.0D-292 1.0D+321
  96. C UNIVAC 1100 SERIES : 1.0D-307 1.0D+307
  97. C CRAY : 2.3D-2466 1.0D+2465
  98. C VAX 11 SERIES : 1.5D-38 3.0D+37
  99. C
  100. C ERRTOL determines the accuracy of the answer
  101. C
  102. C The value assigned by the routine will result
  103. C in solution precision within 1-2 decimals of
  104. C "machine precision".
  105. C
  106. C
  107. C ERRTOL - relative error due to truncation is less than
  108. C 16 * ERRTOL ** 6 / (1 - 2 * ERRTOL).
  109. C
  110. C
  111. C The accuracy of the computed approximation to the inte-
  112. C gral can be controlled by choosing the value of ERRTOL.
  113. C Truncation of a Taylor series after terms of fifth order
  114. C introduces an error less than the amount shown in the
  115. C second column of the following table for each value of
  116. C ERRTOL in the first column. In addition to the trunca-
  117. C tion error there will be round-off error, but in prac-
  118. C tice the total error from both sources is usually less
  119. C than the amount given in the table.
  120. C
  121. C
  122. C
  123. C Sample choices: ERRTOL Relative truncation
  124. C error less than
  125. C 1.0D-3 2.0D-17
  126. C 3.0D-3 2.0D-14
  127. C 1.0D-2 2.0D-11
  128. C 3.0D-2 2.0D-8
  129. C 1.0D-1 2.0D-5
  130. C
  131. C
  132. C Decreasing ERRTOL by a factor of 10 yields six more
  133. C decimal digits of accuracy at the expense of one or
  134. C two more iterations of the duplication theorem.
  135. C
  136. C *Long Description:
  137. C
  138. C DRC special comments
  139. C
  140. C
  141. C
  142. C
  143. C Check: DRC(X,X+Z) + DRC(Y,Y+Z) = DRC(0,Z)
  144. C
  145. C where X, Y, and Z are positive and X * Y = Z * Z
  146. C
  147. C
  148. C On Input:
  149. C
  150. C X, and Y are the variables in the integral DRC(X,Y).
  151. C
  152. C On Output:
  153. C
  154. C X and Y are unaltered.
  155. C
  156. C
  157. C
  158. C DRC(0,1/4)=DRC(1/16,1/8)=PI=3.14159...
  159. C
  160. C DRC(9/4,2)=LN(2)
  161. C
  162. C
  163. C
  164. C ********************************************************
  165. C
  166. C WARNING: Changes in the program may improve speed at the
  167. C expense of robustness.
  168. C
  169. C
  170. C --------------------------------------------------------------------
  171. C
  172. C Special functions via DRC
  173. C
  174. C
  175. C
  176. C LN X X .GT. 0
  177. C
  178. C 2
  179. C LN(X) = (X-1) DRC(((1+X)/2) , X )
  180. C
  181. C
  182. C --------------------------------------------------------------------
  183. C
  184. C ARCSIN X -1 .LE. X .LE. 1
  185. C
  186. C 2
  187. C ARCSIN X = X DRC (1-X ,1 )
  188. C
  189. C --------------------------------------------------------------------
  190. C
  191. C ARCCOS X 0 .LE. X .LE. 1
  192. C
  193. C
  194. C 2 2
  195. C ARCCOS X = SQRT(1-X ) DRC(X ,1 )
  196. C
  197. C --------------------------------------------------------------------
  198. C
  199. C ARCTAN X -INF .LT. X .LT. +INF
  200. C
  201. C 2
  202. C ARCTAN X = X DRC(1,1+X )
  203. C
  204. C --------------------------------------------------------------------
  205. C
  206. C ARCCOT X 0 .LE. X .LT. INF
  207. C
  208. C 2 2
  209. C ARCCOT X = DRC(X ,X +1 )
  210. C
  211. C --------------------------------------------------------------------
  212. C
  213. C ARCSINH X -INF .LT. X .LT. +INF
  214. C
  215. C 2
  216. C ARCSINH X = X DRC(1+X ,1 )
  217. C
  218. C --------------------------------------------------------------------
  219. C
  220. C ARCCOSH X X .GE. 1
  221. C
  222. C 2 2
  223. C ARCCOSH X = SQRT(X -1) DRC(X ,1 )
  224. C
  225. C --------------------------------------------------------------------
  226. C
  227. C ARCTANH X -1 .LT. X .LT. 1
  228. C
  229. C 2
  230. C ARCTANH X = X DRC(1,1-X )
  231. C
  232. C --------------------------------------------------------------------
  233. C
  234. C ARCCOTH X X .GT. 1
  235. C
  236. C 2 2
  237. C ARCCOTH X = DRC(X ,X -1 )
  238. C
  239. C --------------------------------------------------------------------
  240. C
  241. C***REFERENCES B. C. Carlson and E. M. Notis, Algorithms for incomplete
  242. C elliptic integrals, ACM Transactions on Mathematical
  243. C Software 7, 3 (September 1981), pp. 398-403.
  244. C B. C. Carlson, Computing elliptic integrals by
  245. C duplication, Numerische Mathematik 33, (1979),
  246. C pp. 1-16.
  247. C B. C. Carlson, Elliptic integrals of the first kind,
  248. C SIAM Journal of Mathematical Analysis 8, (1977),
  249. C pp. 231-242.
  250. C***ROUTINES CALLED D1MACH, XERMSG
  251. C***REVISION HISTORY (YYMMDD)
  252. C 790801 DATE WRITTEN
  253. C 890531 Changed all specific intrinsics to generic. (WRB)
  254. C 891009 Removed unreferenced statement labels. (WRB)
  255. C 891009 REVISION DATE from Version 3.2
  256. C 891214 Prologue converted to Version 4.0 format. (BAB)
  257. C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
  258. C 900326 Removed duplicate information from DESCRIPTION section.
  259. C (WRB)
  260. C 900510 Changed calls to XERMSG to standard form, and some
  261. C editorial changes. (RWC))
  262. C 920501 Reformatted the REFERENCES section. (WRB)
  263. C***END PROLOGUE DRC
  264. CHARACTER*16 XERN3, XERN4, XERN5
  265. INTEGER IER
  266. DOUBLE PRECISION C1, C2, ERRTOL, LAMDA, LOLIM, D1MACH
  267. DOUBLE PRECISION MU, S, SN, UPLIM, X, XN, Y, YN
  268. LOGICAL FIRST
  269. SAVE ERRTOL,LOLIM,UPLIM,C1,C2,FIRST
  270. DATA FIRST /.TRUE./
  271. C
  272. C***FIRST EXECUTABLE STATEMENT DRC
  273. IF (FIRST) THEN
  274. ERRTOL = (D1MACH(3)/16.0D0)**(1.0D0/6.0D0)
  275. LOLIM = 5.0D0 * D1MACH(1)
  276. UPLIM = D1MACH(2) / 5.0D0
  277. C
  278. C1 = 1.0D0/7.0D0
  279. C2 = 9.0D0/22.0D0
  280. ENDIF
  281. FIRST = .FALSE.
  282. C
  283. C CALL ERROR HANDLER IF NECESSARY.
  284. C
  285. DRC = 0.0D0
  286. IF (X.LT.0.0D0.OR.Y.LE.0.0D0) THEN
  287. IER = 1
  288. WRITE (XERN3, '(1PE15.6)') X
  289. WRITE (XERN4, '(1PE15.6)') Y
  290. CALL XERMSG ('SLATEC', 'DRC',
  291. * 'X.LT.0 .OR. Y.LE.0 WHERE X = ' // XERN3 // ' AND Y = ' //
  292. * XERN4, 1, 1)
  293. RETURN
  294. ENDIF
  295. C
  296. IF (MAX(X,Y).GT.UPLIM) THEN
  297. IER = 3
  298. WRITE (XERN3, '(1PE15.6)') X
  299. WRITE (XERN4, '(1PE15.6)') Y
  300. WRITE (XERN5, '(1PE15.6)') UPLIM
  301. CALL XERMSG ('SLATEC', 'DRC',
  302. * 'MAX(X,Y).GT.UPLIM WHERE X = ' // XERN3 // ' Y = ' //
  303. * XERN4 // ' AND UPLIM = ' // XERN5, 3, 1)
  304. RETURN
  305. ENDIF
  306. C
  307. IF (X+Y.LT.LOLIM) THEN
  308. IER = 2
  309. WRITE (XERN3, '(1PE15.6)') X
  310. WRITE (XERN4, '(1PE15.6)') Y
  311. WRITE (XERN5, '(1PE15.6)') LOLIM
  312. CALL XERMSG ('SLATEC', 'DRC',
  313. * 'X+Y.LT.LOLIM WHERE X = ' // XERN3 // ' Y = ' // XERN4 //
  314. * ' AND LOLIM = ' // XERN5, 2, 1)
  315. RETURN
  316. ENDIF
  317. C
  318. IER = 0
  319. XN = X
  320. YN = Y
  321. C
  322. 30 MU = (XN+YN+YN)/3.0D0
  323. SN = (YN+MU)/MU - 2.0D0
  324. IF (ABS(SN).LT.ERRTOL) GO TO 40
  325. LAMDA = 2.0D0*SQRT(XN)*SQRT(YN) + YN
  326. XN = (XN+LAMDA)*0.250D0
  327. YN = (YN+LAMDA)*0.250D0
  328. GO TO 30
  329. C
  330. 40 S = SN*SN*(0.30D0+SN*(C1+SN*(0.3750D0+SN*C2)))
  331. DRC = (1.0D0+S)/SQRT(MU)
  332. RETURN
  333. END