Python:计算泰勒级数的误差

时间:2015-08-28 21:39:48

标签: python numerical-integration taylor-series

我试图用以下代码计算泰勒系列的误差:

# 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))

我需要以某种方式合并计算kth导数的误差函数,并且我不知道如何做到这一点。错误公式可用at this website,如下所示:

$$R_n(x; c) = \dfrac{f^{(n+1)}(z)}{(n + 1)!} (x - c)^{n+1}.$$

1 个答案:

答案 0 :(得分:1)

除非你知道它正在收敛的确切值,否则无法准确计算泰勒系列中的错误,对于像1.9这样的东西,我们不会这样做。你引用的公式给出了数量c <误差的误差。 z&lt; x(假设c

这个公式的作用是对错误进行限制。如果你看一下公式,你会看到它与系列中的下一个术语具有相同的形式,其中f ^(n + 1)的参数从c,你正在扩展的点改为z,我们的未知参数。换句话说,它表示错误与系列中的下一个术语的大小大致相同,或者至少在您扩展的参数很小时会出现错误。

考虑到这一点,我会通过简单地计算系列中的下一个术语来表示错误,并说它基本上就是这样。