EE 212 Example 1: Complex Numbers Calculations and Plots in Matlab (Interactive)


Interactive Commands Entered and Matlab's Responses:
>> A = -1 + j*2
A =
  -1.0000 + 2.0000i

>> real(A)
ans =
    -1

>> imag(A)
ans =
     2

>> abs(A)
ans =
    2.2361

>> angle(A)
ans =
    2.0344

>> angle(A)*180/pi
ans =
  116.5651

>> B = 2*exp(pi*j/3)
B =
   1.0000 + 1.7321i

>> A + B
ans =
   0.0000 + 3.7321i

>> B - A
ans =
   2.0000 - 0.2679i

>> C = A*B
C =
  -4.4641 + 0.2679i

>> D = B/A
D =
   0.4928 - 0.7464i
   
>> plot(real(A),imag(A),'ro')
>> hold
Current plot held
>> plot(real(B),imag(B),'gx')
>> plot(real(C),imag(C),'b*')
>> plot(real(D),imag(D),'c+')
>> hold
Current plot released
>> gtext('A')
>> gtext('B')
>> gtext('C')
>> gtext('D')
>> xlabel('Re')
>> ylabel('Im')
>> title('Plot of Complex Numbers in Complex Plane');

Figure/Plot Generated: