Unexpected Output From Newton's Method
I have this code for solving Newton's method and in the last iteration, the output values have come wrong. Those values should not be negative as I checked it manually on paper. As
Solution 1:
Ah, I see now.
Just as you say,
float(poly_substitute(poly, x))
evaluates to -0.015
. Then,
float(poly_substitute(poly_diff, x))
evaluates to -0.01
. Thus, substituting for these values and for x
,
x_n = 0.5 - ( (-0.015) / (-0.01) )
x_n = 0.5 - 0.6666666...
x_n = -0.166666...
Your manual math was what was at fault, not the code.
Solution 2:
The polynomial as given has a single solution at x = 0. The code is working fine.
Post a Comment for "Unexpected Output From Newton's Method"