使用牛顿拉夫森法求根

问题描述 投票:-1回答:1

我正在尝试使用牛顿拉弗森方法找到数字的第四根,并且在我的代码中遇到了这个奇怪的错误。谁能帮我解决这个问题?

谢谢

while abs(g**4-k)>=epsilon:
builtins.OverflowError: (34, 'Result too large')


def root():
epsilon = 0.01
k = 100
g = k/2.0
count = 1
while abs(g**4-k)>=epsilon:
    g = g-(((g**4)-k/(4*g**3)))
    count += 1
print("Approximate fourth root of", k, 'is about', g)
python newtons-method
1个回答
0
投票

while条件后的下一行中的括号有误(k后面的右括号)。参见下面的代码:

def root():
    epsilon = 0.01
    k = 100
    g = k/2.0
    count = 1
    while abs(g**4-k) >= epsilon:
        g = g-(((g**4)-k)/(4*g**3))
        count += 1
    print("Approximate fourth root of", k, 'is about', g)
© www.soinside.com 2019 - 2024. All rights reserved.