Next Tricks of the Wizards 160

Solve Any Equation With Newton-Raphson

        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;
        }


Next Copyright © 2003 M. J. Dominus