Next | Making Programs Faster | 124 |
Newton's method takes a guess and finds a better guess
The number of correct bits in the guess tends to double on each iteration
If the initial guess is good, the new guess is superb
If there were no correct bits to begin with, it wanders around aimlessly
The initial guess in the original code was terrible:
my $guess = Math::BigFloat->new( $num / $root );
For Root(500000, 555) this guesses that the root is 900.9009009
The root is actually 1.02392563097332211627
At x = 900.9, the curve y = x555 - 500000 is extremely steep
The tangent line is almost vertical (it has a slope of about 3.4e1639)
So the 'improved' guess is almost the same as the original guess
But twice as long!
Next | Copyright © 2003 M. J. Dominus |