2.8: Complex Numbers
- Page ID
- 84384
By Carey A. Smith
The imaginary unit number is i.
i = sqrt(-1) or i^2 = -1
In engineering, j is often used instead of i for the imaginary unit number.
In MATLAB, you can use either i or j.
Therefore, i and j should not be used as variable names. Instead, use ii or jj or another letter.
In MATLAB, 2*i can be written as 2i, 3*i as 3i, etc. Try this.
A complex number has both a real part and an imaginary part.
a = 2 + i
b = 1 - 4i
c = -2 + 3j
Solution
Add example text here.
% (1 pt) Write a MATLAB m-file script that does the following:
% (1 pt) Define this complex number:
z1 = (2 + 3i)
% (2 pts) Separate the real and imaginary parts like this:
z1_real = real(z1)
z1_imag = imag(z1)
% (1 pt) Compute the conjugate of z1 with this line of code:
z2 = conj(z1) % This changes the sign on the imaginary part
% (1 pt) Compute:
z1*conj(z1) % Note that this = square of the real part + square of the imaginary part
% (1 pt) Compute the length of this vector:
z1_length = sqrt(z1*conj(z1))
- Answer
-
z2 = conj(z1) = 2 - 3i
z1*conj(z1) = 13
z1_length = 3.6056
% (3 pts) A complex number can be plotted by letting zx = real(z1) and zy = imag(z1)
% Plot this complex number with these lines of code:
figure;
plot(z1_real,z1_imag,'*')
grid on % Draw x & y grid lines
xlim([-1,4]) % Set the minimum and maximum x values
ylim([-1,4]) % Set the minimum and maximum y values
- Answer
-
Add texts here. Do not delete this text first.
Draw a line from (0,0) to the point with the following code:
hold on % Keep whats been plotted and add to it
plot([0,z1_real],[0,z1_imag])
% [0,z1_real] = x coordinates of start and and end of the line
% [0,z1_imag] = y coordinates of start and and end of the line
Solution
Add example text here.