#include "CommonTools/Statistics/src/GammaSeries.h"
#include "CommonTools/Statistics/src/GammaLn.h"
#include <iostream>
#include <cmath>
Go to the source code of this file.
Defines | |
#define | EPS 3.0e-7 |
#define | ITMAX 100 |
Functions | |
float | GammaSeries (float a, float x) |
Returns the series summation of the series representation of the incomplete gamma function P(a,x). |
#define EPS 3.0e-7 |
Definition at line 7 of file GammaSeries.cc.
#define ITMAX 100 |
Definition at line 6 of file GammaSeries.cc.
float GammaSeries | ( | float | a, | |
float | x | |||
) |
Returns the series summation of the series representation of the incomplete gamma function P(a,x).
source: Numerical Recipes
Definition at line 9 of file GammaSeries.cc.
References TestMuL1L2Filter_cff::cerr, lat::endl(), EPS, index, ITMAX, and sum().
Referenced by IncompleteGammaComplement::ln(), and IncompleteGammaComplement::value().
00010 { 00011 if( x < 0.0 ) 00012 std::cerr << "GammaSeries::negative argument x" << std::endl; 00013 00014 if( x == 0. ) 00015 return 0.; 00016 00017 // coefficient c_n of x^n is Gamma(a)/Gamma(a+1+n), which leads to the 00018 // recurrence relation c_n = c_(n-1) / (a+n-1) with c_0 = 1/a 00019 double term = 1/a; 00020 double sum = term; 00021 double aplus = a; 00022 for( int index = 1; index <= ITMAX; index++) { 00023 ++aplus; 00024 term *= x/aplus; 00025 sum += term; 00026 if( fabs(term) < fabs(sum)*EPS ) 00027 // global coefficient e^-x * x^a / Gamma(a) 00028 return sum; 00029 } 00030 std::cerr << "GammaSeries::a too large, ITMAX too small" << std::endl; 00031 return 0.; 00032 }