GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
erfc.f
Go to the documentation of this file.
1 *DECK ERFC
2  FUNCTION erfc (X)
3 C***BEGIN PROLOGUE ERFC
4 C***PURPOSE Compute the complementary error function.
5 C***LIBRARY SLATEC (FNLIB)
6 C***CATEGORY C8A, L5A1E
7 C***TYPE SINGLE PRECISION (ERFC-S, DERFC-D)
8 C***KEYWORDS COMPLEMENTARY ERROR FUNCTION, ERFC, FNLIB,
9 C SPECIAL FUNCTIONS
10 C***AUTHOR Fullerton, W., (LANL)
11 C***DESCRIPTION
12 C
13 C ERFC(X) calculates the single precision complementary error
14 C function for single precision argument X.
15 C
16 C Series for ERF on the interval 0. to 1.00000D+00
17 C with weighted error 7.10E-18
18 C log weighted error 17.15
19 C significant figures required 16.31
20 C decimal places required 17.71
21 C
22 C Series for ERFC on the interval 0. to 2.50000D-01
23 C with weighted error 4.81E-17
24 C log weighted error 16.32
25 C approx significant figures required 15.0
26 C
27 C
28 C Series for ERC2 on the interval 2.50000D-01 to 1.00000D+00
29 C with weighted error 5.22E-17
30 C log weighted error 16.28
31 C approx significant figures required 15.0
32 C decimal places required 16.96
33 C
34 C***REFERENCES (NONE)
35 C***ROUTINES CALLED CSEVL, INITS, R1MACH, XERMSG
36 C***REVISION HISTORY (YYMMDD)
37 C 770701 DATE WRITTEN
38 C 890531 Changed all specific intrinsics to generic. (WRB)
39 C 890531 REVISION DATE from Version 3.2
40 C 891214 Prologue converted to Version 4.0 format. (BAB)
41 C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)
42 C 920618 Removed space from variable names. (RWC, WRB)
43 C***END PROLOGUE ERFC
44  dimension erfcs(13), erfccs(24), erc2cs(23)
45  LOGICAL first
46  SAVE erfcs, erc2cs, erfccs, sqrtpi, nterf, nterfc,
47  1 nterc2, xsml, xmax, sqeps, first
48  DATA erfcs( 1) / -.0490461212 34691808e0 /
49  DATA erfcs( 2) / -.1422612051 0371364e0 /
50  DATA erfcs( 3) / .0100355821 87599796e0 /
51  DATA erfcs( 4) / -.0005768764 69976748e0 /
52  DATA erfcs( 5) / .0000274199 31252196e0 /
53  DATA erfcs( 6) / -.0000011043 17550734e0 /
54  DATA erfcs( 7) / .0000000384 88755420e0 /
55  DATA erfcs( 8) / -.0000000011 80858253e0 /
56  DATA erfcs( 9) / .0000000000 32334215e0 /
57  DATA erfcs(10) / -.0000000000 00799101e0 /
58  DATA erfcs(11) / .0000000000 00017990e0 /
59  DATA erfcs(12) / -.0000000000 00000371e0 /
60  DATA erfcs(13) / .0000000000 00000007e0 /
61  DATA erc2cs( 1) / -.0696013466 02309501e0 /
62  DATA erc2cs( 2) / -.0411013393 62620893e0 /
63  DATA erc2cs( 3) / .0039144958 66689626e0 /
64  DATA erc2cs( 4) / -.0004906395 65054897e0 /
65  DATA erc2cs( 5) / .0000715747 90013770e0 /
66  DATA erc2cs( 6) / -.0000115307 16341312e0 /
67  DATA erc2cs( 7) / .0000019946 70590201e0 /
68  DATA erc2cs( 8) / -.0000003642 66647159e0 /
69  DATA erc2cs( 9) / .0000000694 43726100e0 /
70  DATA erc2cs(10) / -.0000000137 12209021e0 /
71  DATA erc2cs(11) / .0000000027 88389661e0 /
72  DATA erc2cs(12) / -.0000000005 81416472e0 /
73  DATA erc2cs(13) / .0000000001 23892049e0 /
74  DATA erc2cs(14) / -.0000000000 26906391e0 /
75  DATA erc2cs(15) / .0000000000 05942614e0 /
76  DATA erc2cs(16) / -.0000000000 01332386e0 /
77  DATA erc2cs(17) / .0000000000 00302804e0 /
78  DATA erc2cs(18) / -.0000000000 00069666e0 /
79  DATA erc2cs(19) / .0000000000 00016208e0 /
80  DATA erc2cs(20) / -.0000000000 00003809e0 /
81  DATA erc2cs(21) / .0000000000 00000904e0 /
82  DATA erc2cs(22) / -.0000000000 00000216e0 /
83  DATA erc2cs(23) / .0000000000 00000052e0 /
84  DATA erfccs( 1) / 0.0715179310 202925e0 /
85  DATA erfccs( 2) / -.0265324343 37606719e0 /
86  DATA erfccs( 3) / .0017111539 77920853e0 /
87  DATA erfccs( 4) / -.0001637516 63458512e0 /
88  DATA erfccs( 5) / .0000198712 93500549e0 /
89  DATA erfccs( 6) / -.0000028437 12412769e0 /
90  DATA erfccs( 7) / .0000004606 16130901e0 /
91  DATA erfccs( 8) / -.0000000822 77530261e0 /
92  DATA erfccs( 9) / .0000000159 21418724e0 /
93  DATA erfccs(10) / -.0000000032 95071356e0 /
94  DATA erfccs(11) / .0000000007 22343973e0 /
95  DATA erfccs(12) / -.0000000001 66485584e0 /
96  DATA erfccs(13) / .0000000000 40103931e0 /
97  DATA erfccs(14) / -.0000000000 10048164e0 /
98  DATA erfccs(15) / .0000000000 02608272e0 /
99  DATA erfccs(16) / -.0000000000 00699105e0 /
100  DATA erfccs(17) / .0000000000 00192946e0 /
101  DATA erfccs(18) / -.0000000000 00054704e0 /
102  DATA erfccs(19) / .0000000000 00015901e0 /
103  DATA erfccs(20) / -.0000000000 00004729e0 /
104  DATA erfccs(21) / .0000000000 00001432e0 /
105  DATA erfccs(22) / -.0000000000 00000439e0 /
106  DATA erfccs(23) / .0000000000 00000138e0 /
107  DATA erfccs(24) / -.0000000000 00000048e0 /
108  DATA sqrtpi /1.772453850 9055160e0/
109  DATA first /.true./
110 C***FIRST EXECUTABLE STATEMENT ERFC
111  IF (first) THEN
112  eta = 0.1*r1mach(3)
113  nterf = inits(erfcs, 13, eta)
114  nterfc = inits(erfccs, 24, eta)
115  nterc2 = inits(erc2cs, 23, eta)
116 C
117  xsml = -sqrt(-log(sqrtpi*r1mach(3)))
118  txmax = sqrt(-log(sqrtpi*r1mach(1)))
119  xmax = txmax - 0.5*log(txmax)/txmax - 0.01
120  sqeps = sqrt(2.0*r1mach(3))
121  ENDIF
122  first = .false.
123 C
124  IF (isnan(x)) THEN
125  erfc = x
126  RETURN
127  ENDIF
128 C
129  IF (x.GT.xsml) go to 20
130 C
131 C ERFC(X) = 1.0 - ERF(X) FOR X .LT. XSML
132 C
133  erfc = 2.
134  RETURN
135 C
136  20 IF (x.GT.xmax) go to 40
137  y = abs(x)
138  IF (y.GT.1.0) go to 30
139 C
140 C ERFC(X) = 1.0 - ERF(X) FOR -1. .LE. X .LE. 1.
141 C
142  IF (y.LT.sqeps) erfc = 1.0 - 2.0*x/sqrtpi
143  IF (y.GE.sqeps) erfc = 1.0 -
144  1 x*(1.0 + csevl(2.*x*x-1., erfcs, nterf) )
145  RETURN
146 C
147 C ERFC(X) = 1.0 - ERF(X) FOR 1. .LT. ABS(X) .LE. XMAX
148 C
149  30 y = y*y
150  IF (y.LE.4.) erfc = exp(-y)/abs(x) * (0.5 + csevl((8./y-5.)/3.,
151  1 erc2cs, nterc2) )
152  IF (y.GT.4.) erfc = exp(-y)/abs(x) * (0.5 + csevl(8./y-1.,
153  1 erfccs, nterfc) )
154  IF (x.LT.0.) erfc = 2.0 - erfc
155  RETURN
156 C
157  40 erfc = 0.
158  RETURN
159 C
160  END