String to Variable converstion
| From: | Paul Cohen | Date: | Thu, 18 Jan 2001 00:13:47 +0000 |
| Subject: | String to Variable converstion | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-35220@lists.php.net to get a copy of this message | ||
Hello all,
I am trying to build an IRR calculator using PHP. The number of cash flow
streams I will have at any time will vary, so I am using a loop to build the
formula. Then I am iterating to solve the equation and output the solution.
As most of you know, I am solving the following for r:
0=SUM SERIES(CF(i)/{(1+r)^n))
I can build my formula sucessfully with the following;
$form="";
while ($row=mysql_fetch_array($result)){
$form.="$CF/pow((1+'$r'),$N)";
}
But it recognizes $form as a string, so when I put it in my "solution for r"
loop:
for($r=-1.00; $r<=1.00; $r=$r+.0001){
if($form>-.001 && $form < .001){
$IRR=round($r*100, 2);
}
}
echo "$IRR%<br>";
BTW, I have also tried building the $form as a variable, but since I don't
have a value for $r it just puts in zero and sets $form equal to the right
side of the equation. Therfore, instead of inserting a formula into my
"solution for r" loop, it inserts a constant for $form.
I think my solution is to build the formula as a string and then insert it
into my "solution for r" loop, convert it back to a real formula and then
iterate for the solution. Is this possible? If not, any suggestions?