简体   繁体   English

PHP中的Erlang-B公式求和

[英]Erlang-B formula sumation in php

I've tried to port the following sum in a php for loop 我试图将以下总和移植到php for循环中 替代文字

this way: 这条路:

    $prod = 1;

for($i=0;$i<$_POST["capacity"];$i++){
$prod = $prod * (($_POST["capacity"] - (i+1)) / $toffered);
} 
    ?>
p(c) is:  <?php echo floatval(1.00/floatval((1+ floatval($prod)))); ?><br /> <br />

but for some reason it seems to give me the wrong result. 但由于某种原因,这似乎给了我错误的结果。 Any hints on what is wrong? 关于什么是错的任何提示?

EDIT : i've modified the initial value of prod as well as adding brackets for i+1 which is subtracted from the capacity. 编辑 :我已经修改了prod的初始值,并为从容量中减去的i + 1添加了括号。 The results aren't better still. 结果仍然不是更好。

I think you are actually not doing the sum, only the product part (the dots ...). 我认为您实际上不是在做总和,而只是做乘积部分(点...)。

If I'm not mistaken, you'll need 2 nested loops here, one for i = 1 to c (computing the sum), and one for 1 to i (computing the product). 如果我没记错的话,这里需要两个嵌套循环,一个用于i = 1至c(计算总和),另一个用于1至i(计算乘积)。

$prod = 0.0;

for($i=1;$i<$capacity;$i++){
$prod = (1.0 + $prod) * (floatval($i) / $toffered);
}
?>

p(c) is:  <?php echo (1.0 / ( 1.0 + $prod)); ?> %

works! 作品!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM