June 2015
Beginner
348 pages
8h 44m
English
We will initialize t just like in the previous section. Again, k = 99 should be sufficient. In order to draw sawtooth and triangle waves, follow these steps:
zero:t = np.linspace(-np.pi, np.pi, 201) k = np.arange(1, 99) f = np.zeros_like(t)
sin() and sum() functions:for i, ti in enumerate(t): f[i] = np.sum(np.sin(2 * np.pi * k * ti)/k) f = (-2 / np.pi) * f
plt.plot(t, f, lw=1.0, label='Sawtooth') plt.plot(t, np.abs(f), '--', lw=2.0, label='Triangle') ...
Read now
Unlock full access