A little math/PHP problem!

  • Pbpixels
  • Novice
  • Novice
  • User avatar
  • Posts: 17

Post 3+ Months Ago

Hello! Since i'm quite new at PHP and that I'm not the best in maths! It doesn't really fit good together!
I have this math:

K*p^r*(1-p)^(n-r)

and I need PHP to calculate it. What I have written so far is this:

PHP Code: [ Select ]
$result = $_POST['k']*($_POST['p']/$_POST['pp'])^$_POST['r']*(1-($_POST['p']/$_POST['pp']))^($_POST['n']-$_POST['r'])



n = 5
k = 10
p = 1
pp = 6
r = 2


Excel: 10*(1/6)^2*(5/6)^3 = 0,1608

Doesn't really work.. I have heard rumors about something called "row" that should be used instead of "^", but I can't quite figure out how.
If anybody could help me rewriting the math so that PHP understands it, it would be very appreciated!

Thanks in advance for your help :)
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Zealous
  • Guru
  • Guru
  • User avatar
  • Posts: 1244
  • Loc: Sydney

Post 3+ Months Ago

Code: [ Select ]
$n = 5;
$k = 10;
$p = 1;
$pp = 6;
$r = 2;
$t = 3;

$s = $k * ($p/$pp)^$r*($n/$pp)^$t;

echo $s;

output= 3
  1. $n = 5;
  2. $k = 10;
  3. $p = 1;
  4. $pp = 6;
  5. $r = 2;
  6. $t = 3;
  7. $s = $k * ($p/$pp)^$r*($n/$pp)^$t;
  8. echo $s;
  9. output= 3

don't think i got it, but this looks like fun.
  • Pbpixels
  • Novice
  • Novice
  • User avatar
  • Posts: 17

Post 3+ Months Ago

hahah! sure is fun! But you can't write the "^" inside php I believe. You have to use something with "pow" but I can't figure out how! Your idea is smart though! My output is 3 aswell without the "^"'s

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 147 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.