```
In [1]:
```%pylab inline

```
```

A complex number has the property that multipied by itself get a negative answer. For example, if an imaginary number like z could be -1

$$ j \cdot j = -1 $$then, the imaginary operatior $j$ is

$$ j= \sqrt{-1}$$Then, a complex numbers is a number that, when squared gives a negative result.

```
In [2]:
```# initiation and examples
z = complex(3,4)
print('The complex {}, where {} is the real and {} the imaginary part'.format(z, z.real, z.imag))

```
```

A complex number give us the distance to the (0,0) origin and the angle to the positive axis

```
In [3]:
```z = 1+1j # alternative way to complex numbers
dist = abs(z)
angle = np.angle(z, deg = True)
print('distance = {:2.4f}, angle = {} deg'.format(dist, angle))

```
```

```
In [4]:
```# distance with trigonometry formula
dist = np.sqrt( np.power(z.imag,2) + np.power(z.real,2))
# angle in radiants
angle = np.rad2deg(np.arctan(z.imag/z.real))
print('distance = {:2.4f}, angle = {} deg'.format(dist, angle))

```
```

```
In [5]:
```z2 = z * z.conjugate()
np.abs(np.sqrt(z2))

```
Out[5]:
```

It's a plane for complex numbers, where we have real and imaginary axis in the plane. We can think of a complex number as a vector (a,bi) or we can express a complex number in its polar form with its module and angle (m, $\phi$). For example, (3+4j) can be also expressed as (5, 0.9273 rad).

```
In [6]:
```z = (3+4j)
m = np.abs(z)
phi = np.angle(z)
print('cartesian coordinates = ({:0.0f}, {:0.0f})'.format(z.real, z.imag))
print('polar coordinates = ({:0.0f}, {:2.4f})'.format(m, phi))
plt.plot(z.real, z.imag, 'ro', ms =12)
plt.plot([0,z.real],[0, z.imag], 'r-', lw=2)
plt.grid(True)
plt.axis([-5,5,-5,5], option = 'square');

```
```

We can use $m e^{j\phi}$, where $m$ is the distance to the origin, and $\phi$ the angle with the ordinal axis to express any irrational number in a circle with radius m. This alternative way to a complex numbers turns out to be very useful, because there are many cases, like multiplication, where it is easier to deal with exponentials than with standard complex numbers.

Euler's formula also provides a link between trigonometry and imaginary numbers.

$$e^{ \pm j\theta } = \cos \theta \pm j\sin \theta$$It describes the vector from the origin to some point of the circle with radius one. If you want to have larger than one vector, we can use:

$$ m e^{ \pm j\theta } = m \cos \theta \pm m j\sin \theta$$Then, we can have complex waves simply expressed as $m e^{j\theta }$

```
In [7]:
```# trigonometric relation
m = np.abs(z)
phi = np.angle(z)
x = m*np.cos(phi)
y = m*np.sin(phi)
print('({} + {}j) is {}e^{:2.4f}j '.format(z.real, z.imag, m, phi))

```
```

```
In [ ]:
```