# Thread: math problem in php

1. ## math problem in php

Let's say I give an option to my user to input two number values, A and B. Then the form will use them to calculate Y.

For example
A = 2.5
B = 2.8

So the formula is

Y * 2.5 - 10,000 = 10,000 * 2.8 - Y / 2
2.5Y - 10,000 = 28,000 - Y / 2
2.5Y - 10,000 = 14,000 - 0.5Y
2.5Y + 0.5Y = 14,000 + 10,000
3Y = 24,000
Y = 8,000

the main question is.... how am I supposed to put that into php coding!

thanks in advance for any help!

2. Y*A - 10000 = (10000B -Y) / 2
Y*(A+0.5) = 5000(B + 2)
Y = 5000(B + 2)/(A + 0.5)

Just use that last formula to find Y. You can pretty much enter it as it is (you just need to replace Y, A and B with the appropriate variables).

EDIT: just saw Chris' post. My formula above is assuming you meant to have brackets so that it looks like this:
Y * 2.5 - 10,000 = (10,000 * 2.8 - Y) / 2
I deduced that from your steps in solving the equation.

3. I think you have an error in your calculation:

aY - 10,000 = 10,0000b - Y /2
aY + Y / 2 = 10,000 (b + 1)
Y(a + 0.5) = 10,000 (b + 1);
Y = 10,000 (b + 1) / (a + 0.5)

So the solution for this equation is always:

Y = 10,000 (b + 1) / (a + 0.5)

This makes it a lot easier to calculate the result in PHP

PHP Code:
\$a 2.5;
\$b 2.8;

function
solve(\$a\$b) {
return
10000 * (\$b 1) / (\$a 0.5);
}

echo
"Using \\$a = \$a and \\$b = \$b the result is: ".solve(\$a\$b);

NOOOO not again redemption was again faster than me

edit: In regards to redemption's post concerning missing brackets and website's suggestion for checking that a != 0.5 here is an updated version:

PHP Code:
\$a 2.5;
\$b 2.8;

function
solve(\$a\$b) {
if (
\$a == -0.5
return
'NaN';

return
5000 * (\$b 2) / (\$a 0.5)
}

echo
"Using \\$a = \$a and \\$b = \$b the result is: ".solve(\$a\$b);

4. but, hang on, you can't devide by number that may possible be 0, in this case, if a is set in to be -0,5 the script fails ...

5. Originally Posted by website
but, hang on, you can't devide by number that may possible be 0, in this case, if a is set in to be -0,5 the script fails ...
Well good point. It would make sense to validate any user input first, and make sure A isn't -0.5.

6. got it, thanks mates.. great help

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•