# %% # Phase Diagram # 2022-01-25 import numpy as np from numpy.linalg import pinv, inv,det import matplotlib.pyplot as plt # For Plotting import os import math import cmath from scipy.signal import find_peaks from datetime import datetime # %% #print(datetime.now()) print(datetime.now().isoformat(' ', 'seconds')) # %% def phasor(x): print(str(x), "= ",abs(x), "<",cmath.phase(x)*180/(math.pi)) def phasor3(x): print(str(x[0]),"= ",abs(x[0]), "<",cmath.phase(x[0])*180/(math.pi)) print(str(x[1]),"= ",abs(x[1]), "<",cmath.phase(x[1])*180/(math.pi)) print(str(x[2]),"= ",abs(x[2]), "<",cmath.phase(x[2])*180/(math.pi)) def cart(mag,degree): rad=degree*(np.pi/180.) y=complex(mag*(np.cos(rad)),mag*(np.sin(rad)) ) return y # %% def pD(cVar,title,minXY,maxXY): titletext=title x1=np.zeros(2) y1=np.zeros(2) x1[1]=cVar[0].real y1[1]=cVar[0].imag x2=np.zeros(2) y2=np.zeros(2) x2[1]=cVar[1].real y2[1]=cVar[1].imag x3=np.zeros(2) y3=np.zeros(2) x3[1]=cVar[2].real y3[1]=cVar[2].imag xmax=maxXY ymax=maxXY xmin=minXY ymin=minXY fig=plt.figure(figsize=(6,6)) ax=fig.add_subplot(111) ax.plot(x1, y1, c='r', label="a/0") # default marker is dot(.) ax.plot(x2, y2, c='b',label="b/1") # ax.plot(x3, y3,c='g', label="c/2") #ax.scatter(x3, y3, c='r', marker='*',label=label3) plt.title(titletext) # plt.legend(loc = 'upper right') plt.legend(loc = 'lower right') plt.grid() plt.xlabel('Real') plt.ylabel('Imag') plt.xlim(xmin,xmax) plt.ylim(ymin,ymax) plt.show() # %% def pD2(cVar1,cVar2,title1,title2,minXY,maxXY): titletext=title1+ ":solid "+title2+ ":dashed" x11=np.zeros(2) y11=np.zeros(2) x11[1]=cVar1[0].real y11[1]=cVar1[0].imag x12=np.zeros(2) y12=np.zeros(2) x12[1]=cVar1[1].real y12[1]=cVar1[1].imag x13=np.zeros(2) y13=np.zeros(2) x13[1]=cVar1[2].real y13[1]=cVar1[2].imag x21=np.zeros(2) y21=np.zeros(2) x21[1]=cVar2[0].real y21[1]=cVar2[0].imag x22=np.zeros(2) y22=np.zeros(2) x22[1]=cVar2[1].real y22[1]=cVar2[1].imag x23=np.zeros(2) y23=np.zeros(2) x23[1]=cVar2[2].real y23[1]=cVar2[2].imag xmax=maxXY ymax=maxXY xmin=minXY ymin=minXY fig=plt.figure(figsize=(6,6)) ax=fig.add_subplot(111) ax.plot(x11, y11, c='r', label="a/0") # default marker is dot(.) ax.plot(x12, y12, c='b',label="b/1") # ax.plot(x13, y13,c='g', label="c/2") ax.plot(x21, y21, c='r', linestyle='dashed',label="a/0") # default marker is dot(.) ax.plot(x22, y22, c='b',linestyle='dashed',label="b/1") # ax.plot(x23, y23,c='g', linestyle='dashed',label="c/2") #ax.scatter(x3, y3, c='r', marker='*',label=label3) plt.title(titletext) # plt.legend(loc = 'upper right') plt.legend(loc = 'lower right') plt.grid() plt.xlabel('Real') plt.ylabel('Imag') plt.xlim(xmin,xmax) plt.ylim(ymin,ymax) plt.show() # %% def puConverter(PUold,Sold,Snew,Vold,Vnew): PUnew=PUold*(Snew/Sold)*(Vold/Vnew)**2 return PUnew # %% # %% vA=cart(1,0) vB=cart(1,-120) vC=cart(1,120) v3=np.array([[vA],[vB],[vC]]) phasor3(v3) # %% pD(v3,"v3",-2,2) # %% iA=cart(0.7,30) iB=cart(0.7,-90) iC=cart(0.7,150) i3=np.array([[iA],[iB],[iC]]) phasor(iA) phasor3(i3) # %% pD(i3,"i3",-2,2) # %% pD2(v3,i3,"v3","i3",-2,2) # %% # %%