20 void gcf(
double& gammcf,
double a,
double x,
double &gln);
21 void gser(
double& gamser,
double a,
double x,
double& gln);
25 double gamser,gammcf,gln;
27 if (x < 0.0 || a <= 0.0)
28 cerr <<
"Invalid arguments in routine gammp" <<
endl;
40 double gamser,gammcf,gln;
42 if (x < 0.0 || a <= 0.0)
43 cerr <<
"Invalid arguments in routine gammp" <<
endl;
59 void gcf(
double& gammcf,
double a,
double x,
double &gln)
62 double an,b,c,d,del,h;
69 for (i=1;i<=
ITMAX;i++) {
82 cerr <<
"a too large, ITMAX too small in gcf" <<
endl;
83 gammcf=
exp(-x+a*
log(x)-(gln))*h;
92 void gser(
double& gamser,
double a,
double x,
double& gln)
100 cerr <<
"x less than 0 in routine gser" <<
endl;
106 for (n=1;n<=
ITMAX;n++) {
111 gamser=sum*
exp(-x+a*
log(x)-(gln));
115 cerr <<
"a too large, ITMAX too small in routine gser" <<
endl;
122 double Sn(
double x,
double a);
128 cerr <<
"a musdt be > 0.1" <<
endl;
139 double fprime=
exp(log_fprime);
143 while(
fabs(h)>1.e-12);
153 const double c=0.57721;
156 double logQ=
log(1-y);
157 double logB=logQ+
gammln(a);
159 double log_x0=1.e+100;
163 if ( logB>
log(.6) || (logB >
log(.45) && a>=.3) )
166 if (logB+logQ >
log(1.e-8))
168 logu=(logP+
gammln(1.0+a))/a;
172 logu=-
exp(logQ)/a -c;
176 double tmp=
log(1-u/(1.0+a));
180 else if ( a<.3 &&
log(.35) <= logB && logB <=
log(.6) )
182 double t=
exp(-c-
exp(logB));
183 double logt=-c-
exp(logB);
188 else if ( (
log(.15)<=logB && logB <=
log(.35)) ||
189 ((
log(.15)<=logB && logB <=
log(.45)) && a>=.3) )
192 double v=y-(1-a)*
log(y);
193 x0=y-(1-a)*
log(v)-
log(1+(1.0-a)/(1.0+v));
196 else if (
log(.01)<logB && logB <
log(.15))
199 double v=y-(1-a)*
log(y);
200 x0=y-(1-a)*
log(v)-
log((v*v+2*(3-a)*v+(2-a)*(3-a))/(v*v +(5-a)*v+2));
203 else if (logB <
log(.01))
206 double v=y-(1-a)*
log(y);
207 x0=y-(1-a)*
log(v)-
log((v*v+2*(3-a)*v+(2-a)*(3-a))/(v*v +(5-a)*v+2));
212 cerr <<
"this can't happen" <<
endl;
218 const double a0 = 3.31125922108741;
219 const double b1 = 6.61053765625462;
220 const double a1 = 11.6616720288968;
221 const double b2 = 6.40691597760039;
222 const double a2 = 4.28342155967104;
223 const double b3 = 1.27364489782223;
224 const double a3 = .213623493715853;
225 const double b4 = .03611708101884203;
240 double t=
sqrt(-2.0*logtau);
242 double num = (((a3*t+a2)*t+a1)*t)+a0;
243 double den = ((((b4*t+b3)*t+b2)*t)+b1)*t+1;
244 double s=sgn*(t-num/den);
249 double roota=
sqrt(a);
250 double w=a+s*roota+(s2-1)/3.0+(s3-7.0*s)/(36.*roota)
251 -(3.0*s4+7.0*s2-16)/(810.0*a)
252 +(9.0*s5+256.0*s3-433.0*s)/(38880.0*a*roota);
261 double v=logP+
gammln(a+1);
262 double u1=
exp(v+w)/a;
263 double S1=1+u1/(a+1);
264 double u2=
exp((v+u1-
log(S1))/a);
265 double S2=1+u2/(a+1)+u2*u2/((a+1)*(a+2));
266 double u3=
exp((v+u2-
log(S2))/a);
267 double S3=1+u3/(a+1)+u3*u3/((a+1)*(a+2))
268 + u3*u3*u3/((a+1)*(a+2)*(a+3));
269 double z=
exp((v+u3-
log(S3))/a);
277 double zbar=
exp((v+z-
log(sn))/a);
278 x0=zbar*(1.0-(a*
log(zbar)-zbar-v+
log(sn))/(a-zbar));
285 double u = -logB +(a-1.0)*
log(w)-
log(1.0+(1.0-a)/(1+w));
295 return log_x0-
log(a);
double gammln(double xx)
Log gamma function.
double inv_cumd_gamma(double y, double a)
double cumd_gamma(double x, double a)
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
df1_two_variable fabs(const df1_two_variable &x)
ivector sgn(const dvector &v)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
prnstream & endl(prnstream &)
d3_array sqrt(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
double get_initial_u(double a, double y)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
double gammp(double a, double x)
d3_array exp(const d3_array &arr3)
Returns d3_array results with computed exp from elements in arr3.
void gcf(double &gammcf, double a, double x, double &gln)
Incomplete gamma function.
void gser(double &gamser, double a, double x, double &gln)
Incomplete gamma function.
double Sn(double x, double a)
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.