簡體   English   中英

Python:泰勒級數的計算誤差

[英]Python: Calculating Error of 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))

我需要以某種方式合並誤差函數來計算第k個導數,但我不確定該怎么做。 網站上的錯誤公式如下:

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

除非您知道其收斂的確切值,否則無法精確計算taylor序列中的誤差,而對於ln 1.9這樣的誤差,我們不會。 您引用的公式給出的誤差為數量c <z <x(假設c <x),在這種情況下,其范圍為0 <z <0.9,但否則未知。 這意味着我們無法使用此使用公式來查找確切的錯誤。 (否則,我們無法找到ln 1.9的確切值)

該公式的作用是限制錯誤。 如果看一下公式,您會發現它的形式與系列中的下一項相同,其中f ^(n + 1)的參數已從c(您要擴展的點)更改為z(我們的未知參數)。 換句話說,該誤差與該系列中的下一個術語的大小大致相同,或者如果您要擴展的參數較小,則該誤差至少會相同。

考慮到這一點,我可以通過簡單地計算系列中的下一項並說基本上就是這個來近似誤差。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM