import numpy as np
def fun(x):
return x**3-2*x-5
def dfun(x):
return 3*x*x-2
def newton(fun,dfun,a,b,eps):
err = 1
x = b
c = dfun(x)
k = 0
while err > eps:
x = x - fun(x)/c
err = fun(x)
k = k+1
print('简化牛顿法的迭代次数为{:d}次'.format(k))
return x
x = newton(fun, dfun, 0, 10, 0.0000001)
print('简化牛顿迭代法的求解结果为{:.7}'.format(x))
x1 = np.linspace(-10, 10, 1000)
y1 = fun(x1)
简化牛顿法求解非线性方程
最新推荐文章于 2022-05-06 11:52:31 发布