# A little math/PHP problem!

• Pbpixels
• Novice
• Joined: May 23, 2012
• Posts: 17
• Status: Offline

May 29th, 2012, 8:11 am

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!

• Anonymous
• Bot
• Joined: 25 Feb 2008
• Posts: ?
• Loc: Ozzuland
• Status: Online

May 29th, 2012, 8:11 am

• Zealous
• Guru
• Joined: Apr 15, 2011
• Posts: 1195
• Loc: Sydney
• Status: Offline

May 29th, 2012, 10:13 am

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
• Joined: May 23, 2012
• Posts: 17
• Status: Offline

May 29th, 2012, 10:37 am

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

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.