# A little math/PHP problem!

• Novice
• Posts: 17

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!

• Guru
• Posts: 1295
• Loc: Sydney

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.
• Novice
• Posts: 17

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 36 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