Jump to content
Science Forums

Solving roots- Without rooting?


AGThePoet

Recommended Posts

Hi, im trying to solve a way to do an eqaution via PHP, and due to certain restrictions on it i cant just square/cube/whatever root it. Well, i can square root, but i need to do it with any level of root. The equation i need to know how to solve is:

 

PS not sure how the forum formats, this maybe wont turn out.

-----______________

--T/-----------E

---/--------------------

/--------------P

 

EDIT: sorry that looks horrible, i had to add the dashes or else it collpases the whole thing tot he side..

 

if it doesnt work., ill edit it and fix it after i post it.

 

 

So it the T root of (e divided by p)... anyways, here are the rules i need the solutions to follow:

 

No actual square/cube/whatever roots

Only multiplying, dividing, adding, subtracting

Exponents can be used, but only if its a single term or multiple terms multiplied together... meaning no (E + P) squared. No adding/subracting inside the exponent range. foiling would be extrememly difficult to follow with generic programming when T could be anything.,

 

Thanks for any and all help

 

Alex

Link to comment
Share on other sites

ok this is a reasonably easy one.

 

$t = 'T'; // Insert value for T

$x = E/P;

$y = pow($t, $x);

echo $y;

 

By raising T to the power of a fraction less than 1, you are therefore working out the square root.

 

I havent actually tried this example, but have written similar ones in both PHP and Python. You've probably seen it done before. In M$ Excel.

 

Whilst this does not follow most of your rules, the value of T is irrelevent as long as E/P always evaluates correctly. It is, however, generic to the point of accepting any root where a fraction can be determined.

Link to comment
Share on other sites

lol, i fixed it, is this how you did it?

 

<?php

$AT = $_POST['T'];

$E = $_POST['E'];

$P = $_POST['P'];

$T = $_POST['T'];

$T = (1/$T);

$X = ($E/$P);

$Y = pow($X, $T);

$Y--;

$Y = ($Y*100);

print "You inputted the following:";

echo "

";

print "Principle: $ $P";

echo "

";

print "Time: $AT days";

echo "

";

print "End Result: $ $E";

echo "

";

echo "

";

print "Interest: $Y %";

echo "

";

?>

 

 

ANyways, thanks for the help, i havent been able to get it to work until now

Link to comment
Share on other sites

pretty much. I've been using this for some pretty nasty fractions and it hasn't let me down (yet). That pow() function can be hellishly useful.

 

Sometimes even M$ has its uses. If only to learn functions for porting elsewhere.

 

I checked out your results page and it did seem to be working ok although I did get a bit confused as to what values I was inputting, but for a simple test it looked fine.

Link to comment
Share on other sites

yeah, its not "cosmetically" set yet, just PHP functional. ill make it look better later

 

basically, its a loan program, where you enter 3 things:

 

Principal- Amoutn of money you put it

Time- amount of time in days the money coolects interest

Ending- Amount of money it has at the end.

 

THen it finds the interest % needed daily to get those results

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...