1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import os import matplotlib.pyplot as plt import numpy as np os.chdir('/home/vg/Downloads/projects/ex7') os.getcwd() plt.figure(figsize=(10,8)) N = 2**8 t = np.linspace(0,1,N) y = np.zeros(N) for n in range(1,32,2): y = y + 4/(np.pi*n)*np.sin(2*np.pi*n*t*2) plt.plot(t,y) plt.axis([0,1,-1.4,1.4]) plt.grid() plt.xlabel('Time, sec') plt.ylabel('Value') plt.title('Fourier expansion of a rectangular wave') plt.savefig("example7.png", dpi=100) plt.show() plt.close() |
Recent Comments