Im creating a website with math functions but not the simple stuff. I'm not starting anything until I can get somethign confirmed. Is it possible in PHP to create a script to calculate lets say (x+y)^2

# Math in PHP??

Started by jeremic, Oct 24 2006 11:12 PM

5 replies to this topic

### #1

Posted 24 October 2006 - 11:12 PM

### #3

Posted 25 October 2006 - 12:31 AM

Yes I have but what I'm trying to find out if a function can be created to raise arbitrary variables such as X and Y to powers as stated above. I know that you can raise a number to a power but can you raise a letter? and get a letter as an out put??

(x + y)^3 = x^3 + 3x^2y + 3xy^2 + y^3

(x + y)^3 = x^3 + 3x^2y + 3xy^2 + y^3

### #4

Posted 25 October 2006 - 12:41 AM

NO you can't "raise a

$x = 2;

$y = 4;

$a = $y + $x; //$a will equal 6

$a = $y * $x; //$a will equal 8

$a = pow($x, 2); //$a will equal 4 -> (2 squared)

$a = pow($y, -2); //$a will equal 2 -> (square root of 4)

**letter**". But a raise a**variable**--YES.$x = 2;

$y = 4;

$a = $y + $x; //$a will equal 6

$a = $y * $x; //$a will equal 8

$a = pow($x, 2); //$a will equal 4 -> (2 squared)

$a = pow($y, -2); //$a will equal 2 -> (square root of 4)

Don

### #5

Posted 25 October 2006 - 06:35 AM

$a = pow($y, -2); //$a will equal 0.0625 -> (1 / 4^2)

$a = pow($y, 1/2); //$a will equal 2 -> (square root of 4)

$a = pow($y, 1/2); //$a will equal 2 -> (square root of 4)

*If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.*

Donations gratefully received

|baaGrid| easy data tables - and more |baaChart| easy line, column and pie charts |

### #6

Posted 25 October 2006 - 07:29 AM

Basially, he wants a function that can do his Algebra homework.

He's not asking us to do any calcuating that will output a numeric value - just factoring Algebric expression.

Like, inputting "(x-y)^2" in the textbox will output "x^2 -xy -xy + y^2" or "x^2 -2xy + y^2" (simpfiled).

Inputting "(x + y)^3" will output "x^3 + 3x^2y + 3xy^2 + y^3"

If that's the case, seems complicated...

He's not asking us to do any calcuating that will output a numeric value - just factoring Algebric expression.

Like, inputting "(x-y)^2" in the textbox will output "x^2 -xy -xy + y^2" or "x^2 -2xy + y^2" (simpfiled).

Inputting "(x + y)^3" will output "x^3 + 3x^2y + 3xy^2 + y^3"

If that's the case, seems complicated...

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users