Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from numpy import linspace
- import matplotlib.pyplot as plt
- from matplotlib.animation import FuncAnimation
- from fractions import Fraction
- W = [Fraction(1)]
- def W2p1(n):
- global W
- for i in range(len(W), n+1):
- W.append(Fraction(2*i, 2*i+1)*W[i-1])
- return W[n]
- def phi(n, x): return (1-x**2)**n/2/W2p1(n).real
- def init():
- line.set_data([], [])
- return line,
- def animate(i):
- line.set_data(pts, phi(i, pts))
- return line,
- ##
- W2p1(600) # Pre-compute Wallis
- pts = linspace(-1, 1, 1000)
- line, = plt.plot([], [])
- plt.axis([-1, 1, -1, 15])
- plt.show()
- ## Animation
- anim = FuncAnimation(plt.gcf(), animate, init_func=init, frames=600, interval=16, blit=True, repeat=False)
- ## All together
- for i in range(1, 600): plt.plot(pts, phi(i, pts))
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement