rc.f 11 KB

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