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

  1.       stngbi (i,kk,p,df,cf)
  2.  
  3.       /*this subroutine computes the probability and cumulative*/
  4.       /*distribution of negative binomial distribution of the form*/
  5.       /*df(kk,i,p)=c(i+kk-1.,kk)*p**i*(1.-p)**kk for arbitrary fixed*/
  6.       /*integer i greater than zero and p in the interval 0 to 1.*/
  7.  
  8.       int i,kk;
  9.       float p,*df,*cf;
  10.  
  11.      {
  12.  
  13.       int j,k,l;
  14.       float ri,skk,s1,fj,t,s2,fl;
  15.       extern double pow();
  16.  
  17.       ri = i;
  18.       *cf = pow(p,ri);
  19.       *df = *cf;
  20.  
  21.       if (kk <= 0) return;
  22.  
  23.       for (k = 1; k <= kk; k++)
  24.       {
  25.         skk = k;
  26.         s1 = 1.;
  27.  
  28.         for (j = 1; j <= k; j++)
  29.         {
  30.           fj = j;
  31.           t = ri + skk - fj;
  32.           s1 = s1*t;
  33.         }
  34.         s2 = 1.;
  35.  
  36.         for (l = 1; l <= k; l++)
  37.         {
  38.           fl = l;
  39.           s2 = s2*fl;
  40.         }
  41.         *df = (s1/s2)*pow(p,ri)*pow((1.-p),skk);
  42.         *cf = *cf + *df;
  43.       }
  44.  
  45.      }
  46.