Next | Tricks of the Wizards | 162 |
sub how_long { my ($P, $i, $F) = @_; my $g = 1; # Initial guess my $d = 1; until ($d/$g < 0.000001) { $d = ($P * (1+$i)**$g - $F) / ($P * (1+$i)**$g * log(1+$i)); $g -= $d; } return $g; }
Example: how_long(10000, 0.065, 1000000) is 73.1271913100701
$10,000 invested at 6.5% interest becomes $1,000,000 after 73.12 years
Next | Copyright © 2003 M. J. Dominus |