Complex Numbers and Complex Functions ===================================== $\DeclareMathOperator{\arctantwo}{arctan2}$ Algebra ------- To quote Wikipedia: In its most general form algebra is the study of *symbols* and the rules for *manipulating symbols* and is a unifying thread of all of mathematics. An example is simple arithmetic we are all used to. We all know that $a\times b=b\times a$, i.e. if $a$ and $b$ are the numbers we all think of then the order in a multiplication is irrelevant. We could device of set of symbols and manipulation rules where this property is not true. The algebra of *complex numbers* is close to the algebra of the real numbers (in which the commutative property of multiplication does hold). Basically what we do to define complex numbers is that we add a new 'number' that we call $j$ to the real numbers (in control theory it is called 'j', in classical math literature it is called 'i'). We can add $j$ to a real number like $2+j$. This is not a real number of course and there is no way to simplify this in any way. But what *is* it? Essentially, mathematicians don't care, they want a neat self consistent structure (an algebra) so they can do calculations. We can also multiply a real number with the complex number $j$ and get $3j$, again something we can't simplify. But what happens when we multiply $j$ with itself? What is $j\times j = j^2$? If this can't be simplified we open up a box of pandora because then what is $j j j = j^3$. Instead of introducing just one new symbol in our calculations, we essentially introduce a lot of them: $j$, $j^2$, $j^3$, etc. And what to think of $j^\pi$? Fortunately complex numbers are more neat than this. We **define** Imaginary number The imaginary number $j$ has the property that $j^2=-1$. Note that this really is a remarkable definition. When you are accustomed to real numbers it is no wonder we call it an imaginary number: indeed a strange thing that the square of a 'number' is negative. But for now just play along with this mathematical game; these complex numbers turn out to be very useful in practice indeed. Given this definition we have $j^3 = j^2 j = -1 j = -j$. Note that we haven't said what $j^\pi$ is, but can you really explain what $2^\pi$ is? We get to that later. If you think of it the general form of a complex number is simple: Complex Numbers A complex number $z=a+jb$ has a real part $\Re(z)=a$ and a complex part $\Im(z)=b$ where $a$ and $b$ are real numbers. **Any complex number** $z$ **can be written as** $a+jb$. Complex numbers are used so often they got their own name. The set of all complex numbers is denoted as $\mathbb C$ Algebraically the complex numbers follow the same rules as the real numbers (mathematicians say that the set of all complex numbers form a **field**): Addition We can add two complex numbers to give a new complex number. We *define*: $(a+jb)+(c+jd)=(a+c)+j(b+d)$. In adding a complex number we add the real and imaginary parts (and we do know how to do that because these are real numbers by definition). Identity Element there is a unique additive identity element $0$ such that for all complex numbers $z$ we have: $z+0=z$. The identity element of course is $0+j0$. Additive Inverse Element there is an additive inverse element $-z$ such that $z+ (-z)=0$. Obviously in case $z=a+jb$ we have $-z=-a-jb$. Commutative and Associative the addition and multiplication are commutative ($a+b=b+a$) and associative ($a+(b+c)=(a+b)+c$). The associative property implies that in an addition of several complex numbers we may leave out all parentheses. The commutative property and the commutative property combined make that in a summation of several complex numbers we may permute the numbers in the sum. Multiplication we can multiply two complex numbers to give a new complex number: $(a+jb)(c+jd)=(ac-bd)+j(ad+bc)$ There is really nothing special in the multiplication. Just follow your high school math method to get rid of parenthesis (in Dutch high schools there are two prevailing tricks: the 'snavel' method and the table method): $(a+jb)(c+jd)=ac + jad + jbc + jbjd = (ac-bd)+j(ad+bc)$ Multiplicative Identity Element there is multiplicative identity element $1$ such that $1z=z$ Multiplicative Inverse Element there is a multiplicative inverse element $z\inv$ for every $z\not=0$ such that $z z\inv = 1$: Consider $z=a+jb$ then: .. math:: (a+jb)\inv = \frac{1}{a+jb} = \frac{a-jb}{a^2+b^2} = \frac{a}{a^2+b^2} - j \frac{b}{a^2+b^2} There is a lesson to be learned here. No matter how complicated an algebraic expression using complex numbers may get that expression always represents a complex number and thus we should be able to find the real values $a$ and $b$ such that the complex number is $a+jb$. And there a few 'tricks' that you can use to do so (or use Mathematica or Wolfram Alpha...). The trick to write $1/(a+jb)$ as a real number in the standard form is to multiply the nominator and denominator with $a-jb$. Distributive over Addition the multiplication distributes over the addition: $u(v+w) = uv+uw$. Complex Conjugate The complex conjugate $z^\ast$ of a complex number $z=a+jb$ is defined as $z^\ast=a-jb$. Roots of Polynomials Whereas for real numbers the equation $z^2=-1$ has no solution, for complex numbers we can find two roots: $z=i$ and $z=-i$. Remember that a quadratic equation didn't have solutions when the determinant is negative? Well in $\mathbb C$ there is always a solution and a negative determinant merely indicates that some roots are complex values. In fact in $\setC$ an $n$-th order polynomial has exactly $n$ roots (taking multiplicity of roots into account). Complex Functions ----------------- We are accustomed to look at functions as mappings from the set of real numbers to the set of real numbers. Complex functions do exist as well, so we can define a function $f:\setC\rightarrow\setC$: .. math:: f(z) = z^2+1 indeed for every $z\in\setC$ the function gives a complex value $f(z)$. A complex function is not so easy to plot: every complex value $z=x+jy$ is mapped to a new value $f(z) = x'+jy'$ where $x' = f_r(x,y)$ and $y'=f_i(x,y)$. In terms of real valued functions a complex function is the combination of two real valued functions in two variables. Please note that this is not the prefered way to look at complex functions. Just consider complex functions as a kind of slot machine where you put in one complex number ($z$) and the machine will return you another complex number ($f(z)$). As we started by defining the algebraic operations on complex numbers, all functions that are compositions of these basic algebraic operations are complex functions. But what about the sin function or the exponential functions or the logarithmic function. Can we take the sin of a complex number? And what would it mean then? And of course: "Yes we can!". Complex function theory is a rather complex theory and for all details we refer to standard books on this subject. Here we point at a common way to define complex functions. We start with a real function, say $\sin(x)$, then expand this function in a series using only algebraic operations on the argument $x$ making sure the series for is valid for any $x\in\setR$. Then we *define* the complex function using the algebraic series of the real valued function. Take the real valued sine function $f(x)=\sin x$. Its Taylor series expansion is: .. math:: \sin x = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \cdots Mathematicians can prove that this series converges to the true value for any $x$. Note that the right hand side of the above equation makes perfectly sense if we replace $x$ with a complex value $z$. So we *define* the complex sine function as: .. math:: \sin z = z - \frac{z^3}{3!} + \frac{z^5}{5!} - \frac{z^7}{7!} + \cdots Of course this only makes sense in case this series converges for all values of $z$. The series definition of the sine function is not the way you would like to calculate the sine function of course. Fortunately it can be shown that .. math:: \sin( x+jy) = \sin x \cosh y + j \cos x \sinh y where $\sinh$ and $\cosh$ are the hyperbolic sine function and hyperbolic cosine functions (look them up on Wikipedia in case you want to knwo). These functions are implemented in any decent math library. Along the same line of reasoning we can define the complex exponential function: .. math:: e^z = 1 + z + \frac{z^2}{2!} + \frac{z^3}{3!} + \frac{z^4}{4!} + \cdots We get a famous result in case we set $z=j\phi$ (a pure imaginary number): .. math:: e^{j\phi} &= 1 + j\phi + \frac{(j\phi)^2}{2!} + \frac{(j\phi)^3}{3!} + \frac{(j\phi)^4}{4!} + \frac{(j\phi)^5}{5!}\cdots\\ &= 1 + j\phi + - \frac{\phi^2}{2!} - j \frac{\phi^3}{3!} + \frac{\phi^4}{4!} + j \frac{\phi^5}{5!} + \cdots\\ &= \left(1 - \frac{\phi^2}{2!} + \frac{\phi^4}{4!} - \cdots\right) + j \left(\phi - \frac{\phi^3}{3!} + \frac{\phi^5}{5!}\cdots \right) In the second series on the right hand side of the above equation we recognize the series of the sine function. The first series is equal to the cosine function. This leads to a famous formula: Euler's formula .. math:: e^{j\phi} = \cos\phi + j\sin\phi. From this it is evident that $e^{-j\phi} = \cos\phi - j\sin\phi$. Using both the above expressions we can derive that: .. math:: \cos\phi &= \frac{e^{j\phi}+e^{-j\phi}}{2}\\ \sin\phi &= \frac{e^{j\phi}-e^{-j\phi}}{2j} Eulers formula plays an important role in signal processing. In (digital) signal processing we will use complex functions quite a lot. Mostly we will consider the `nice' functions that behave along the lines we would expect from our calculus course. But be warned: complex functions can really be quite complex: .. math:: 1 = \sqrt{1} = \sqrt{(-1)(-1)} = \sqrt{-1} \sqrt{-1} = jj = j^2 = -1 No this is certainly not true, but it is an error because a result from real analysis is used that is not generally true for complex functions. For complex arguments in general: $\sqrt{ab}\not=\sqrt{a}\sqrt{b}$. For complex functions $f(z): \setC\mapsto \setC$ we can also define its derivative $f'(z)$: .. math:: \frac{df(z)}{dz} = f'(z) = \lim_{w\rightarrow v}\frac{f(w)-f(z)}{w-z} Note that the limit not need to exist, then the function is said to be non differentiable in $z$. The notion of complex derivative is much more complex than you might think. For starters: note that there are not just two ways for $w$ to approach $z$ (as would be the case for a function defined on the real axis. There are infinitely many paths to approach $z$. For a nice illustration and more background on complex derivatives we refer to `this online resource `_. Fortunately in this course we are exclusively using function $f: t\in\setR\mapsto f(t)\in\setC$ so we will not be differentiating with respect to a complex variable. Geometrical Interpretation -------------------------- As we have said before any complex number $z$ can be written as $z=x+jy$ where $x$ and $y$ are two real numbers. The numbers can be interpreted as coordinates in the **complex plane** (also called Argand plane of Gauss plane) where $x$ is the coordinate along the horizontal real axis and $y$ is the coordinate along the vertical imaginairy axis. We then can also interpret $z=x+jy$ as a vector pointing from the origin to $z$ in the complex plane. With this vectorial interpretation it is not hard to check that the addition, subtraction and scalar (with a real value) multiplication were are used to in a real vector space are equivalent to the complex algebra defined in this section. The use of complex numbers to look at vectors in a 2D plane adds the possibility to multiply two vectors. But what is the geometrical interpretation of such a multiplication? In order to answer that question take a complex number $z=x+jy$ and multiply it with $j$. Plot both $z$ and $jz$. What is their relation? And if you multiply again with $j$, i.e. $jjz$? A useful way is to introduce the polar representation of complex numbers. Any point with coordinates $(x,y)$ in the plane can also be represented in polar coordinates $(r,\phi)$ with: .. math:: x &= r\cos\phi\\ y &= r\sin\phi For the complex number $z=x+jy$ we thus have .. math:: z &= r\cos\phi + jr\sin\phi\\ &= r(\cos\phi + j\sin\phi)\\ &= re^{j\phi} Polar Representation Any complex number $z=x+jy$ can also be written in polar form as $z=re^{j\phi}$ where .. math:: r &= \sqrt{x^2+y^2}\\ \phi &= \arctantwo(y,x) The value of $r$ is called the **absolute value**, **magnitude** or **modulus** of the complex number $z$ and is denoted as $|z|$. The value $\phi$ is called the **angle**, **argument** or **phase** of the complex number and is denoted with $\angle z$ or $\arg(z)$. .. image:: https://upload.wikimedia.org/wikipedia/commons/thumb/7/71/Euler%27s_formula.svg/270px-Euler%27s_formula.svg.png :align: center This polar representation makes it easy to see what multiplication and division of complex numbers does in the complex plane. Multiplication in the Polor Representation Multiplication of two complex numbers $z_1=r_1 e^{j\phi_1}$ and $z_2=r_2 e^{j\phi_2}$ results in the complex number $z = z_1 z_2 = r_1 r_2 e^{j(\phi_1+\phi_2)}$, i.e. the lengths multiply and the angles add up. The division is left as an exerise to the reader... Complex Numbers in Python/Numpy ------------------------------- Complex numbers are easy in Python/Numpy, they are integral part of the language just like integers and floating points numbers. An imaginaire number is written as $5j$. Note that you can't write $j$, instead you have to use $1j$. .. ipython:: python import numpy as np z1 = 3 + 2j z2 = -2 - 5j print(z1+z2) print(z1*z2) print(np.abs(z1), np.angle(z1)) print(np.abs(z2), np.angle(z2)) Even calculation of the roots of polynomials is build into Numpy. A polynomial $ax^2+bx+c$ is represented with its coefficients in a list $[a,b,c]$. .. ipython:: python a = 1; b = 0; c = 1 pol = [a, b, c] roots(pol) Exercises --------- #. Complex Numbers I Let $z_1=1+2j$ en $z_2=2+j$. For each of the following complex numbers calculate: its real part, its imaginairy part, the absolute value and the angle. #. $z_1$ #. $z_2$ #. $z_1+z_2$ #. $z_1-z_2$ #. $z_1 z_2$ #. $z_1 / z_2$ #. Complex Numbers II The same as above but this time for $z_1=1+j$ and $z_2=-1+j$. #. Polair Representation Plot the following complex numbers in the complex plane (a separate drawing for ex 1 and ex 2). Make sure to label the four points in each drawing! #. $z_1=\exp(j0.5\pi)$, $z_2=\exp(-j0.5\pi)$, $z_3=\exp(-j\pi)$, $z_4=\exp(j3\pi/4)$ #. $z_1=\exp(0.5j)$, $z_2=\exp(-0.5j)$, $z_3=\exp(j)$, $z_4=\exp(3j)$ #. If all went well all points are on the unit circle. Why is that? #. Inverse Element Given the expression for the inverse element of $z=a+jb$: .. math:: z\inv = \frac{a}{a^2+b^2} - j\frac{b}{a^2+b^2} prove that $z z\inv = 1$. #. Complex Conjugate Show that $zz^\ast=|z|^2$. #. Quadratic Equation Remember the 'abc'-formula from highschool to solve a quadratic equation of the form $ax^2+bx+c=0$: .. math:: x_{1,2} = \frac{-b \pm \sqrt{b^2-4ac}}{2a} Calculate the roots of the following equations: #. $z^2+4z-5$ #. $z^2+4z+5$ #. $z^2-1$ #. $z^2+1$ #. $z^2+4z-5j$ #. $z^2+j$ #. $jz^2-2z+j$ Of course you may check your answers with Numpy, but you only score points in case you give the derivation. #. Higher Order Calculate the roots of the following equations: #. $z^4+1$ #. $z^4-0.34$ #. $Cos$ and $Sin$ I Prove both equations: .. math:: \sin(\phi) &= \frac{e^{j\phi}-e^{-j\phi}}{2j}\\ \cos(\phi) &= \frac{e^{j\phi}+e^{-j\phi}}{2} #. $Cos$ and $Sin$ II Rewrite $2\exp(2j\Omega) + \exp(j\Omega) + \exp(-j\Omega) + \exp(-2j\Omega)$ using $\sin$ and $\cos$. #. $Cos$ and $Sin$ III Rewrite $(z-\exp(j\pi/10))(z-\exp(-j\pi/10))$ using $\sin$ and $\cos$. #. Powers on Unit Circle Let $z=\frac{\sqrt{3}}{2} + j\frac{1}{2}$. #. Show that $z$ is on the unit circle in the complex plane. #. Calculate $z^2$ in two ways, first in the algebraic representation with the real and imaginairy parts and secondly by first calculating the polar representation of $z$. #. Plot $z$, $z^2$, $z^3$ and $z^4$ in the complex plane. #. Roots on the Unit Circle Solve $z^n=e^{j\phi}$. Note that there are more then just one solution!