source: sasview/sansmodels/src/cephes/nbdtr.c @ 5cfa884

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 5cfa884 was 431c9e0, checked in by ajj, 12 years ago

Adding parts of cephes math library to provide bessel functions on all platforms.

  • Property mode set to 100644
File size: 3.3 KB
Line 
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 * DESCRIPTION:
15 *
16 * Returns the sum of the terms 0 through k of the negative
17 * binomial distribution:
18 *
19 *   k
20 *   --  ( n+j-1 )   n      j
21 *   >   (       )  p  (1-p)
22 *   --  (   j   )
23 *  j=0
24 *
25 * In a sequence of Bernoulli trials, this is the probability
26 * that k or fewer failures precede the nth success.
27 *
28 * The terms are not computed individually; instead the incomplete
29 * beta integral is employed, according to the formula
30 *
31 * y = nbdtr( k, n, p ) = incbet( n, k+1, p ).
32 *
33 * The arguments must be positive, with p ranging from 0 to 1.
34 *
35 * ACCURACY:
36 *
37 * Tested at random points (a,b,p), with p between 0 and 1.
38 *
39 *               a,b                     Relative error:
40 * arithmetic  domain     # trials      peak         rms
41 *    IEEE     0,100       100000      1.7e-13     8.8e-15
42 * See also incbet.c.
43 *
44 */
45/*                                                     nbdtr.c
46 *
47 *      Complemented negative binomial distribution
48 *
49 *
50 *
51 * SYNOPSIS:
52 *
53 * int k, n;
54 * double p, y, nbdtrc();
55 *
56 * y = nbdtrc( k, n, p );
57 *
58 * DESCRIPTION:
59 *
60 * Returns the sum of the terms k+1 to infinity of the negative
61 * binomial distribution:
62 *
63 *   inf
64 *   --  ( n+j-1 )   n      j
65 *   >   (       )  p  (1-p)
66 *   --  (   j   )
67 *  j=k+1
68 *
69 * The terms are not computed individually; instead the incomplete
70 * beta integral is employed, according to the formula
71 *
72 * y = nbdtrc( k, n, p ) = incbet( k+1, n, 1-p ).
73 *
74 * The arguments must be positive, with p ranging from 0 to 1.
75 *
76 * ACCURACY:
77 *
78 * Tested at random points (a,b,p), with p between 0 and 1.
79 *
80 *               a,b                     Relative error:
81 * arithmetic  domain     # trials      peak         rms
82 *    IEEE     0,100       100000      1.7e-13     8.8e-15
83 * See also incbet.c.
84 */
85/*                                                     nbdtr.c
86 *
87 *      Functional inverse of negative binomial distribution
88 *
89 *
90 *
91 * SYNOPSIS:
92 *
93 * int k, n;
94 * double p, y, nbdtri();
95 *
96 * p = nbdtri( k, n, y );
97 *
98 * DESCRIPTION:
99 *
100 * Finds the argument p such that nbdtr(k,n,p) is equal to y.
101 *
102 * ACCURACY:
103 *
104 * Tested at random points (a,b,y), with y between 0 and 1.
105 *
106 *               a,b                     Relative error:
107 * arithmetic  domain     # trials      peak         rms
108 *    IEEE     0,100       100000      1.5e-14     8.5e-16
109 * See also incbi.c.
110 */
111
112/*
113Cephes Math Library Release 2.8:  June, 2000
114Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
115*/
116
117#include "mconf.h"
118#ifdef ANSIPROT
119extern double incbet ( double, double, double );
120extern double incbi ( double, double, double );
121#else
122double incbet(), incbi();
123#endif
124
125double nbdtrc( k, n, p )
126int k, n;
127double p;
128{
129double dk, dn;
130
131if( (p < 0.0) || (p > 1.0) )
132        goto domerr;
133if( k < 0 )
134        {
135domerr:
136        mtherr( "nbdtr", DOMAIN );
137        return( 0.0 );
138        }
139
140dk = k+1;
141dn = n;
142return( incbet( dk, dn, 1.0 - p ) );
143}
144
145
146
147double nbdtr( k, n, p )
148int k, n;
149double p;
150{
151double dk, dn;
152
153if( (p < 0.0) || (p > 1.0) )
154        goto domerr;
155if( k < 0 )
156        {
157domerr:
158        mtherr( "nbdtr", DOMAIN );
159        return( 0.0 );
160        }
161dk = k+1;
162dn = n;
163return( incbet( dn, dk, p ) );
164}
165
166
167
168double nbdtri( k, n, p )
169int k, n;
170double p;
171{
172double dk, dn, w;
173
174if( (p < 0.0) || (p > 1.0) )
175        goto domerr;
176if( k < 0 )
177        {
178domerr:
179        mtherr( "nbdtri", DOMAIN );
180        return( 0.0 );
181        }
182dk = k+1;
183dn = n;
184w = incbi( dn, dk, p );
185return( w );
186}
Note: See TracBrowser for help on using the repository browser.