Study Guides / Linear Algebra / Exercise session 1
EXERCISE SESSION 1 · ETH ZURICH · HS19 · linalg

Complex Numbers and Matlab

Complex numbers, 'nice' cosine and sine values on the unit circle, Matlab

SB
Steven Battilana Quant · ex-ETH

Complex Numbers

Remark

z2+1=0z^2+1=0 is an example of an equation that has no solution in R\mathbb{R}. To find a solution, we therefore extend the field to R2\mathbb{R}^2 and call it the field (covered in more detail in chapter 5, Algebra, of Discrete Mathematics) of complex numbers C\mathbb{C}.

Definition imaginary unit
i2=−1i=^ the imaginary unit\begin{aligned} i^2 &= -1\\ i &\mathrel{\hat{=}} \text{ the imaginary unit}\end{aligned}
Definition Cartesian form
z=x+iyz = x + iy
Definition real and imaginary part
Re(z):=x∈R=^ real partIm(z):=y∈R=^ imaginary part\begin{aligned} Re(z) &:= x \in \mathbb{R} \quad \mathrel{\hat{=}} \text{ real part}\\ Im(z) &:= y \in \mathbb{R} \quad \mathrel{\hat{=}} \text{ imaginary part}\end{aligned}
Definition conjugation

The conjugate of z=x+iy∈Cz = x + iy \in \mathbb{C} is

z‾=x−iy∈C.\overline{z} = x - iy \in \mathbb{C}.

Conjugation has the following properties:

(i) For all z=x+iy=(x,y),z∈C=R2z = x + iy = (x,y), z \in \mathbb{C} = \mathbb{R}^2 we have

  • z⋅z‾=(x+iy)⋅(x−iy)=x2−i2y2=x2+y2=∥z∥2.z \cdot \overline{z} = (x + iy) \cdot (x - iy) = x^2 - i^2y^2 = x^2 + y^2 = \left\lVert z \right\rVert ^2.

(ii) For all z1,z2∈Cz_1,z_2 \in \mathbb{C} we have

  • z1+z2‾=z1‾+z2‾\overline{z_1 + z_2} = \overline{z_1} + \overline{z_2};
  • z1z2‾=z1‾ z2‾\overline{z_1z_2} = \overline{z_1}\, \overline{z_2}.
Remark

Further properties of the complex numbers. Let z,w∈Cz, w \in \mathbb{C}; then the following hold:

  1. ∥z⋅w∥=∥z∥⋅∥w∥\Vert z \cdot w \Vert = \Vert z \Vert \cdot \Vert w \Vert
  2. ∥zw∥=∥z∥∥w∥,w≠0\Vert \frac{z}{w} \Vert = \frac{\Vert z \Vert}{\Vert w \Vert}, w \neq 0
  3. ∥z∥=∥z‾∥\Vert z \Vert = \Vert \overline{z} \Vert
  4. ∥z+w∥≤∥z∥+∥w∥\Vert z + w \Vert \leq \Vert z \Vert + \Vert w \Vert triangle inequality
Definition Euler's formula
eiφ=cos⁡φ+isin⁡φe^{i \varphi} = \cos \varphi + i \sin \varphi
Definition polar form

The polar form of z=x+iy∈Cz = x + iy \in \mathbb{C} is (caution: φ∈(−π,π]\varphi \in (-\pi, \pi])

z= reiφ,⇔Euler’s formulaz= r(cos⁡φ+isin⁡φ),with r=∥z∥,x=r cos⁡φ,y=r sin⁡φ.\begin{aligned} z = \,&re^{i \varphi},\\ \overset{\text{Euler's formula}}{\Leftrightarrow} z = \,& r(\cos \varphi + i \sin \varphi),\\ \text{with } &r = \Vert z \Vert,\\ &x = r\, \cos \varphi,\\ &y = r\, \sin \varphi. \end{aligned}φ={arctan⁡(yx),x>0arctan⁡(yx)+π,x<0∧y≥0arctan⁡(yx)−π,x<0∧y<0π2,x=0∧y>0−π2,x=0∧y<0undefined,x=0∧y=0\varphi = \begin{cases} \arctan (\frac{y}{x}), &x>0\\ \arctan (\frac{y}{x}) + \pi, &x<0 \wedge y \geq 0\\ \arctan (\frac{y}{x}) - \pi, &x<0 \wedge y < 0\\ \frac{\pi}{2}, &x = 0 \wedge y > 0\\ -\frac{\pi}{2}, &x = 0 \wedge y < 0\\ \text{undefined}, &x = 0 \wedge y = 0 \end{cases}
Remark

The angle φ′\varphi' in the interval [0,2π)[0, 2\pi) can in principle be computed by first computing the angle in (−π,π](-\pi, \pi] as described above and, only if it is negative, increasing it by 2π2\pi:

φ′={φ+2π,φ<0φ,otherwise.\varphi' = \begin{cases} \varphi + 2\pi, &\varphi < 0\\ \varphi, &\text{otherwise.} \end{cases}
Remark

As an alternative to arctan, φ\varphi can also be computed via sine and cosine:

φ∈[0,π]:cos⁡(φ)=xr⟺φ=arccos⁡(xr)φ∈[−π2,π2]:sin⁡(φ)=yr⟺φ=arcsin⁡(yr)\begin{aligned} \varphi \in [0, \pi]: \quad \cos(\varphi) &= \frac{x}{r} \qquad \Longleftrightarrow \qquad \varphi = \arccos\left(\frac{x}{r}\right)\\ \varphi \in [-\tfrac{\pi}{2}, \tfrac{\pi}{2}]: \quad \sin(\varphi) &= \frac{y}{r} \qquad \Longleftrightarrow \qquad \varphi = \arcsin\left(\frac{y}{r}\right) \end{aligned}
Remark Outlook

z2+1=0z^2 + 1 = 0 is an example of an equation with no solution in R\mathbb{R} that does have solutions in C\mathbb{C} (namely z=±iz = \pm i). More generally, the fundamental theorem of algebra holds: every polynomial

p(z)=zn+an−1zn−1+⋯+a0p(z) = z^n + a_{n-1}z^{n-1} + \cdots + a_0

of degree n≥1n \geq 1 has a root in C\mathbb{C}. That is, unlike R\mathbb{R}, C\mathbb{C} is algebraically closed.

Example 1

Compute: 6+7i3−8i\frac{6+7i}{3-8i}

Show solutionHide solution 6+7i3−8i=6+7i3−8i⋅3+8i3+8i=18+21i+48i+56i29−64i2=18+21i+48i−569+64=−38+69i73\frac{6+7i}{3-8i} = \frac{6+7i}{3-8i} \cdot \frac{3+8i}{3+8i} = \frac{18 + 21i + 48i + 56i^2}{9 - 64i^2} = \frac{18 + 21i + 48i - 56}{9 + 64} = \frac{-38+69i}{73}
Example 2

Compute the polar form of z=1+iz = 1+i.

Show solutionHide solution r=12+12=2φ=arctan⁡(11)=π4⇒z=2eiπ4\begin{aligned} r &= \sqrt{1^2 + 1^2} = \sqrt{2}\\ \varphi &= \arctan (\frac{1}{1}) = \frac{\pi}{4}\\ &\Rightarrow z = \sqrt{2} e^{i \frac{\pi}{4}} \end{aligned}
Example 3

Compute the Cartesian form of 7eiπ37 e^{i \frac{\pi}{3}}.

Show solutionHide solution 7eiπ3=7(cos⁡(π3)+isin⁡(π3))=7⋅12+7⋅32i=72+732i7 e^{i \frac{\pi}{3}} = 7(\cos (\frac{\pi}{3}) + i\sin (\frac{\pi}{3})) = 7 \cdot\frac{1}{2} + 7 \cdot \frac{\sqrt{3}}{2} i = \frac{7}{2} + \frac{7 \sqrt{3}}{2} i
Example 4

Sketch the following set in the complex plane:

D:={(22(1+i))n    :    n∈N}D := \left\{ \left(\frac{\sqrt{2}}{2} (1+i) \right)^n \;\; : \;\; n \in \mathbb{N} \right\}
Show solutionHide solution

In polar coordinates (1+i)=2eiπ4(1+i) = \sqrt{2} e^{i \frac{\pi}{4}}, hence

(22(1+i))n=einπ4.\left( \frac{\sqrt{2}}{2} (1+i) \right)^n = e^{i \frac{n \pi}{4}}.

Since eiθ=ei(θ+2kπ)e^{i \theta} = e^{i (\theta + 2k \pi)} ∀k∈Z\quad \forall k \in \mathbb{Z}, DD consists of 8 points, obtained for n=0,1,2,..7n=0,1,2,..7:

D={1,eiπ4,ei2π4,ei3π4,ei4π4,ei5π4,ei6π4,ei7π4}D = \{1, e^{i \frac{\pi}{4}}, e^{i \frac{2\pi}{4}}, e^{i \frac{3\pi}{4}}, e^{i \frac{4\pi}{4}}, e^{i \frac{5\pi}{4}}, e^{i \frac{6\pi}{4}}, e^{i \frac{7\pi}{4}} \}
The eight points of D on the unit circle
Example 5

Sketch the following set in the complex plane:

E:={z∈C    :    ∥z−i∥<∥z−1∥}E := \left\{ z \in \mathbb{C} \;\; : \;\; \Vert z - i \Vert < \Vert z - 1 \Vert \right\}
Show solutionHide solution ∥z−i∥<∥z−1∥⟺∥z−i∥2<∥z−1∥2⟺∥x+iy−i∥2<∥x+iy−1∥2⟺∥x+i(y−1)∥2<∥(x−1)+iy∥2⟺(a+ib)(a+ib)‾=∥a+ib∥2=a2+b2x2+(y−1)2<(x−1)2+y2⟺x2+y2−2y+1<x2−2x+1+y2⟺y>x\begin{aligned} \Vert z - i \Vert &< \Vert z - 1 \Vert\\ \Longleftrightarrow \qquad \Vert z - i \Vert^2 &< \Vert z - 1 \Vert^2\\ \Longleftrightarrow \qquad \Vert x + iy - i \Vert^2 &< \Vert x + iy - 1 \Vert^2\\ \Longleftrightarrow \qquad \Vert x + i(y - 1) \Vert^2 &< \Vert (x - 1) + iy \Vert^2\\ \overset{(a + ib)\overline{(a + ib)} = \Vert a + ib \Vert^2 = a^2 + b^2}{\Longleftrightarrow} \qquad x^2 + (y - 1)^2 &< (x - 1)^2 + y^2\\ \Longleftrightarrow \qquad x^2 + y^2 - 2y + 1 &< x^2 - 2x + 1 + y^2\\ \Longleftrightarrow \qquad y &> x \end{aligned}
The half-plane y > x in the complex plane
Remark belongs in your exam summary

Below you see the "nice" cosine and sine values on the unit circle, where the xx-direction corresponds to cos⁡(φ)\cos(\varphi) and the yy-direction to sin⁡(φ)\sin(\varphi):

Unit circle with the nice cosine and sine values
Remark

Quadratic formula (learn by heart)

ax2+bx+c=0⇒x1,2=−b±b2−4ac2a\begin{aligned} ax^2 + bx + c &= 0\\ \Rightarrow \quad x_{1,2} &= \frac{-b \pm \sqrt{b^2 -4ac}}{2a} \end{aligned}
Example 6

Find all solutions of the following equation:

z2−2(3i+eiπ)=0(1)z^2 - 2 \left( \sqrt{3} i + e^{i \pi} \right) = 0 \tag{1}
Show solutionHide solution z2−2(3i+eiπ)=0⟺eiπ=−1z2−2(3i−1)=0⟺z2=2(3i−1)⟺z2=−2+23i⟺z2=4(−12+32i)⟺polar form and Euler’s formula(reiϑ)2=4ei2π3⟺r2e2iϑ=4ei2π3\begin{aligned} z^2 - 2 \left( \sqrt{3} i + e^{i \pi} \right) &= 0\\ \overset{e^{i \pi} = -1}{\Longleftrightarrow} \qquad z^2 - 2 \left( \sqrt{3} i -1 \right) &= 0\\ \Longleftrightarrow \qquad z^2 &= 2 \left( \sqrt{3} i -1 \right)\\ \Longleftrightarrow \qquad z^2 &= - 2 + 2 \sqrt{3} i\\ \Longleftrightarrow \qquad z^2 &= 4 \left( -\frac{1}{2} + \frac{\sqrt{3}}{2}i \right)\\ \overset{\text{polar form and Euler's formula}}{\Longleftrightarrow} \qquad \left(r e^{i \vartheta} \right)^2 &= 4 e^{i \frac{2 \pi}{3}}\\ \Longleftrightarrow \qquad r^2 e^{2 i \vartheta} &= 4 e^{i \frac{2 \pi}{3}} \end{aligned}⟹r=4=2⟹2ϑ=2π3+2kπ,    ∀k∈Z⟺ϑ=π3+kπ,    ∀k∈Z\begin{aligned} \Longrightarrow \qquad r &= \sqrt{4} = 2\\ \Longrightarrow \qquad 2 \vartheta &= \frac{2 \pi}{3} + 2k \pi,\;\; \forall k \in \mathbb{Z}\\ \Longleftrightarrow \qquad \vartheta &= \frac{\pi}{3} + k \pi,\;\; \forall k \in \mathbb{Z} \end{aligned}⟹z=2ei(π3+kπ)for   k=0,1⟺z={2eiπ3,2ei4π3}⟺z={1+3i,−1−3i}\begin{aligned} \Longrightarrow \qquad z &= 2 e^{i \left(\frac{\pi}{3} + k \pi \right)} \qquad \text{for } \; k = 0, 1\\ \Longleftrightarrow \qquad z &= \left\{ 2e^{i \frac{\pi}{3}}, 2e^{i \frac{4\pi}{3}} \right\}\\ \Longleftrightarrow \qquad z &= \left\{ 1 + \sqrt{3} i, -1 - \sqrt{3}i \right\} \end{aligned}

MATLAB

If you have a function but are not sure what it needs as input or what it returns, you can find out as follows:

Example 7 Lucas numbers
  • Definition

    Ln:={2,n=01,n=1Ln−1+Ln−2,n>1L_n := \begin{cases} 2, &n = 0\\ 1, &n = 1\\ L_{n-1} + L_{n-2}, \quad &n > 1 \end{cases}

    This gives us the sequence: 2,1,3,4,7,11,18,29,47,76,123,…2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, \dots

  • Task
    Write a Matlab function lucas(n) that, for a given positive integer nn, computes the Lucas numbers L0,…,LnL_0, \dots, L_n.