In [1]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
From wikipedia we get:
A complex number is a number that can be expressed in the form $a + bi$, where $a$ and $b$ are real numbers and $i$ is the imaginary unit, that satisfies the equation $i^2 = −1$.
And of course this is true but not very useful if you're just starting out. This excellent playlist gives an awesome introduction to the subject. And if you're interested in numbers in general The Story of One is fun too.
We can show the problem with this innocent looking equation: $y = x^2 + 1$. If we want to find the root where $y = 0$ we end up with $x^2 = -1 \implies x = \sqrt{-1}$. There wasn't any number that satisfied $n^2 \lt 0$ so what ended up happening was a new number being invented. Eventually it got known as the imaginary number $i$ and this number is defined as $i = \sqrt{-1}$.
Basically it turns out that numbers have more than one dimension and this in turn leads us to the complex plane. As it turns out we can plot all our familiar numbers along the $x$ axis and their imaginary components along the $y$ axis in order to somewhat visualize how they work.
In [117]:
fig, ax = plt.subplots(1)
ax.tick_params('both', length=10, width=1, direction='inout')
for s in ['top', 'right']:
ax.spines[s].set_visible(False)
for s in ['left', 'bottom']:
ax.spines[s].set_position(('data', 0))
for a, s in [(ax.xaxis, 'bottom'), (ax.yaxis, 'left')]:
a.set_ticks_position(s)
ax.xaxis.set_ticklabels([])
ax.yaxis.set_ticklabels([])
ax.xaxis.set_ticks([-4, -3, -2, -1, 1, 2, 3, 4])
ax.yaxis.set_ticks([-4, -3, -2, -1, 1, 2, 3, 4])
ax.set_xlim(-5, 5)
ax.set_ylim(-5, 5)
arrowprops = {
'head_length': 0.3,
'head_width': 0.24,
'length_includes_head': True,
'overhang': 0.3
}
ax.arrow(0, 0, 4, 3, fc='b', ec='b', **arrowprops, label='foo')
ax.arrow(0, 0, 0, 1, fc='#dd1111', ec='#dd1111', zorder=3, **arrowprops)
ax.arrow(0, 0, -3, 4, fc='#11aa77', ec='#11aa77', **arrowprops)
ax.arrow(0, 0, -4, -3, fc='#11cc99', ec='#11cc99', **arrowprops)
ax.arrow(0, 0, 3, -4, fc='#11eeaa', ec='#11eeaa', **arrowprops)
ax.annotate('$(4 + 3i)i^0$', (4.25, 3))
ax.annotate('$i$', (0.3, 1))
ax.annotate('$(4 + 3i)i^1$', (-2.5, 4))
ax.annotate('$(4 + 3i)i^2$', (-4.5, -3.75))
ax.annotate('$(4 + 3i)i^3$', (3.25, -4))
Out[117]:
In [114]:
[np.complex(4, 3) * np.complex(0, 1)**x for x in range(4)]
Out[114]:
In [ ]: