A **complex number** is *a number that can be expressed or written in the form a + bi*, where a and b are real numbers, and i is the imaginary unit defined by i^{2} = −1.

We are going to use Octave. Octave is one of the most popular high-level programming languages, primarily intended and widely used for numerical computations. The Octave syntax is largely compatible with Matlab. It is the best free alternative to Matlab.

- Let’s define two complex numbers in Octave: x = 8 + 5i, y = 7 - 2i;
- Next, we perform all the standard operations with complex numbers:
**x + y**= ( (a + bi) + (c + di) = (a + c) + (b + d)i) = 15 + 3i.**x - y**= ( (a + bi) - (c + di) = (a - c) + (b - d)i)) = 1 + 7i.**x * y**= ( (a + bi) * (c + di) = (ac−bd) + (ad+bc)i) = 66 + 19i.**x / y**= ( (a + bi) / (c + di) = (ac + bd) + (bc -ad)i⁄c2 + d2 = 0.86792 + 0.96226i. - Then, abs(x) computes the radial coordinate, distance or radius of x = r = sqrt(a
^{2}+ b^{2}) = sqrt(64+25) = 9.4340. angle(x) computes the angular coordinate or angle of x = θ = atan2 (b, a) = arctan (b, a) in radians (a > 0) = 0.55860.**A complex number can be represented in rectangular form**as x = a + bi =*8 + 5i*where “i” is the imaginary unit**or**can alternatively be written**in polar form**as x = r(cosθ + sinθi) = re^{iθ}=*√89 e*.^{itan-1(5⁄8)} - real(x) and imag(x) return the real and imaginary part of the given complex number respectively (8, 5), and conj(x) returns the complex conjugate of x = a -bi = 8 -5i.
- Finally, the polar coordinates r and θ can be converted to the Cartesian coordinates “a” and “b” by: a = rcosθ = abs(x)*cos(angle(x)) y b = rsinθ = abs(x)*sin(angle(x)).

```
user@pc:~$ python
Python 3.8.10 (default, Jun 2 2021, 10:49:15)
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x=8+5j; # The quickest way to define a complex number in Python is by simply typing x = a +bj; in the source code
>>> y=7-2j;
>>> x+y # Since complex is a native data type in Python, you can do basic arithmetic calculations with them.
(15+3j)
>>> x-y
(1+7j)
>>> x*y
(66+19j)
>>> x/y;
(0.8679245283018868+0.9622641509433962j)
>>> 3*x
(24+15j)
>>> x.real # To get the real and imaginary parts of a complex number in Python, we only need to reach for the real and imag attributes.
8.0
>>> x.imag
5.0
>>> x.conjugate() # The conjugate method returns the complex conjugate, it is obtained by changing the sign of its imaginary part.
(8-5j)
>>> abs(x) # To get the magnitude, radial coordinate or radius of a complex number, we have to call abs()
9.433981132056603
>>> import cmath, numpy
>>> cmath.phase(x) # To get the phase, angular coordinate or angle of a complex number, we have to call cmath.phase()
0.5585993153435624
>>> numpy.degrees(cmath.phase(x)) # The phase returned by cmath.phase(x) is in radians and we may want to use the numpy.degrees() function to convert it to degrees.
32.005383208083494
```

Let’s use Geogebra to visualize complex numbers. More specifically, let’s visualize 8 + 5i. First, we will draw a triangle. Select **Polygon**, and click on the points or vertices (0, 0), (8, 0), (8, 5), and then the first point again (0, 0) to complete the triangle. Alternatively, you can type in the input field: *A = (0, 0), B = (8, 0), C = (8, 5), Polygon[A, B, C, A]*.

To get the phase or angle, select **Angle**, and click on B, A, and C or just type *Angle[B, A, C]* in the input field. The phase returned by Geogebra is in degrees.

Select C, then right-click **Object Properties**, and select in the drop menu **Show Label**, *Name & Value*.

We can enter the complex number w = 8 + 5i into the Input Bar. Next, click on the point, then right-click **Object Properties**, and select in the drop menu **Show Label**, *Name & Value*. Then, select **Complex Number** (*w = 8 + 5i*), **Cartesian Coordinates** (*w = (8, 5)* ) or **Polar Coordinates** (*w = (9.43, 32.010*) ) from the list of Coordinates formats on the tab **Algebra**.

We can use the following commands: x(w), y(w), abs(w), and arg(w). They return the real and imaginary part, the magnitude or radius, and the phase or angle of the given complex number respectively. conjugate(w) returns the conjugate of the complex number w: 8 - 5i.

Let’s go back to Octave.

- We can also convert the polar coordinates into Cartesian coordinates by typing: xTest = abs(x)*(cos(angle(x))+i*sin(angle(x)))
- cart2pol transforms Cartesian coordinates to polar coordinates:
*[theta, r] = cart2pol(8, 5)*. - pol2cart transforms polar coordinates to Cartesian coordinates:
*[u, v] = pol2cart(theta, r)*.

As you can see in the screenshot below, you can do *basic arithmetic on complex numbers with WolframAlpha*, too, e.g., (2+3i)*(4-2i), 1/(1+3i), (2+3i)^3…

We can use the Cartesian coordinate system and describe the location of a point p by two coordinates (x, y). We can also assign the point p a pair of polar coordinates (r, θ).

The first coordinate r “**is the distance from the pole (0, 0) to p** along a straight radial line, and θ is the **angle formed by that radial line and the positive x-axis**, measured anti-clockwise from the x-axis to the line,” Maths in a minute: Polar coordinates, +plus magazine. We can think of it as a clock with one hand. We “move out a distance r along the hand from the origin, then rotate the hand upwards (counter-clockwise) by an angle θ to reach the point,” xaktly.com, Polar coordinates.

Let’s use fooPlot, a simple online plotting tool. You can see a plot with a default function (x^2), but on the right, you can change the function and select **Polar** so it can be used in plotting polar graphs. You can set the background color, show/hide the grid lines, export the graph as svg, eps, pdf, and png, and even share it on your favorite social network.

r(theta) = 2 is the equation of a circle of radius R = 2 centered at the origin in polar coordinates. The graphs of the sine (sin(theta), theta in [0, pi]) and cosine functions (cos(theta), theta in [0, pi]) in polar coordinates are circles, too. sin(2*theta), theta in [0, 2*pi] is *a rose with four petals*. Remember that sin(theta), theta in [0, pi], was a circle, so sin(2*theta), theta in [0, ^{pi}⁄_{2}] is *a petal in the first quadrant*, and sin(2*theta), theta in [^{pi}⁄_{2}, pi] is the second petal in the second quadrant and so on, [pi, 3^{pi}⁄_{2}] and [3^{pi}⁄_{2}, 2]. 3*sin(2*theta) is the same rose with four petals, but three times the radius.

r(theta) = 2*sin(4*theta), theta in [0, 2pi] draws a pretty flower or rose with eight petals. 2 is the radius of the rose. It is formed by increasing the frequency factor (4), so it increases the number of loops in the polar graph (4=2*2, it doubles the petals of the last example).

The Archimidian spiral is described by the equation r = a + b*theta. a=0, so the center point of our spiral is the origin, and b=0.3. b controls the distance between loops.

```
import numpy as np
import matplotlib.pyplot as plt # matplotlib.pyplot provides a MATLAB-like way of plotting.
theta = np.arange(0, 2*np.pi, 0.01) # np.arange() returns the ndarray object containing evenly spaced values within [0, 2*np.pi]; in other words, we will plot the function for all theta in [0, 2*π]
r = 2*theta # Let's plot the Archimidian spiral.
plt.polar(theta, r,'b.') # matplotlib.pyplot.polar makes a polar plot.
plt.title("r(theta)=2*theta", va='bottom') # A title for our plot
plt.show()
```

```
import numpy as np # Let's use Python to plot functions in polar coordinates
import matplotlib.pyplot as plt # matplotlib.pyplot provides a MATLAB-like way of plotting.
theta = np.arange(0, 2*np.pi, 0.01) # np.arange() returns the ndarray object containing evenly spaced values within [0, 2*np.pi]; in other words, we will plot the function for all theta in [0, 2*π]
r = 2+3*np.cos(theta) # Let's plot the cardioid.
plt.polar(theta, r, 'b.') # matplotlib.pyplot.polar makes a polar plot.
plt.title("r(theta)=2+3*np.sin(theta)", va='bottom') # A title for our plot
plt.show()
```

Of course, we can *use WolframAlpha to plot functions in polar coordinates*, too, e.g., polar plot r=0.3*theta, theta=0 to 8*Pi, polar plot r=2 +3*sin(theta), theta=0 to 2*Pi, etc.

GeoGebra supports complex numbers, just enter a = 1 + 2i and b = 3 +i. Alternatively, you can select **New Point**, and plot the points A (1, 2) and B(3, 1).

Next, type aux1=Vector[(0, 0), a] and aux2=Vector[(0, 0), b] in the input field. Graphically, select the option **Vector between Two Points** from the menu **Line through Two Points**, and click on the starting point (0, 0) and A (1, 2) (a) and then again click on (0, 0) and B(3, 1) (b).

Let’s draw two parallel lines by selecting the option **Parallel Line** from the menu **Perpendicular Line**. Click on the point B(3, 1) (b) and the vector “aux1” or just type: aux3=Line(b, aux1). Click on the point A(1, 2) (a) and the vector “aux2” or type in the Input field: aux4=Line(a, aux2).

Now, we ask Geogebra to show us the intersection of both parallel lines. Navigate to the menu **New Point, Intersect Two Objects** and click on the lines drawn in the previous step or write *c=Intersect[aux3, aux4]*.

Finally, select the option **Vector between Two Points** from the menu **Line through Two Points**, and click on the starting point (0, 0) and c or type Vector[(0, 0), c]. Observe that A (1, 2) (a, 1 +2i) + B (3, 1) (b, 3 +i) = (4, 3) (c, 4 +3i).

A **parametric equation** defines a group of quantities as functions of one or more independent variables called parameters. It is **a set of equations with more than one dependent variables**, e.g., x = x(t), y = y(t), that defines or specifies the (dependent) variables x and y as functions of a parameter or independent variable t.

```
from sympy import * # Let's plot a parametric equation with Python
import sympy.plotting as plt
t = symbols('t')
x = 0.3*t*cos(t) # cos(t), sin(t), t∈[0, 2*pi] is a circle; 2*cos(t), 3*sin(t), t∈[0, 2*pi] defines a parable. We draw them with FooPlot.
y = 0.3*t*sin(t) # Spirals have the parameter form: x(t) = a*t*cos(t), y(t) = a*t*sin(t), a is a constant.
plt.plot_parametric(x, y, (t, 0, 10*pi)) # Plots 2D parametric plots.
```

```
from sympy import * # Let's plot a parametric equation with Python
import sympy.plotting as plt
import math
t = symbols('t')
x = cos(t) # If you draw a circle with x=cos(t) and y=sin(t) and pull it evenly in z-direction, you get a _cylindrical spiral or helix_.
y = sin(t)
z = t
plt.plot3d_parametric_line(x, y, z, (t, 0, 8*math.pi)) # Plots 3D line plots, defined by a parameter.
```

A torus with major radius R and minor radius r may be defined as: *x = (r Cos(u) + R) Cos(v); y = (r Cos(u) + R) Sin(v); z = r Sin(u), v, u∈[0, 2*pi]*, R = 3, r = 2. Let’s plot it on WolframAlpha: *ParametricPlot3D[{(2 Cos[u]+3) Cos[v], (2 Cos[u]+3) Sin[v], 2 Sin[u]}, {u, 0, 2 Pi}, {v, 0, 2 Pi}]*.

We draw a sphere, too, ParametricPlot3D[{(2sin(v)*cos(u)), 2sin(v)*sin(u), 2cos(v) }, {u, 0, 2 Pi}, {v, 0, 2 Pi}].