Construction of complex numbers
In this demo, we will look at the basic techniques when graphing complex numbers in Engee.
A complex number is a number of the form , where are real numbers, is an imaginary unit . The number is the real part of the complex number and is denoted as . The number is the imaginary part of the complex number and is labelled .
The complex number can be plotted in the Cartesian coordinate system, where its real part is plotted on the abscissa axis and its imaginary part is plotted on the ordinate axis.
Also can be plotted in polar coordinates. To do this, we should refer to its exponential or trigonometric notation .
Hence: the modulus and the argument are respectively the distance from the origin and the radius-vector with the abscissa axis for the complex number .
Construction of the vector of complex numbers
Let's define a vector of complex numbers.
Pkg.add(["LinearAlgebra"])
z = [
3 + 4im,
-4 - 3im,
1 - 2im,
-1 - 1im
];
Let's load the library and connect the backend for plotting.
import Pkg
Pkg.add("Plots")
using Plots;
plotlyjs()
Let's plot the given vector on the complex plane by substituting the real and imaginary parts extracted from z
as coordinates.
scatter(
real.(z), imag.(z),
title="Комплексные числа",
xlabel="Re(z)",
ylabel="Im(z)",
markersize=4,
markercolor=:red,
legend=:topleft,
label="z"
)
When mapping complex numbers, it is not necessary to extract the real and imaginary parts. When passing complex numbers to the functions scatter(z)
or plot(z)
, their coordinates on the complex plane will be determined automatically, as we will see below.
Roots of nth degree from one on the complex plane
For a polynomial of the form , where , we can find the complex roots of according to the Moiré formula:
, where
Let us define the function for calculating the roots:
nthroots(n::Integer) = [ cospi(2k/n) + sinpi(2k/n)im for k = 0:n-1 ]
Find the complex roots of a polynomial of degree n = 5
:
z = nthroots(5)
Let's display the found roots on the complex plane in the Cartesian coordinate system. In this construction we pass to the function scatter()
an array of complex numbers without extracting the real and imaginary parts.
scatter(
z,
title="Корни полинома",
xlabel="Re(z)",
ylabel="Im(z)",
markersize=4,
markercolor=:blue,
legend=:topleft,
label="z"
)
According to the properties of roots of n-th degree from 1, the modulus of complex roots will be equal to 1. To be sure of this, let us proceed to the mapping of these roots in polar coordinates. In this case, the function scatter()
must be passed the arrays of arguments and moduli of complex roots.
scatter(
angle.(z), abs.(z),
proj=:polar,
marker = :circle,
m=4, #markersize
markercolor=:green,
legend=:topleft,
label="z"
)
As follows from the geometric properties of roots of degree 5 of 1, their modules are equal to 1, on the complex plane they are located in the vertices of a regular pentagon with the centre at the origin of coordinates, and one of the roots is equal to the complex unit .
Parametric curve on the complex plane
Let us construct a parametric curve on the complex plane, which is represented by the expression .
The parameter will be defined in the range .
Let's set an array of 200 points of the parameter in the defined range and calculate the array of points of the parametric curve.
t = collect(range(0, 4pi, length=200));
z = t.*exp.(t.*im);
Display the parametric curve on the complex plane in the Cartesian coordinate system:
plot(
z,
title="Параметрическая кривая",
xlabel="Re(z)",
ylabel="Im(z)",
markersize=4,
markercolor=:blue,
legend=:topright,
label="z",
width=3
)
Display the parametric curve on the complex plane in the polar coordinate system:
plot(
angle.(z), abs.(z),
proj=:polar,
legend=:topleft,
label="z",
width=3
)
Eigenvalues of the matrix on the complex plane
For a square matrix there exist eigenvalues that are either valid or are complex-conjugate pairs.
Let us verify this property and display the eigenvalues on the complex plane.
To find the conjugate values, let us load and connect the library LinearAlgebra
:
Pkg.add("LinearAlgebra")
using LinearAlgebra;
Let us find the eigenvalues for the matrix , generated randomly.
z=eigen(rand(20,20));
Let us construct the eigenvalues of the matrix on the complex plane.
scatter(
z.values,
title="Собственные значения",
xlabel="Re(z)",
ylabel="Im(z)",
markersize=4,
markercolor=:magenta,
legend=:topleft,
label="z"
)
As follows from the properties of eigenvalues for a square matrix , 20 points can be observed on the complex plane, which are either located on the axis of real values or represent complex-conjugate pairs.
Several arrays of complex numbers in the plane
Consider the representation of two different sets of complex data on the complex plane. They will be defined by the following expressions:
We define the vector of values of in steps of and compute the arrays of values of and .
x = collect(-2:0.25:2);
z1=Complex.(x).^exp.(-x.^2);
z2=2*Complex.(x).^exp.(-x.^2);
Let's extract real and imaginary parts of numbers for both arrays:
re_z1 = real.(z1);
im_z1 = imag.(z1);
re_z2 = real.(z2);
im_z2 = imag.(z2);
Let us plot two sets of complex numbers on the same plane:
scatter(
re_z1, im_z1,
title="Массивы комплексных чисел",
xlabel="Re(z)",
ylabel="Im(z)",
marker=:cross,
markersize=5,
markercolor=:violet,
legend=:topleft,
label="z1"
)
scatter!(
re_z2, im_z2,
marker=:xcross,
markersize=5,
markercolor=:orange,
label="z2"
)
Conclusion
In this demo, we have looked at various tools and techniques for graphically representing complex numbers in Engee.