Mathematic 2
Mathematic 2
9- Complex Numbers
Complex numbers consist of two separate parts: a real part and an imaginary part. The
basic imaginary unit is equal to the square root of -1. This is represented in MATLAB by
either of two letters: i or j.
>> i
ans =
0.0000 + 1.0000i
>> j
ans =
0.0000 + 1.0000i
>> sqrt(-1)
ans =
0.0000 + 1.0000i
>> z=2+3i
z =
2.0000 + 3.0000i
>> z=-4-5j
z =
-4.0000 - 5.0000i
Another way to create a complex number is using the complex function. This function
combines two numeric inputs into a complex output, making the first input real and the
second imaginary.
>> x = 4;
>> y = -2;
>> z = complex(x,y)
z =
4.0000 - 1.0000i
6
Mathematics II – Practical (Matlab) IT Department First Stage \ Second Semester
>> z1=2+3i;
>> z2=4-5i;
>> z1+z2
ans =
6.0000 - 2.0000i
>> z1-z2
ans =
-2.0000 + 8.0000i
>> z1*z2
ans =
23.0000 + 2.0000i
>> z1/z2
ans =
-0.1707 + 0.5366i
>> x=real(z)
x =
6
>> y=imag(z)
y =
-8
7
Mathematics II – Practical (Matlab) IT Department First Stage \ Second Semester
Also, the function conj(z) computes the complex conjugate of the complex number z,
and the function abs(z) computes the absolute value of z:
>> z=3+4i;
>> conj(z)
ans =
3.0000 - 4.0000i
>> abs(z)
ans =
5
10 - Display Format
MATLAB has several different screen output formats for displaying numbers. These
formats can be found by typing the help command: help format in the Command Window.
A few of these formats are shown in Table