Complex Number; An Overview

Complex Number; An Overview

What is Complex Number

The term complex number sounds complex but it isn't at all. Data types in any programming language are the format or the identity of any input and in python, these format varies from Numbers, String, Boolean to mention a few. From the term complex number, we can deduce that it's classified as a Number data type but it's not your regular number (winks).

The different Number data types include the

  • integer which denotes a whole number
  • Float which contains a decimal point
  • And lastly, Complex number.

Complex Numbers are derived from real numbers with a combination of imaginary numbers. An imaginary number is represented

2i in mathematics but in python, the j denotes it. In python, an imaginary number is any number with the j i.e 3j, 5j, 10.2j.

Safe to say Complex Numbers are Imaginary numbers. It is important to note that complex numbers can be represented in an integer format

2j, 4+6j

Also in the float format

5.3j, 10.0j, 3+4.5j

Formation of Complex Number

They are formed from real numbers. Imagine calculating the square root of a negative number.

from math import sqrt

sqrt(-1)
ValueError                                Traceback (most recent call last)
<ipython-input-2-3b3751bd173e> in <module>
      1 from math import sqrt
----> 2 sqrt(-1)

ValueError: math domain error

We got an error message indicating a math domain error. Reasonable because the square root of any negative number is an imaginary number but can be calculated in python using a module called cmath.

import cmath
cmath.sqrt(-1) 

1j

The cmath modules also known as complex mathematics is used to generate complex numbers.

How to use Complex Number

It's important to note that complex numbers can be written in 2 forms

  • as an imaginary number alone 2j or 5.2j or -5j

  • in combination with a real number 3+8j, 5.2+6.4j. These combinations are also referred to as complex numbers.

We can add, subtract, multiply and divide them like normal numbers.

c1 = 6j
c2 = 4j
​
print(c1+c2)  #addition of complex numbers
10j

print (c1-c2)  #substraction
2j

print(c1*c2)   #multiplication
(-24+0j)

print(c1/c2)    #division
(1.5+0j)

Complex Numbers doesn't support operators like

>,<,>=,<=

and returns an error message if used.

The following functions can be performed on Complex Number ;

  • Power and log Functions
  • Trigonometric Functions
  • Hyperbolic Functions

Complex Number could also be plotted on a polar plot using the Matpltlib Library.

I hope you now have a basic understanding of what a complex number is.

Thank you for reading, see you next time...