我正在尝试使用以下代码计算泰勒级数的误差:
# Define initial values, including appropriate value of x for the series input
import numpy as np
x = -0.9
i = 1
taySum = 0
ln = np.log(1.9)
terms = 1
''' Iterate through the series while checking that
the difference between the obtained series value and ln(1.9)
exceeds 10 digits of accuracy. Stop iterating once the series
value is within 10 digit accuracy of ln(1.9).'''
while (abs(taySum - ln) > 0.5e-10) == True:
taySum += (-1) * (pow(x,i))/(i)
i += 1
terms += 1
print ('value: {}, terms: {}'.format(taySum, terms))
我需要以某种方式合并计算第 k 个导数的误差函数,但我不知道该怎么做。错误公式可在此网站上找到,如下所示: