Complex numbers

Roberto Di Remigio, Luca Frediani

Complex numbers are extremely important in mathematics and physics. The concept of a complex number was introduced as early as the 16th century in order to solve algebraic equations without a real solution, such as:

\begin{equation} x^2 + 1 = 0 \end{equation}

If we define the imaginary unit as:

\begin{equation} \mathrm{i}^2 = -1 \end{equation}

then the quadratic equation above admits the two, purely imaginary, solutions $+\mathrm{i}$ and $-\mathrm{i}$.

In general, a complex number is any entity that can be written in the form:

\begin{equation} z = a +\mathrm{i}b = \Re(z) +\mathrm{i}\Im(z) \end{equation}

where $a, b$ are real numbers and are called the real and imaginary part of the complex number $z$. Apart from all the usual operations, i.e. addition, subtraction, multiplication and division, we can furthermore define complex conjugation:

\begin{equation} z^* = a - \mathrm{i} b = \Re(z) - \mathrm{i}\Im(z) \end{equation}

Exercise 1

Write down explicitly the form of the sum, difference, multiplication and division of two complex numbers $z = a + \mathrm{i}b$ and $w=c + \mathrm{i}d$. Prove also that:

\begin{alignat}{2} \Re(z) = a = \frac{z+z^*}{2};\quad&\quad \Im(z) = b = \frac{z-z^*}{2\mathrm{i}} \end{alignat}

We can draw a powerful analogy between points in the plane and complex numbers. Let's rename the $x$-axis the real axis and the $y$-axis the imaginary axis. Any complex number can be represented in this plane, simply drawing the point with $x$ coordinate equal to its real part and $y$ coordinate equal to its imaginary part. This amounts to specifying the components of a 2-dimensional vector:

\begin{equation}\label{eq:vector} \overrightarrow{v} = \begin{pmatrix} \Re(z) \\ \Im(z) \end{pmatrix} = \begin{pmatrix} a \\ b \end{pmatrix} \end{equation}

Exercise 2

Draw the following numbers in the complex plane: $z=\frac{\sqrt{2}}{2} + \mathrm{i}\frac{\sqrt{2}}{2}$, $w=\frac{\sqrt{3}}{2} + \mathrm{i}\frac{1}{2}$ and their complex conjugates $z^*$ and $w^*$. The following example shows how to draw arrows using matplotlib and the arrow function. This function takes two four arguments, the $x$ and $y$ coordinates of the arrow start and the $x$ and $y$ coordinates of the arrow end.


In [29]:
import matplotlib.pyplot as plt
%matplotlib inline

ax = plt.axes()
# Use the arrow function
# The arrow start at x=0.0, y=0.0 and ends at x=0.5, y=0.5
ax.arrow(x=0, y=0, dx=0.5, dy=0.5)
plt.show()


The analogy between complex numbers and 2-dimensional vectors can be brought a bit further. Using Pythagoras' theorem we can calculate the length of a 2-dimensional vector (its norm or its magnitude) in terms of its components:

\begin{equation} v = \sqrt{a^2 + b^2} = \sqrt{\Re(z)^2 + \Im(z)^2} \end{equation}

This lets us introduce a third way of representing a complex number, the polar representation. Instead of specifying the cartesian components of our point in the complex plane (cartesian or rectangular representation), we can specify the length of the vector, $\rho$, and its angle with respect to the real axis $\theta$. We assume that angles increase in an anti-clockwise sense, with the zero corresponding to the $x$-axis.

Exercise 3

Using the Figure below

prove the following sets of relations between the rectangular and polar representations:

