home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / math / cephes / cprob / nbdtr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-17  |  2.1 KB  |  135 lines

  1. /*                            nbdtr.c
  2.  *
  3.  *    Negative binomial distribution
  4.  *
  5.  *
  6.  *
  7.  * SYNOPSIS:
  8.  *
  9.  * int k, n;
  10.  * double p, y, nbdtr();
  11.  *
  12.  * y = nbdtr( k, n, p );
  13.  *
  14.  *
  15.  *
  16.  * DESCRIPTION:
  17.  *
  18.  * Returns the sum of the terms 0 through k of the negative
  19.  * binomial distribution:
  20.  *
  21.  *   k
  22.  *   --  ( n+j-1 )   n      j
  23.  *   >   (       )  p  (1-p)
  24.  *   --  (   j   )
  25.  *  j=0
  26.  *
  27.  * In a sequence of Bernoulli trials, this is the probability
  28.  * that k or fewer failures precede the nth success.
  29.  *
  30.  * The terms are not computed individually; instead the incomplete
  31.  * beta integral is employed, according to the formula
  32.  *
  33.  * y = nbdtr( k, n, p ) = incbet( n, k+1, p ).
  34.  *
  35.  * The arguments must be positive, with p ranging from 0 to 1.
  36.  *
  37.  *
  38.  *
  39.  * ACCURACY:
  40.  *
  41.  * See incbet.c.
  42.  *
  43.  */
  44. /*                            nbdtrc.c
  45.  *
  46.  *    Complemented negative binomial distribution
  47.  *
  48.  *
  49.  *
  50.  * SYNOPSIS:
  51.  *
  52.  * int k, n;
  53.  * double p, y, nbdtrc();
  54.  *
  55.  * y = nbdtrc( k, n, p );
  56.  *
  57.  *
  58.  *
  59.  * DESCRIPTION:
  60.  *
  61.  * Returns the sum of the terms k+1 to infinity of the negative
  62.  * binomial distribution:
  63.  *
  64.  *   inf
  65.  *   --  ( n+j-1 )   n      j
  66.  *   >   (       )  p  (1-p)
  67.  *   --  (   j   )
  68.  *  j=k+1
  69.  *
  70.  * The terms are not computed individually; instead the incomplete
  71.  * beta integral is employed, according to the formula
  72.  *
  73.  * y = nbdtrc( k, n, p ) = incbet( k+1, n, 1-p ).
  74.  *
  75.  * The arguments must be positive, with p ranging from 0 to 1.
  76.  *
  77.  *
  78.  *
  79.  * ACCURACY:
  80.  *
  81.  * See incbet.c.
  82.  *
  83.  */
  84.  
  85. /*
  86. Cephes Math Library Release 2.0:  April, 1987
  87. Copyright 1984, 1987 by Stephen L. Moshier
  88. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  89. */
  90.  
  91. #include "mconf.h"
  92.  
  93. double nbdtrc( k, n, p )
  94. int k, n;
  95. double p;
  96. {
  97. double dk, dn;
  98. double incbet();
  99.  
  100. if( (p < 0.0) || (p > 1.0) )
  101.     goto domerr;
  102. if( k < 0 )
  103.     {
  104. domerr:
  105.     mtherr( "nbdtr", DOMAIN );
  106.     return( 0.0 );
  107.     }
  108.  
  109. dk = k+1;
  110. dn = n;
  111. return( incbet( dk, dn, 1.0 - p ) );
  112. }
  113.  
  114.  
  115.  
  116. double nbdtr( k, n, p )
  117. int k, n;
  118. double p;
  119. {
  120. double dk, dn;
  121. double incbet();
  122.  
  123. if( (p < 0.0) || (p > 1.0) )
  124.     goto domerr;
  125. if( k < 0 )
  126.     {
  127. domerr:
  128.     mtherr( "nbdtr", DOMAIN );
  129.     return( 0.0 );
  130.     }
  131. dk = k+1;
  132. dn = n;
  133. return( incbet( dn, dk, p ) );
  134. }
  135.