Dirichlet Kernels
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
def DK(N,x):
if x == 0:
return (1 + N * 2)/(2 * np.pi)
else:
return np.sin((N+1/2)*x)/(np.sin(x/2) * 2*np.pi)
fig, ax = plt.subplots(figsize=(10,10))
def animation(n):
xs = np.linspace(-np.pi,np.pi,100 + n**2)
ax.clear()
plt.grid()
ax.spines['left'].set_position(('data', 0.0))
ax.spines['bottom'].set_position(('data', 0.0))
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.set_ylim([-2, 14])
ax.set_xlim([-np.pi, np.pi])
ax.plot(xs,list(map(lambda x:DK(n,x),xs)))
plt.title('N={}'.format(n))
ani = FuncAnimation(fig, animation, repeat=True,
frames=50, interval=50)
ani.save(filename="plot.gif", writer="pillow")
"""
from IPython.display import HTML
HTML(ani.to_jshtml())
"""