3
* Inverse of complemented imcomplete Gamma integral
9
* double a, x, p, igami();
15
* Given p, the function finds x such that
19
* Starting with the approximate value
26
* t = 1 - d - ndtri(p) sqrt(d)
32
* the routine performs up to 10 Newton iterations to find the
33
* root of igamc(a,x) - p = 0.
37
* Tested at random a, p in the intervals indicated.
40
* arithmetic domain domain # trials peak rms
41
* IEEE 0.5,100 0,0.5 100000 1.0e-14 1.7e-15
42
* IEEE 0.01,0.5 0,0.5 100000 9.0e-14 3.4e-15
43
* IEEE 0.5,10000 0,0.5 20000 2.3e-13 3.8e-14
47
Cephes Math Library Release 2.3: March, 1995
48
Copyright 1984, 1987, 1995 by Stephen L. Moshier
54
extern double MACHEP, MAXNUM, MAXLOG, MINLOG, NAN;
56
double igamc(), ndtri(), exp(), fabs(), log(), sqrt(), lgam();
62
double x0, x1, x, yl, yh, y, d, lgm, dithresh;
65
/* bound the solution */
70
dithresh = 5.0 * MACHEP;
72
if ((y0<0.0) || (y0>1.0) || (a<=0)) {
73
mtherr("igami", DOMAIN);
85
/* approximation to inverse function */
87
y = ( 1.0 - d - ndtri(y0) * sqrt(d) );
94
if( x > x0 || x < x1 )
97
if( y < yl || y > yh )
109
/* compute the derivative of the function at this point */
110
d = (a - 1.0) * log(x) - x - lgm;
114
/* compute the step to the next approximation of x */
116
if( fabs(d/x) < MACHEP )
121
/* Resort to interval halving if Newton iteration did not converge. */
129
while( x0 == MAXNUM )
145
for( i=0; i<400; i++ )
147
x = x1 + d * (x0 - x1);
149
lgm = (x0 - x1)/(x1 + x0);
150
if( fabs(lgm) < dithresh )
153
if( fabs(lgm) < dithresh )
169
d = (y0 - yl)/(yh - yl);
184
d = (y0 - yl)/(yh - yl);
189
mtherr( "igami", UNDERFLOW );