뉴턴의 방법

1128 days 전, jhlee2chn 작성

f(x) = x^3 - 2*x -5 df(x) = diff(f(x),x) x0 = 2.0 d = f(x0)/df(x0) print "x = ", x0, "f(x) = ", f(x0) while abs(d) > 1e-8: x0 = x0 - d print "x = ", x0, "f(x) = ", f(x0) d = f(x0)/df(x0) 
       
x =  2.00000000000000 f(x) =  -1.00000000000000
x =  2.10000000000000 f(x) =  0.0610000000000017
x =  2.09456812110419 f(x) =  0.000185723173270702
x =  2.09455148169820 f(x) =  1.73976211215177e-9
x =  2.00000000000000 f(x) =  -1.00000000000000
x =  2.10000000000000 f(x) =  0.0610000000000017
x =  2.09456812110419 f(x) =  0.000185723173270702
x =  2.09455148169820 f(x) =  1.73976211215177e-9