AGThePoet Posted March 26, 2004 Report Posted March 26, 2004 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 rootsOnly multiplying, dividing, adding, subtractingExponents 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
Wannabe Genius Posted April 2, 2004 Report Posted April 2, 2004 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.
AGThePoet Posted April 2, 2004 Author Report Posted April 2, 2004 $E = $_POST['E']; $P = $_POST['P']; $T = $_POST['T']; $X= ($E/$P); $Y = pow($T, $X); print $Y; just to put it in correct PHP syntax Ill go test it now
Wannabe Genius Posted April 2, 2004 Report Posted April 2, 2004 hmm I've got a funny feeling I've missed a step out. checking now
AGThePoet Posted April 2, 2004 Author Report Posted April 2, 2004 lol, okay, ill let you know what happens with the current code once ive finished testing
Wannabe Genius Posted April 2, 2004 Report Posted April 2, 2004 Ok, IF I'm right I've written this out backwards. I've written it as T^E/P and it SHOULD be E/P^1/T -- apologies. it IS 2:40am here in sunny England and its beena long day.
AGThePoet Posted April 2, 2004 Author Report Posted April 2, 2004 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
AGThePoet Posted April 2, 2004 Author Report Posted April 2, 2004 oh, btw, the result is here: http://members.lycos.co.uk/agthepoet/test/index3.html not sure how long i will keep it in that location but you can check it out quick
Wannabe Genius Posted April 2, 2004 Report Posted April 2, 2004 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.
AGThePoet Posted April 2, 2004 Author Report Posted April 2, 2004 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 itTime- amount of time in days the money coolects interestEnding- Amount of money it has at the end. THen it finds the interest % needed daily to get those results
Wannabe Genius Posted April 2, 2004 Report Posted April 2, 2004 I kinda figured that out after I saw the result. The main think is though, it works.
Recommended Posts