diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/pmf/README.md b/lib/node_modules/@stdlib/stats/base/dists/binomial/pmf/README.md index b4725a5d5719..6118ecccf174 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/pmf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/pmf/README.md @@ -152,6 +152,114 @@ for ( i = 0; i < 10; i++ ) { + + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/binomial/pmf.h" +``` + +#### stdlib_base_dists_binomial_pmf( x, n, p ) + +Returns the [probability mass function][pmf] (PMF) for a [binomial][binomial-distribution] distribution with number of trials `n` and success probability `p`. + +```c +double out = stdlib_base_dists_binomial_pmf( 3.0, 20, 0.2 ); +// returns ~0.205 +``` + +The function accepts the following arguments: + +- **x**: `[in] int32_t` input value. +- **n**: `[in] int32_t` number of trials. +- **p**: `[in] double` success probability. + +```c +double stdlib_base_dists_binomial_pmf( const int32_t x, const int32_t n, const double p ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/binomial/pmf.h" +#include "stdlib/math/base/special/ceil.h" +#include +#include +#include + +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v * (max - min) ); +} + +int main( void ) { + int32_t n; + double p; + int32_t x; + double y; + int i; + + for ( i = 0; i < 25; i++ ) { + n = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) ); + p = random_uniform( 0.0, 1.0 ); + x = stdlib_base_ceil( random_uniform( 0.0, 50.0 ) ); + y = stdlib_base_dists_binomial_pmf( x, n, p ); + printf( "x: %d, n: %d, p: %lf, P(X=x;n,p): %lf\n", x, n, p, y ); + } + + return 0; +} +``` + +
+ + + +
+ + + + + +
+ +
+ + +