clear; close all;clc Imag=input('Enter the AC current peak amplitude (near 1 is best):'); Iphase=input('Enter the AC current initial phase (radians) (better to avoid 0 here):'); Ifreq=input('Enter the AC current frequency (randians/sec):'); disp('Now select the device impedance with left mouse'); disp('Use right mouse over complex plane to exit'); I=Imag*exp(i*Iphase); run=1; while run==1 theta = 0:pi/50:2*pi; uncirc = exp(i.*theta); figure(1) 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); thetaZ=angle(Z); hold off S2=sprintf('V=IZ=%.2f e^{j(%.2f)} %.2f e^{j(%.2f)}',Imag,Iphase,r,thetaZ); h2=text(-1.4,1.25,S2); set(h2,'FontSize',16); S2=sprintf('V=%.2f e^{j(%.2f)}',Imag*r,Iphase+thetaZ); h2=text(-1.4,.75,S2); set(h2,'FontSize',16); figure(2) t=linspace(0,6*pi/Ifreq,1000); current=Imag*cos(Ifreq*t+Iphase); Vmag=Imag*r; Vphase=Iphase+thetaZ; V=Vmag*exp(i*Vphase); x=Vmag*cos(Ifreq*t+Vphase); plot(t,current,'b-',t,x,'g-'); legend('Current i(t)','Voltage v(t)'); grid xlabel('t'); ylabel('v(t) (Volts), i(t) (Amps)'); axis tight; S=sprintf('v(t)=%.2f cos(%2.f t + (%.2f))',Vmag,Ifreq,Vphase); h=text(pi/(2*Ifreq),-.8*Imag,S); set(h,'FontSize',18); S=sprintf('i(t)=%.2f cos(%2.f t + (%.2f))',Imag,Ifreq,Iphase); h=text(pi/(2*Ifreq),.8*Imag,S); set(h,'FontSize',18); figure(3) plot(real(I),imag(I),'b*',X,Y,'r*',real(V),imag(V),'g*'); legend('I','Z','V'); hold on r1=linspace(0,Imag,100); r2=linspace(0,r,100); r3=linspace(0,Vmag,100); plot(r1*exp(i*Iphase),'b-') plot(r2*exp(i*thetaZ),'r-') plot(r3*exp(i*Vphase),'g-') axis equal ylabel('Imaginary Axis'); xlabel('Real Axis'); title('V=IZ'); hold off end