Jump to content

Find value from the while loop


vivis933

Recommended Posts

<?php
function factorial($number)
{
if ($number < 2) {
return 1;
} else {
return ($number * factorial($number-1));
}
}

function poisson($occurrence,$chance)
{
$e = exp(1);

$a = pow($e, (-1 * $chance));
$b = pow($chance,$occurrence);
$c = factorial($occurrence);

return $a * $b / $c;
}

$x = 2.5;
$y = 1.5;
$calAll = array();
for($z = 0 ; $z <= 9 ; $z++) {
array_push($calAll,
(poisson($z,$x) * poisson(0,$y))*100,
(poisson($z,$x) * poisson(1,$y))*100,
(poisson($z,$x) * poisson(2,$y))*100


);
}
$value = max($calAll);
$key = array_search($value, $calAll);
print_r($calAll) . "\n";
echo "max =",$value , " key =",$key . "\n";;
?>

it is possible to find $z and the number 0,1 or 2 from the max of the returned array ?

I used excel to perform this action and i found that for max=8.5854557290941 the $z is 2 and number 1 how to achieve this in php ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.