Advertisement
am1x

zetam002.py

Aug 14th, 2022
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | Source Code | 0 0
  1. import math
  2.  
  3.  
  4. #calculates (x+1)^a - x^a
  5. def df(x, a):
  6.     lm = 0.5 * a * math.log(x * (x + 1.0))
  7.     ld = 0.5 * a * math.log1p(1.0 / x)
  8.     return 2 * math.exp(lm) * math.sinh(ld)
  9.  
  10.  
  11. def zetam(a, n):
  12.     a += 0.0
  13.     assert a != -1
  14.  
  15.     l = []
  16.     for i in range(n):
  17.         l.append(df(2 * i + 1.0, a))
  18.     l.append(-0.5 * (2 * n + 1.0) ** a)
  19.  
  20.     q = 20
  21.     l1 = [0.25 * ((-1) ** i) * df(2 * n + i + 1.0, a) for i in range(q)]
  22.     for i in range(q):
  23.         l.append(l1[0])
  24.         for j in range(q - i - 1):
  25.             l1[j] = 0.5 * (l1[j] + l1[j + 1])
  26.  
  27.     return math.fsum(l) / df(1.0, a + 1.0)
  28.  
  29. zetam_vs = {
  30.     2.5 : 0.00851692877785033054,
  31.     2.0 : 0,
  32.     0.5 : -0.207886224977354566,
  33.     0.0 : -0.5,
  34.     -0.5 : -1.4603545088095868,
  35.     -2.0 : math.pi ** 2 / 6
  36. }
  37.  
  38.  
  39. a = -2.0
  40. n = 6
  41. q = 20
  42.  
  43. print("a =", a, ", n =", n, ", q =", q)
  44. r0 = zetam(a, n)
  45. rd = zetam_vs.get(a, 0.0)
  46.  
  47. print("{:.30f}".format(r0), r0 - rd)
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement