牛顿法中的浮零除法误差

2024-04-25 02:17:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我的newtons方法的代码显示了被零除的错误。为什么我会得到这个?你知道吗

from math import * x = 2 for iteration in range(1,1001): N0 = .00003 NI =1000 b =.12 xnew = x - ((N0*exp((log1p(NI/N0))*(1-exp(-b*x))))-1)/(b*N0*exp((log1p(NI/N0))*(1-exp(-b*x))-b*x)) # the Newton-Raphson's formula if abs(xnew - x) < 0.000001: break x = xnew print('The root : %0.5f' % xnew) print('The number of iterations : %d' % iteration)

w型


Tags: the方法代码fromimport错误mathprint