Complex Numbers
Contents
rectangular/polar conversions
z = complex(3,4);
rho = abs(z);
theta = angle(z)*180/pi;
fprintf('given: z = complex(3,4)\n');
fprintf('rho %g theta %g\n',rho,theta);
x = 5;
y = 12;
fprintf('given: x %g y %g\n',x,y);
[theta,rho] = cart2pol(x,y);
fprintf('rho %g theta %g\n',rho,theta*180/pi);
rho = 2.0;
theta = 45;
[x,y] = pol2cart(theta*pi/180,rho);
fprintf('given: rho %g theta %g\n',rho,theta);
fprintf('x %g y %g\n',x,y);
given: z = complex(3,4)
rho 5 theta 53.1301
given: x 5 y 12
rho 13 theta 67.3801
given: rho 2 theta 45
x 1.41421 y 1.41421
angle calculations
x = -1;
y = sqrt(3);
theta1 = atan2(y,x)*180/pi;
theta2 = angle(complex(x,y))*180/pi;
if (theta1==theta2)
fprintf('calculations match, theta = %g degrees\n',theta1);
end
calculations match, theta = 120 degrees
Hambley, Example 5.3
v1 = phasor2complex(20,-45);
fprintf(['v1 ' ctext(v1) '\n' ]);
v2 = phasor2complex(10,-30);
fprintf('v2 %s\n', ctext(v2));
vx = v1+v2;
[rho,theta] = complex2phasor(vx);
fprintf('result: rho %g theta %g\n',rho,theta);
v1 14.1421 - 14.1421j
v2 8.66025 - 5j
result: rho 29.772 theta -40.0128
Lagging/Leading
close all
t = linspace(-1.5,2.5,201);
v1 = 3*cos(2*pi*t+40*pi/180);
v2 = 4*cos(2*pi*t-20*pi/180);
z1 = phasor2complex(3,40);
z2 = phasor2complex(4,-20);
plot([0 real(z1)],[0 imag(z1)],'b',[0 real(z2)],[0 imag(z2)],'k');
w = 5;
axis([-w w -w w]);
axis square;
figure;
plot(t,v1,'b',t,v2,'k','LineWidth',2);
axis([-1.5 2.5 -4.5 4.5]);
grid