2
REAL FUNCTION RF (X, Y, Z, IER)
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
8
C (1/2)(t+X) (t+Y) (t+Z) dt.
9
C If X, Y or Z is zero, the integral is complete.
12
C***TYPE SINGLE PRECISION (RF-S, DRF-D)
13
C***KEYWORDS COMPLETE ELLIPTIC INTEGRAL, DUPLICATION THEOREM,
14
C INCOMPLETE ELLIPTIC INTEGRAL, INTEGRAL OF THE FIRST KIND,
16
C***AUTHOR Carlson, B. C.
18
C Iowa State University
22
C Iowa State University
25
C Lawrence Livermore National Laboratory
30
C Evaluate an INCOMPLETE (or COMPLETE) ELLIPTIC INTEGRAL
32
C Standard FORTRAN function routine
33
C Single precision version
34
C The routine calculates an approximation result to
35
C RF(X,Y,Z) = Integral from zero to infinity of
38
C (1/2)(t+X) (t+Y) (t+Z) dt,
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.
50
C Values assigned by the calling routine
52
C X - Single precision, nonnegative variable
54
C Y - Single precision, nonnegative variable
56
C Z - Single precision, nonnegative variable
60
C On Return (values assigned by the RF routine)
62
C RF - Single precision approximation to the integral
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.
70
C IER > 0 Abnormal termination of the routine
72
C X, Y, Z are unaltered.
77
C Value of IER assigned by the RF routine
79
C Value assigned Error Message Printed
80
C IER = 1 MIN(X,Y,Z) .LT. 0.0E0
81
C = 2 MIN(X+Y,X+Z,Y+Z) .LT. LOLIM
82
C = 3 MAX(X,Y,Z) .GT. UPLIM
86
C 4. Control Parameters
88
C Values of LOLIM, UPLIM, and ERRTOL are set by the
91
C LOLIM and UPLIM determine the valid range of X, Y and Z
93
C LOLIM - Lower limit of valid arguments
95
C Not less than 5 * (machine minimum).
97
C UPLIM - Upper limit of valid arguments
99
C Not greater than (machine maximum) / 5.
102
C Acceptable Values For: LOLIM UPLIM
103
C IBM 360/370 SERIES : 3.0E-78 1.0E+75
104
C CDC 6000/7000 SERIES : 1.0E-292 1.0E+321
105
C UNIVAC 1100 SERIES : 1.0E-37 1.0E+37
106
C CRAY : 2.3E-2466 1.09E+2465
107
C VAX 11 SERIES : 1.5E-38 3.0E+37
111
C ERRTOL determines the accuracy of the answer
113
C The value assigned by the routine will result
114
C in solution precision within 1-2 decimals of
115
C "machine precision".
119
C ERRTOL - Relative error due to truncation is less than
120
C ERRTOL ** 6 / (4 * (1-ERRTOL) .
124
C The accuracy of the computed approximation to the inte-
125
C gral can be controlled by choosing the value of ERRTOL.
126
C Truncation of a Taylor series after terms of fifth order
127
C introduces an error less than the amount shown in the
128
C second column of the following table for each value of
129
C ERRTOL in the first column. In addition to the trunca-
130
C tion error there will be round-off error, but in prac-
131
C tice the total error from both sources is usually less
132
C than the amount given in the table.
138
C Sample Choices: ERRTOL Relative Truncation
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.
153
C RF Special Comments
157
C Check by addition theorem: RF(X,X+Z,X+W) + RF(Y,Y+Z,Y+W)
158
C = RF(0,Z,W), where X,Y,Z,W are positive and X * Y = Z * W.
163
C X, Y, and Z are the variables in the integral RF(X,Y,Z).
169
C X, Y, and Z are unaltered.
173
C ********************************************************
175
C Warning: Changes in the program may improve speed at the
176
C expense of robustness.
180
C Special Functions via RF
183
C Legendre form of ELLIPTIC INTEGRAL of 1st kind
184
C ----------------------------------------------
188
C F(PHI,K) = SIN(PHI) RF(COS (PHI),1-K SIN (PHI),1)
192
C K(K) = RF(0,1-K ,1)
195
C = INT (1-K SIN (PHI) ) D PHI
202
C Bulirsch form of ELLIPTIC INTEGRAL of 1st kind
203
C ----------------------------------------------
207
C EL1(X,KC) = X RF(1,1+KC X ,1+X )
212
C Lemniscate constant A
213
C ---------------------
217
C A = INT (1-S ) DS = RF(0,1,2) = RF(0,2,1)
221
C -------------------------------------------------------------------
223
C***REFERENCES B. C. Carlson and E. M. Notis, Algorithms for incomplete
224
C elliptic integrals, ACM Transactions on Mathematical
225
C Software 7, 3 (September 1981), pp. 398-403.
226
C B. C. Carlson, Computing elliptic integrals by
227
C duplication, Numerische Mathematik 33, (1979),
229
C B. C. Carlson, Elliptic integrals of the first kind,
230
C SIAM Journal of Mathematical Analysis 8, (1977),
232
C***ROUTINES CALLED R1MACH, XERMSG
233
C***REVISION HISTORY (YYMMDD)
234
C 790801 DATE WRITTEN
235
C 890531 Changed all specific intrinsics to generic. (WRB)
236
C 891009 Removed unreferenced statement labels. (WRB)
237
C 891009 REVISION DATE from Version 3.2
238
C 891214 Prologue converted to Version 4.0 format. (BAB)
239
C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
240
C 900326 Removed duplicate information from DESCRIPTION section.
242
C 900510 Changed calls to XERMSG to standard form, and some
243
C editorial changes. (RWC))
244
C 920501 Reformatted the REFERENCES section. (WRB)
246
CHARACTER*16 XERN3, XERN4, XERN5, XERN6
248
REAL LOLIM, UPLIM, EPSLON, ERRTOL
249
REAL C1, C2, C3, E2, E3, LAMDA
250
REAL MU, S, X, XN, XNDEV
251
REAL XNROOT, Y, YN, YNDEV, YNROOT, Z, ZN, ZNDEV,
254
SAVE ERRTOL,LOLIM,UPLIM,C1,C2,C3,FIRST
257
C***FIRST EXECUTABLE STATEMENT RF
260
ERRTOL = (4.0E0*R1MACH(3))**(1.0E0/6.0E0)
261
LOLIM = 5.0E0 * R1MACH(1)
262
UPLIM = R1MACH(2)/5.0E0
270
C CALL ERROR HANDLER IF NECESSARY.
273
IF (MIN(X,Y,Z).LT.0.0E0) THEN
275
WRITE (XERN3, '(1PE15.6)') X
276
WRITE (XERN4, '(1PE15.6)') Y
277
WRITE (XERN5, '(1PE15.6)') Z
278
CALL XERMSG ('SLATEC', 'RF',
279
* 'MIN(X,Y,Z).LT.0 WHERE X = ' // XERN3 // ' Y = ' // XERN4 //
280
* ' AND Z = ' // XERN5, 1, 1)
284
IF (MAX(X,Y,Z).GT.UPLIM) THEN
286
WRITE (XERN3, '(1PE15.6)') X
287
WRITE (XERN4, '(1PE15.6)') Y
288
WRITE (XERN5, '(1PE15.6)') Z
289
WRITE (XERN6, '(1PE15.6)') UPLIM
290
CALL XERMSG ('SLATEC', 'RF',
291
* 'MAX(X,Y,Z).GT.UPLIM WHERE X = ' // XERN3 // ' Y = ' //
292
* XERN4 // ' Z = ' // XERN5 // ' AND UPLIM = ' // XERN6, 3, 1)
296
IF (MIN(X+Y,X+Z,Y+Z).LT.LOLIM) THEN
298
WRITE (XERN3, '(1PE15.6)') X
299
WRITE (XERN4, '(1PE15.6)') Y
300
WRITE (XERN5, '(1PE15.6)') Z
301
WRITE (XERN6, '(1PE15.6)') LOLIM
302
CALL XERMSG ('SLATEC', 'RF',
303
* 'MIN(X+Y,X+Z,Y+Z).LT.LOLIM WHERE X = ' // XERN3 //
304
* ' Y = ' // XERN4 // ' Z = ' // XERN5 // ' AND LOLIM = ' //
314
30 MU = (XN+YN+ZN)/3.0E0
315
XNDEV = 2.0E0 - (MU+XN)/MU
316
YNDEV = 2.0E0 - (MU+YN)/MU
317
ZNDEV = 2.0E0 - (MU+ZN)/MU
318
EPSLON = MAX(ABS(XNDEV), ABS(YNDEV), ABS(ZNDEV))
319
IF (EPSLON.LT.ERRTOL) GO TO 40
323
LAMDA = XNROOT*(YNROOT+ZNROOT) + YNROOT*ZNROOT
324
XN = (XN+LAMDA)*0.250E0
325
YN = (YN+LAMDA)*0.250E0
326
ZN = (ZN+LAMDA)*0.250E0
329
40 E2 = XNDEV*YNDEV - ZNDEV*ZNDEV
330
E3 = XNDEV*YNDEV*ZNDEV
331
S = 1.0E0 + (C1*E2-0.10E0-C2*E3)*E2 + C3*E3