clear; close all;clc Imag=input('Enter the AC current peak amplitude:'); Iphase=input('Enter the AC current initial phase (radians):'); 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'); 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); theta=angle(Z); hold off S2=sprintf('V=IZ=%.2f e^{j(%.2f)} %.2f e^{j(%.2f)}',Imag,Iphase,r,theta); h2=text(-1.4,1.25,S2); set(h2,'FontSize',16); S2=sprintf('V=%.2f e^{j(%.2f)}',Imag*r,Iphase+theta); 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+theta; x=Vmag*cos(Ifreq*t+Vphase); plot(t,current,t,x); legend('Current','Voltage'); grid xlabel('t'); ylabel('v(t) (Volts), i(t) (Amps)'); 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); end