Jump to content

[SOLVED] Convert cube root function into PHP


chrischen

Recommended Posts

Hi I need to write a PHP function for this equation:

 

[ ((2/3)(x-50))^(1/3) ] + 4

 

The problem is that PHP converts the 1/3 to a decimal or something, but I need it to take the cube root. Right now with that equation above in PHP any X value under 50 produces a nonreal answer and thus NaN as a result. The equation works fine on my Ti-84.

 

So basically I need to figure out how to take cube roots in PHP.

For some reason if you try to cube root -16 it breaks...

 

So I changed $x to equal 3 instead of two. All number from -99 to 99 have been tested.

 

function cube( $c ) {

$x = 3;

 

do {

$x = $x - (pow($x,3) - $c)/(3*pow($x,2));

 

$count++;

} while($count < 50);

return $x;

 

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.