home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-SSP.ARJ / STGAMA.C < prev    next >
Encoding:
Text File  |  1984-08-03  |  838 b   |  45 lines

  1.       stgama(m,x,df,cf)
  2.  
  3.       /*this subroutine computes the density function*/
  4.       /**df = x**(m-1)*exp(-x)/(m-1)*(m-2)*...3*2*1*/
  5.       /*and cumulative function for gamma distribution.*/
  6.  
  7.       int m;
  8.       float x,*df,*cf;
  9.  
  10.      {
  11.  
  12.       extern double exp(),pow();
  13.       float fm,c,fi,t,tm1,s,fs,ss,gs,gc;
  14.       int m1,i;
  15.  
  16.       fm = m;
  17.       gc = 1.;
  18.       m1 = m - 1;
  19.  
  20.       for (i = 1; i <= m1; i++)
  21.       {
  22.         fi = i;
  23.         gc = gc*fi;
  24.       }
  25.  
  26.       t = x;
  27.       tm1 = m1;
  28.       s = pow(t,tm1) + gc;
  29.       fs = 1.;
  30.  
  31.       for (i = 1; i <= m1-1; i++)
  32.       {
  33.         fi = i;
  34.         fs = fs*(fm - fi);
  35.         tm1 = m-i-1;
  36.         s = s + pow(t,tm1)*fs;
  37.       }
  38.  
  39.       ss = -exp(-t)*s;
  40.       gs = ss + gc;
  41.       *cf = gs/gc;
  42.       *df = pow(t,(fm - 1.))/(exp(t)*gc);
  43.  
  44.      }
  45.