Next | Tricks of the Wizards | 160 |
Suppose you want to solve f(x) = N
Step 1: Compute the derivative d(x)
Or get the math expert down the hall to do it
Then the answer is:
sub solve { my ($N) = @_; my $g = 1; # Substitute a reasonable guess here until (the guess is good enough) { $g -= (f($g) - $N) / d($g); } return $g; }
Warnings:
Initial guess must be reasonable
Method doesn't always work
Next | Copyright © 2003 M. J. Dominus |