%% Use left mouse to select a phasor value %% Use right mouse to exit pz=figure('Name','Complex Plane','Position',[250 400 500 450]); run=1; while run==1 theta = 0:pi/50:2*pi; uncirc = exp(i.*theta); figure(pz) hold on; nl=-1.4:.2:1.4; plot(nl + i*.0001,'g'), plot(.0001+ i.*nl,'g'), for n=-1.4:.2:1.4, plot(nl + i*(n+.0001),'b'), plot(n + i.*nl,'b'), end plot(uncirc,'g') plot(nl + i*.0001, 'g'), plot(.0001+ i*nl, 'g'), axis('square'); axis([-1.5,1.5,-1.5,1.5]); xlabel('Real'); ylabel('Imaginary'); [X,Y,BUTTON] = ginput(1); Z=X+i*Y; clf; if BUTTON==3 close all break end plot(X,Y,'rx'); r=abs(Z); theta=angle(Z); hold off if imag(Z) >0 S2=sprintf('V=%.2f e^{j%.2f}=%.2f + j %.2f',r,theta,real(Z),abs(imag(Z))); h2=text(-1,1.25,S2); set(h2,'FontSize',18); else S2=sprintf('V=%.2f e^{-j%.2f}=%.2f - j %.2f',r,abs(theta),real(Z),abs(imag(Z))); h2=text(-1,1.25,S2); set(h2,'FontSize',18); end figure(2) w=2*pi; t=0:.05:5; x=r*cos(w*t+theta); plot(t,x); axis([0,5,-2,2]); grid xlabel('t'); ylabel('v(t)'); title('f=1 Hz, \omega=2\pi rads/sec'); if theta >0 S=sprintf('v(t)=%.2f cos(6.28t + %.2f)',r,theta); h=text(1.1,1.75,S); set(h,'FontSize',18); else S=sprintf('v(t)=%.2f cos(6.28t - %.2f)',r,abs(theta)); h=text(1.1,1.75,S); set(h,'FontSize',18); end end