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.8: June, 2000
48 Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
53 extern double MACHEP, MAXNUM, MAXLOG, MINLOG;
55 extern double igamc ( double, double );
56 extern double ndtri ( double );
57 extern double exp ( double );
58 extern double fabs ( double );
59 extern double log ( double );
60 extern double sqrt ( double );
61 extern double lgam ( double );
63 double igamc(), ndtri(), exp(), fabs(), log(), sqrt(), lgam();
69 double x0, x1, x, yl, yh, y, d, lgm, dithresh;
72 /* bound the solution */
77 dithresh = 5.0 * MACHEP;
79 /* approximation to inverse function */
81 y = ( 1.0 - d - ndtri(y0) * sqrt(d) );
88 if( x > x0 || x < x1 )
91 if( y < yl || y > yh )
103 /* compute the derivative of the function at this point */
104 d = (a - 1.0) * log(x) - x - lgm;
108 /* compute the step to the next approximation of x */
110 if( fabs(d/x) < MACHEP )
115 /* Resort to interval halving if Newton iteration did not converge. */
123 while( x0 == MAXNUM )
139 for( i=0; i<400; i++ )
141 x = x1 + d * (x0 - x1);
143 lgm = (x0 - x1)/(x1 + x0);
144 if( fabs(lgm) < dithresh )
147 if( fabs(lgm) < dithresh )
163 d = (y0 - yl)/(yh - yl);
178 d = (y0 - yl)/(yh - yl);
183 mtherr( "igami", UNDERFLOW );