// ************************************************************** fdouble gammp(fdouble a, fdouble x) /** * Returns the incomplete gamma function P (a, x). * See "Numerical Recipes in C", 2nd edition, page 218 */ { fdouble gamser, gammcf, gln; if (x < 0.0 || a <= 0.0) { std_cout << "Invalid arguments in routine gammp\n"; abort(); } if (x < (a+fone)) { //Use the series representation. gser(&gamser, a, x, &gln); return gamser; } else { // Use the continued fraction representation and take its complement. gcf(&gammcf, a, x, &gln); return fone - gammcf; } }
int main(void) { char txt[MAXSTR]; int i,nval; float a,gamser,gln,val,x; FILE *fp; if ((fp = fopen("fncval.dat","r")) == NULL) nrerror("Data file fncval.dat not found\n"); fgets(txt,MAXSTR,fp); while (strncmp(txt,"Incomplete Gamma Function",25)) { fgets(txt,MAXSTR,fp); if (feof(fp)) nrerror("Data not found in fncval.dat\n"); } fscanf(fp,"%d %*s",&nval); printf("\n%s\n",txt); printf("%4s %11s %14s %14s %12s %8s\n","a","x", "actual","gser(a,x)","gammln(a)","gln"); for (i=1; i<=nval; i++) { fscanf(fp,"%f %f %f",&a,&x,&val); gser(&gamser,a,x,&gln); printf("%6.2f %12.6f %12.6f %12.6f %12.6f %12.6f\n", a,x,val,gamser,gammln(a),gln); } fclose(fp); return 0; }
double gammq(double a, double x) { if (x < a || a <= 0.0) { if (a < 0) fprintf(stderr, "gammq(%f, %f): invalid arguments\n", a, x); return 0.0; } if (x < a + 1.0) return 1.0 - gser(a, x); return gcf(a, x); }
/** Represents incomplete error function, P(a,x) **/ float gammp(float a, float x) { float gamser,gammcf,gln; if(x < 0.0 || a <= 0.0) printf("Invalid arguments in routine gammp"); if (x < (a+1.0)) { gser(&gamser,a,x,&gln); return gamser; } else { gcf(&gammcf,a,x,&gln); return 1.0 - gammcf; } }
double gammq(double a, double x) { if(x < 0.0 || a <= 0.0) printf("bad args in gammq\n"); if(x == 0.0) return 1.0; else if((int) a >= ASWITCH) return gammpapprox(a, x, 0); else if(x < a + 1.0) return 1.0 - gser(a, x); else return gcf(a, x); }
double gammq ( double a, double x ) { double gamser,gammcf,gln; if (x < 0.0 || a <= 0.0) nrerror("Invalid arguments in routine GAMMQ"); if (x < (a+1.0)) { gser(&gamser,a,x,&gln); return 1.0-gamser; } else { gcf(&gammcf,a,x,&gln); return gammcf; } }
double numrec_gammp(double a, double x) { double gamser,gammcf,gln; if (x < 0.0 || a <= 0.0) my_error("Invalid arguments in routine gammp"); if (x < (a+1.0)) { gser(&gamser,a,x,&gln); return gamser; } else { gcf(&gammcf,a,x,&gln); return 1.0-gammcf; } }
float gammp(float a, float x) { if(x < 0.0 || a <= 0.0) printf("bad args in gammp\n"); if(x == 0.0) return 0.0; else if((int) a >= ASWITCH) return gammpapprox(a, x, 1); else if(x < a + 1.0) return gser(a, x); else return 1.0 - gcf(a, x); }
double gammaq(double a, double x) { double gamser,gammcf,gln; if (x < 0.0 || a <= 0.0) return 0; if (x < (a+1.0)) { gser(&gamser,a,x,&gln); return 1.0-gamser; } else { gcf(&gammcf,a,x,&gln); return gammcf; } }
double Statistics::gammq(double a, double x) { double gamser, gammcf, gln, pval; if(x < (a + 1.0)){ gser(&gamser, a, x, &gln); pval = 1.0 - gamser; } else{ gcf(&gammcf, a, x, &gln); pval = gammcf; } return pval; }
DP NR::gammp(const DP a, const DP x) { DP gamser,gammcf,gln; if (x < 0.0 || a <= 0.0) nrerror("Invalid arguments in routine gammp"); if (x < a+1.0) { gser(gamser,a,x,gln); return gamser; } else { gcf(gammcf,a,x,gln); return 1.0-gammcf; } }
// compute incomplete gamma function double gammp(const double a, const double x) { if (x < 0 || a < 0) { return -1; } double chi; if (x < (a + 1.0)) chi = 1.0 - gser(a, x); else chi = gcf(a, x); return chi; }
void gammp (double *a, double *x, double *res) { if (*x < 0.0 || *a <= 0.0) { output("Invalid arguments in routine gammp\n"); error=1; return; } if (*x < (*a+1.0)) { *res=gser(*a,*x); return; } else { *res=gamm(*a)-gcf(*a,*x); return; } }
Scalar gammq(Scalar a, Scalar x) { Scalar gamser,gammcf,gln; // void gcf(),gser(),nrerror(); // if (x < 0.0 || a <= 0.0) nrerror("Invalid arguments in routine GAMMQ"); if (x < (a+1.0)) { gser(&gamser,a,x,&gln); return 1.0-gamser; } else { gcf(&gammcf,a,x,&gln); return gammcf; } }
/** * Returns the incomplete gamma function P(a,x) * * "Numerical Recipes in C", Section 6.2 */ double gammap( const double x, const double a ) { double gam,gln; if (x < 0.0 || a <= 0.0){ printf("Incomplete Gamma Calculated with: x:%f and a:%f\n",x,a); failwith("Invalid argument for incomplete gamma"); } if ( x < (a+1.0)) { gser(&gam,a,x,&gln); } else { gcf (&gam,a,x,&gln); //inverse of continued fraction representation gam = 1.0 - gam; } return gam; }
double gammq(double a, double x) { void gcf(double *gammcf, double a, double x, double *gln); void gser(double *gamser, double a, double x, double *gln); double gamser,gammcf,gln; if (x < 0.0 || a <= 0.0) my_error("Invalid arguments in routine gammq"); if (x < (a+1.0)) { gser(&gamser,a,x,&gln); return 1.0-gamser; } else { gcf(&gammcf,a,x,&gln); return gammcf; } }
double gammaCDF(double a, double x) { double gln, p; if (x <= 0.0 || a <= 0.0) return 0.0; else if (a > LARGE_A) return gnorm(a, x); else { gln = lngamma(a); if (x < (a + 1.0)) return gser(a, x, gln); else return (1.0 - gcf(a, x, gln)); } }
double gammq ( double a, double x ) { double gammser, gammcf, gln; if (x < 0.0 || a <= 0.0) error("Invalid arguments in routine gammq"); if (x < (a + 1.0)) { gser (&gammser, a, x, &gln); // use the series representation return (1.0 - gammser); // and take its complement } else { gcf ( &gammcf, a, x, &gln); // use the continued fraction representation return gammcf; } }
//gammq ---- returns the incomplete gamma function Q(a,x) = 1 - P(a,x). float Test::gammq(float a, float x) { float gamser, gammcf, gln; //cout <<"a " << a<< " x "<<x<<endl; if (x < 0.0 || a <= 0.0) { nerror("Invalid arguments in routine gammq"); } if (x < (a + 1.0)) { //use the series representation gser(&gamser, a, x, &gln); return 1.0 - gamser; //and take its complement } else { gcf(&gammcf, a, x, &gln); //use the continued fraction representation return gammcf; } }
// Function: gammq(a,x) // REAL_TYPE gammq(REAL_TYPE a, REAL_TYPE x) { REAL_TYPE gamser, gammcf, gln; if((x<0.0||a<=0.0)) throw(std::invalid_argument(std::string("gammp():x must be >= 0 and a must be > 0"))); if(x<(a+1.0)) { gser(&gamser,a,x,&gln); return 1.0-gamser; } else { gcf(&gammcf,a,x,&gln); return gammcf; } }
float gammq(float a, float x) { void gcf(float *gammcf, float a, float x, float *gln); void gser(float *gamser, float a, float x, float *gln); void nrerror(char error_text[]); float gamser,gammcf,gln; if (x < 0.0 || a <= 0.0) nrerror("Invalid arguments in routine gammq"); if (x < (a+1.0)) { gser(&gamser,a,x,&gln); return 1.0-gamser; } else { gcf(&gammcf,a,x,&gln); return gammcf; } }
double gammp(double a, double x) // Returns normalised lower incomplete gamma function { void gcf(double *gammcf,double a, double x, double *gln); void gser(double *gamser, double a, double x, double *gln); double gamser,gammcf,gln; if(x<0) DEBUG << "Error: Argument of incomplete gamma function <= 0" << endl; if(x< (a+1.0E0)) { gser(&gamser,a,x,&gln); return gamser; } else{ gcf(&gammcf, a, x, &gln); return (1.0E0-gammcf); } }
REAL_TYPE gammp(REAL_TYPE a, REAL_TYPE x) { REAL_TYPE gamser, gammcf, gln; assert(!(x<0.0||a<=0.0)); // Invalid arguments if(x<(a+1.0)) { gser(&gamser,a,x,&gln); return gamser; } else { gcf(&gammcf,a,x,&gln); return 1.0-gammcf; } }
double gammp(double a, double x) { /* void gcf(double *gammcf, double a, double x, double *gln); void gser(double *gamser, double a, double x, double *gln); void nrerror(char error_text[]); */ double gamser,gammcf,gln; if (x < 0.0 || a <= 0.0) nrerror("Invalid arguments in routine gammp"); if (x < (a+1.0)) { gser(&gamser,a,x,&gln); return gamser; } else { gcf(&gammcf,a,x,&gln); return 1.0-gammcf; } }
//Returns the incomplete gamma function P (a, x). double gammp(double a, double x) { int gcf(double *gammcf, double a, double x, double *gln); int gser(double *gamser, double a, double x, double *gln); double gamser,gammcf,gln; if (x < 0.0 || a <= 0.0) { fprintf (stderr, "Invalid arguments in routine gammp (x=%5.1lf, a=%5.1lf).\n", x, a); exit (1); } if (x < (a+1.0)) { // Use the series representation. gser(&gamser,a,x,&gln); return gamser; } else { // Use the continued fraction representation gcf(&gammcf,a,x,&gln); return 1.0-gammcf; //and take its complement. } }
double vpRobust::gammp(double a, double x) { double gamser=0.,gammcf=0.,gln; if (x < 0.0 || a <= 0.0) std::cout << "Invalid arguments in routine GAMMP"; if (x < (a+1.0)) { gser(&gamser,a,x,&gln); return gamser; } else { gcf(&gammcf,a,x,&gln); return 1.0-gammcf; } }
double gammp(const double a, double x) { static const int ASWITCH = 100; if(x < 0.0 || a <= 0.0) { std::cout << "Bad value in Fgamma!"; return 0.0; } if(x == 0.0) { return 0.0; } else if(a >= ASWITCH) { return gammpapprox(a,x,1); /* use quadrature */ } else if(x < a + 1.0) { return gser(a,x); /* use the series expansion */ } else { return 1.0 - gcf(a,x); /* use the continued fraction expansion */ } }
double gammp( double a, double x ) { // x = chisquare, a = df/2 if( x < 0.0 || a <= 0.0 ) { printf( "error: invalid arguments in routine gammp" ); exit( 1 ); } if( x < ( a + 1.0 ) ) { gser( a, x ); return( gamser ); } else { gcf( a, x ); return( 1.0 - gammcf ); } // returns the incomplete gamma function P(a,x); }