#! /usr/bin/env python
#-*-coding:utf8-*-
def shanks_once(series):
rslt = list()
for i in range(1, len(series)-1):
nm1, n, np1 = series[i-1], series[i], series[i+1]
item = (nm1*np1 - n**2) / (nm1 + np1 - 2*n)
rslt.append(item)
return rslt
def shanks(series, n):
rslt = series
for i in range(n):
rslt = shanks_once(rslt)
return rslt
def sum_series(series):
rslt, item = list(), 0
for i in series:
item += i
rslt.append(item)
return rslt
if __name__ == "__main__":
s = [
4, -4/3, 4/5, -4/7, 4/9, -4/11, 4/13,
-4/15, 4/17, -4/19, 4/21, -4/23, 4/25,
]
s0 = sum_series(s)
i0 = len(s0)-1
print("%.8f" % s0[i0])
s4 = shanks(s0, 4)
i4 = len(s4)-1
print("%.8f" % s4[i4])
香克斯变换求π
最新推荐文章于 2021-01-18 15:57:03 发布