\begin{alignat}{2} \left\{ \begin{array}{lr} \rho = \sqrt{a^2 + b^2} \\ \tan\theta = \frac{b}{a} \end{array} \right. \quad&\quad \left\{ \begin{array}{lr} a = \rho\cos\theta\\ b = \rho\sin\theta \end{array} \right. \end{alignat} The tangent function is defined as $\tan\alpha=\frac{\sin\alpha}{\cos\alpha}$.

Using the second set among the equations above we have:

\begin{equation} z = \rho\cos\theta + \mathrm{i}\rho\sin\theta = \rho(\cos\theta + \mathrm{i}\sin\theta) \end{equation}

which we will rewrite as:

\begin{equation} z = \rho \mathrm{e}^{\mathrm{i}\theta} \end{equation}

The exponential above can be expanded as:

\begin{equation} \mathrm{e}^{\mathrm{i}\theta} = \cos\theta + \mathrm{i}\sin\theta \end{equation}

known as Euler's formula and $\mathrm{e}=2.71828\ldots$ is the Napier's constant. This formula is extremely important both from a theoretical and practical point of view.

Exercise 4

Given $z=\rho \mathrm{e}^{\mathrm{i}\theta}$ how would you write the Euler representation of its complex conjugate $z^*$?

Hint: what happens to $a+\mathrm{i} b$ when taking the complex conjugate?

Draw some more vectors in the complex plane using matplotlib: $\mathrm{e}^{\mathrm{i}\theta}$ where $\theta$ is $30^\circ$, $150^\circ$, $210^\circ$ and $330^\circ$. What do all these vectors have in common? You can write polar vectors in matplotlib in two ways. Either by using Euler's formula to find the arrow start and end coordinates or by using the proper syntax for polar plots. We invite you to use both and define the appropriate functions for the calculations needed when using the Cartesian representation. What follows is an example of polar plot.


In [2]:
import matplotlib.pyplot as plt
# make sure we see it on this notebook
%matplotlib inline
import numpy as np

# Enable polar coordinates
ax = plt.axes(polar=True)
# Use the arrow function
# The arrow forms a 45° angle with the x axis and has length 1
ax.arrow(x=45/180.*np.pi, y=0.0, dx=0, dy=1)
# We can still use the Cartesian format
ax.arrow(x=0.0, y=0.0, dx=0.5, dy=0.5)
plt.show()


Exercise 5

The Taylor expansion of $\mathrm{e}^{\mathrm{i}\theta}$ is given below. In this exercise we will try to ``prove'', by a convincing yet non-formal argument, that Euler's formula does indeed hold true.

\begin{equation} \begin{aligned} e^{\mathrm{i}\theta} &= \sum_{n = 0}^\infty \frac{(\mathrm{i}\theta)^n}{n!} \\ &= 1 + \mathrm{i}\theta + \frac{(\mathrm{i}\theta)^2}{2!} + \frac{(\mathrm{i}\theta)^3}{3!} + \frac{(\mathrm{i}\theta)^3}{3!} + \ldots \\ &= \left( 1 - \frac{\theta^2}{2!} + \frac{\theta^4}{4!} - \frac{\theta^6}{6!} +\ldots\right) + \mathrm{i}\left( \theta - \frac{\theta^3}{3!} + \frac{\theta^5}{5!} - \frac{\theta^7}{7!} + \ldots \right) \\ &= \cos\theta + \mathrm{i}\sin\theta \end{aligned} \end{equation}

Using matplotlib, you will produce two plots. The former will contain the plot of $\cos\theta$, $1$, $\left( 1 - \frac{\theta^2}{2!}\right)$, $\left( 1 - \frac{\theta^2}{2!} + \frac{\theta^4}{4!}\right)$ and $\left( 1 - \frac{\theta^2}{2!} + \frac{\theta^4}{4!} - \frac{\theta^6}{6!} \right)$. The latter will contain the plot of $\sin\theta$, $\theta$, $\left(\theta - \frac{\theta^3}{3!}\right)$, $\left(\theta - \frac{\theta^3}{3!} + \frac{\theta^5}{5!}\right)$ and $\left(\theta - \frac{\theta^3}{3!} + \frac{\theta^5}{5!} - \frac{\theta^7}{7!} \right)$. What is it you notice?

As a quick reminder, you should use both numpy and matplotlib to generate these plots. Defining functions will also help ;)

Bonus

The general expression for a Taylor expansion at $x_0$ is:

\begin{equation} f(x) = \sum_{n=0}^\infty\frac{(x-x_0)^n}{n!}f^{(n)}(x_0) \end{equation}

where $f^{(n)}(x_0) = \frac{\mathrm{d}^n f}{\mathrm{d}x^n}(x_0)$ is the $n$-th order derivative function of $f(x)$ evaluated at $x_0$. Write down explicitly the first few terms for the expansion of $\cos(x)$ and $\sin(x)$ for $x_0=0$ and verify that the identification made in the Taylor expansion above is correct.