예제 #1
0
// **************************************************************
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;
}
예제 #3
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);
}
예제 #4
0
/**
   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);
}
예제 #6
0
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;
	}
}
예제 #7
0
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);
}
예제 #9
0
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;
	}
}
예제 #10
0
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;
}
예제 #11
0
파일: gammp.cpp 프로젝트: HunterAllman/kod
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;
	}
}
예제 #12
0
// 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;
}
예제 #13
0
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;
	}
}
예제 #14
0
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;
	}
}
예제 #15
0
파일: gamma.c 프로젝트: amnh/poy5
/** 
 * 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;
}
예제 #16
0
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;
	}
}
예제 #17
0
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));
	}
}
예제 #18
0
파일: MathStats.cpp 프로젝트: zhanxw/mycode
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;
      }
   }
예제 #19
0
파일: Test.cpp 프로젝트: stites/CSSR
//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;
        }
    }
예제 #21
0
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;
	}
}
예제 #22
0
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;
        }
    }
예제 #24
0
파일: tools.c 프로젝트: tracy107/v1
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;
  }
}
예제 #25
0
//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.
    }
}
예제 #26
0
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;
  }
}
예제 #27
0
파일: gamma.cpp 프로젝트: LijieTu/hfcxx
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 */
	}
}
예제 #28
0
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);
}