#!/usr/bin/env python # coding: utf-8 # In[7]: get_ipython().run_line_magic('matplotlib', 'inline') import matplotlib.pyplot as plt import numpy as np import scipy # Graphing helper function def setup_graph(title='', x_label='', y_label='', fig_size=None): fig = plt.figure() if fig_size != None: fig.set_size_inches(fig_size[0], fig_size[1]) ax = fig.add_subplot(111) ax.set_title(title) ax.set_xlabel(x_label) ax.set_ylabel(y_label) # --- # # Euler's Formula # $$e^{ix} = \cos(x) + i \sin(x)$$ # # # So raising $e^{ix}$ produces rotation (in the Complex plane) # # # ## Related to Euler's Identity # # $$e^{i \pi} + 1 = 0$$ # # * At $x = \pi$, $\sin(\pi) = 0$, and $\cos(\pi) = -1$ # * So $e^{i \pi} = -1 + 0$ # * Move the 1 over: $e^{i \pi} + 1 = 0$ # # ## Complex Plane # ![Complex Plane](files/images/complex_plane.jpg) # In[8]: # Generate some complex numbers, and convert them to (x,y) coordinates complex_points = [np.e**(1j * i) for i in np.linspace(0, 2*np.pi, 16)] real_parts = [z.real for z in complex_points] imag_parts = [z.imag for z in complex_points] # Matplotlib code to draw graph fig = plt.figure() fig.set_size_inches(6, 6) ax = fig.add_subplot(111) ax.spines['left'].set_position('center') ax.spines['bottom'].set_position('center') ax.spines['top'].set_color('none') ax.spines['right'].set_color('none') ax.set_xlim((-1.5,1.5)) ax.set_xticks(np.linspace(-1.5,1.5,4)) ax.set_ylim((-1.5,1.5)) ax.set_yticks(np.linspace(-1.5,1.5,4)) ax.annotate("{0} + {1}i".format(real_parts[1], imag_parts[1]), xy=(real_parts[1], \ imag_parts[1]), xytext=(1,1), arrowprops=dict(facecolor='black', shrink=0.08)) _ = plt.plot(real_parts, imag_parts, 'go') # ### Going around a circle produces sine and cosine waves # # ![sine_curve](files/images/Sine_curve_drawing_animation.gif) # # Circles produce sin (and cos) waves # In[9]: t = np.linspace(0, 3 * 2*np.pi, 100) e_func = [np.e**(1j * i) for i in t] # In[10]: setup_graph(title='real part (cosine) of e^ix', x_label='time', y_label='amplitude of real part', fig_size=(12,6)) _ = plt.plot(t, [i.real for i in e_func]) # In[11]: setup_graph(title='imaginary part (sin) of e^ix', x_label='time', y_label='amplitude of imaginary part', fig_size=(12,6)) _ = plt.plot(t, [i.imag for i in e_func]) # In[ ]: