Imaginary Numbers

Imaginary Numbers#

Imaginary numbers allow us to find an answer to the question “what is the square root of a negative number?”. We define \(i\) to be the square root of minus one.

\[ i = \sqrt{-1} \]

We find the other square roots of a negative number, say \(-x\), as follows:

\[ \sqrt{-x} = \sqrt{x \times -1} = \sqrt{x} \times \sqrt{-1} = \sqrt{x} \times i \]

Example

Find the square root of:

  1. \(\sqrt{-9}\)

  2. \(\sqrt{-13}\)

Solution:

  1. \(\sqrt{-9} = \sqrt{9\times -1} = \sqrt{9}\times\sqrt{-1} = 3i\)

  2. \(\sqrt{-13} = \sqrt{13\times -1} = \sqrt{13}\times\sqrt{-1} = \sqrt{13}i\)


Using NumPy, it is necessary for the input to be a complex number to produce the correct result.

import numpy as np

np.sqrt(-9 + 0j)
3j
np.sqrt(-13 + 0j)
3.605551275463989j

We can check that \(3.6055\ldots\) is equal to \(\sqrt{13}\).

np.sqrt(-13 + 0j) == np.sqrt(13) * 1j
True

If a non-complex input is provided, np.sqrt will return a nan.

np.sqrt(-9)
/tmp/ipykernel_2334/2149185541.py:1: RuntimeWarning: invalid value encountered in sqrt
  np.sqrt(-9)
nan