Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get y root of x in php for example 3 root of 8 is 2

Tags:

php

math

i want to get x root of y. just as 3 root of 8 is 2 is there any function in php to get this result.

sqrt function is getting square root of the given value. but i want n root of given value. is there another way to find it.

like image 485
Satish Sharma Avatar asked Jan 12 '13 05:01

Satish Sharma


3 Answers

You can use something like this

pow(8,1/3);

remember that rule ? :-)

like image 61
sjobe Avatar answered Sep 28 '22 06:09

sjobe


x = be

becomes:

ln x = e ln b
ln x / e = ln b
ln b = ln x / e
b = eln x / e

hence:

$b = exp(log($x) / $e);

Note that this will only give you one real root, if any exist. You'll need to perform math in the complex domain if you want all e roots.

like image 26
Ignacio Vazquez-Abrams Avatar answered Sep 28 '22 06:09

Ignacio Vazquez-Abrams


To get any root of a number your can use the pow() function:

pow(8, 1/3)

which gives you the third root of eight.

For reference check

http://php.net/manual/en/function.pow.php

like image 30
Deepu Avatar answered Sep 28 '22 04:09

Deepu