Complex Numbers
Contents
rectangular/polar conversions
% example 1 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); % example 2 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); % example 3 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
Using phasors to add sinuosoids
Suppose that
v1 = 20 cos(wt-45 deg) v2 = 10 sin(wt+60 deg) Reduce the sum vs(t) = v1(t) + v2(t) to a single sum. Reference: Hambley, Example 5.3
% first phasor is v1 = phasor2complex(20,-45); fprintf(['v1 ' ctext(v1) '\n' ]); % subtract 90 degree from second phasor because v2 is a sine function 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; %[arrowx arrowy] = dsxy2figxy(gca,[0 real(z1)],[0 imag(z1)]); %annotation('arrow',arrowx,arrowy); %[arrowx arrowy] = dsxy2figxy(gca,[0 real(z2)],[0 imag(z2)]); %annotation('arrow',arrowx,arrowy); figure; plot(t,v1,'b',t,v2,'k','LineWidth',2); axis([-1.5 2.5 -4.5 4.5]); grid

