Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // if GMP extension is not enabled
- // we must create a gmp_fact function
- if(!function_exists('gmp_fact')) {
- function gmp_fact($x) {
- $result = 1;
- for($i = $x; $i > 1; $i--) {
- $result *= $x;
- $x--;
- }
- return $result;
- }
- }
- $varn = 5;
- $varx = 1;
- $varp = 0.15;
- $varq = 0.85;
- // calculate n combination of x
- $comb = gmp_fact($varn)/(gmp_fact($varx)*gmp_fact($varn-$varx));
- // calculate probability
- $prob = $comb*pow($varp, $varx)*pow($varq, $varn-$varx);
- // result
- echo $prob;
Add Comment
Please, Sign In to add comment