home *** CD-ROM | disk | FTP | other *** search
- stgama(m,x,df,cf)
-
- /*this subroutine computes the density function*/
- /**df = x**(m-1)*exp(-x)/(m-1)*(m-2)*...3*2*1*/
- /*and cumulative function for gamma distribution.*/
-
- int m;
- float x,*df,*cf;
-
- {
-
- extern double exp(),pow();
- float fm,c,fi,t,tm1,s,fs,ss,gs,gc;
- int m1,i;
-
- fm = m;
- gc = 1.;
- m1 = m - 1;
-
- for (i = 1; i <= m1; i++)
- {
- fi = i;
- gc = gc*fi;
- }
-
- t = x;
- tm1 = m1;
- s = pow(t,tm1) + gc;
- fs = 1.;
-
- for (i = 1; i <= m1-1; i++)
- {
- fi = i;
- fs = fs*(fm - fi);
- tm1 = m-i-1;
- s = s + pow(t,tm1)*fs;
- }
-
- ss = -exp(-t)*s;
- gs = ss + gc;
- *cf = gs/gc;
- *df = pow(t,(fm - 1.))/(exp(t)*gc);
-
- }