Jupyter notebook Fourier Series.ipynb
import matplotlib.pyplot as plt from numpy import pi,sin,linspace,zeros,arange,cos from ipywidgets import interact %matplotlib inline
The fourier series for a square wave is
Let us explore how this summation converges
def square_wave(N = 1,L = 5,num_points = 200): x = linspace(-4*pi,4*pi,num_points) y = zeros(num_points) for n in arange(1,N+1,2): y = y + (1.0/n * sin(n*pi*x/L)) y = y * 4.0/pi plt.plot(x,y)
square_wave(N=5,L=5)
An interactive version of the above:
interact(square_wave,N=(1,50,2),L=5,points=200)