Advertisement
Guest User

convol poly

a guest
Oct 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. from numpy import linspace
  2. import matplotlib.pyplot as plt
  3. from matplotlib.animation import FuncAnimation
  4. from fractions import Fraction
  5.  
  6. W = [Fraction(1)]
  7. def W2p1(n):
  8.     global W
  9.     for i in range(len(W), n+1):
  10.         W.append(Fraction(2*i, 2*i+1)*W[i-1])
  11.     return W[n]
  12.  
  13. def phi(n, x): return (1-x**2)**n/2/W2p1(n).real
  14.  
  15. def init():
  16.     line.set_data([], [])
  17.     return line,
  18.  
  19. def animate(i):
  20.     line.set_data(pts, phi(i, pts))
  21.     return line,
  22. ##
  23. W2p1(600) # Pre-compute Wallis
  24. pts = linspace(-1, 1, 1000)
  25. line, = plt.plot([], [])
  26. plt.axis([-1, 1, -1, 15])
  27. plt.show()
  28.  
  29. ## Animation
  30. anim = FuncAnimation(plt.gcf(), animate, init_func=init, frames=600, interval=16, blit=True, repeat=False)
  31.  
  32. ## All together
  33. for i in range(1, 600): plt.plot(pts, phi(i, pts))
  34. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement