# -*- coding: utf8 -*- import numpy as np from scipy.integrate import quad from scipy.optimize import * import matplotlib.pyplot as plt T1=14;T2=18;T3=28;T=15;K=0.9;tau=6.4# ( ) fmin=0.004# fmax=0.08# df=0.0001# n=np.arange(fmin,fmax,df)# def W(w):# j=(-1)**0.5 return ((K*(np.exp(-tau*j*w))/((T1*j*w+1)*(T2*j*w+1)*(T3*j*w+1)))) def WO(w):# j=(-1)**0.5 return (1/(K*(T*j*w+1-np.exp(-tau*j*w))/((T1*j*w+1)*(T2*j*w+1)*(T3*j*w+1)))) def ReWO(w):# j=(-1)**0.5 return WO(w).real def ImWO(w):# j=(-1)**0.5 return WO(w).imag S1=[ReWO(w) for w in n] S2=[ImWO(w) for w in n] plt.title(" \n ") plt.xlabel("Re(WO)") plt.ylabel("Im(WO)") plt.plot(ReWO(min(n)),ImWO(min(n)),'o',label=' -(%s,%s)'%(round(ReWO(min(n)),1),round(ImWO(min(n)),1))) plt.plot(ReWO(max(n)),ImWO(max(n)),'o',label=' -B(%s,%s)'%(round(ReWO(max(n)),1),round(ImWO(max(n)),1))) plt.plot(S1,S2) plt.grid(True) plt.legend(loc='best') plt.show()
# -*- coding: utf8 -*- import numpy as np from scipy.integrate import quad from scipy.optimize import * import matplotlib.pyplot as plt import matplotlib as mpl mpl.rcParams['font.family'] = 'fantasy' mpl.rcParams['font.fantasy'] = 'Comic Sans MS, Arial' T1=14;T2=18;T3=28;K=0.9;tau=6.4# , , m=0.366;m1=0.221# n= np.arange(0.001,0.15,0.0002)# Kr-Ki n1=np.arange(0.00001,0.12,0.0001)# Ki=f(w) n2=np.arange(0.0002,0.4,0.0001)# def WO(m,w):# j=(-1)**0.5 return K*np.exp(-tau*(-m+j)*w)/((T1*(-m+j)*w+1)*(T2*(-m+j)*w+1)*(T3*(-m+j)*w+1)) def WR(w,Kr,Ti,Td):# j=(-1)**0.5 return Kr*(1+1/(j*w*Ti)+j*w*Td) def ReW(m,w):# j=(-1)**0.5 return WO(m,w).real def ImW(m,w):# j=(-1)**0.5 return WO(m,w).imag def A0(m,w):# return -(ImW(m,w)*m/(w+w*m**2)+ReW(m,w)/(w+w*m**2)) def Ti(alfa,m,w):# return (-ImW(m,w)-(ImW(m,w)**2-4*((ReW(m,w)*alfa*w-ImW(m,w)*alfa*w*m)*A0(m,w)))**0.5)/(2*(ReW(m,w)*alfa*w-ImW(m,w)*alfa*w*m)) def Ki(alfa,m,w):# return 1/(w*Ti(alfa,m,w)**2*alfa*(m*ReW(m,w)+ImW(m,w))-Ti(alfa,m,w)*ReW(m,w)+(m*ReW(m,w)-ImW(m,w))/(w+w*m**2)) def Kr(alfa,m,w):# if Ki(alfa,m,w)*Ti(alfa,m,w)<0: z=0 else: z=Ki(alfa,m,w)*Ti(alfa,m,w) return z def Kd(alfa,m,w):# return alfa*Kr(alfa,m,w)*Ti(alfa,m,w) alfa=0.2 Ki_1=[Ki(alfa,m1,w) for w in n] Kr_1=[Kr(alfa,m1,w) for w in n] Ki_2=[Ki(alfa,m,w) for w in n] Kr_2=[Kr(alfa,m,w) for w in n] Ki_3=[Ki(alfa,0,w) for w in n] Kr_3=[Kr(alfa,0,w) for w in n] plt.figure() plt.title(" \n alfa=%s"%alfa) plt.axis([0.0, round(max(Kr_3),4), 0.0, round(max(Ki_3),4)]) plt.plot(Kr_1, Ki_1, label=' m=%s'%m1) plt.plot(Kr_2, Ki_2, label=' m=%s'%m) plt.plot(Kr_3, Ki_3, label=' m=0') plt.xlabel(" - Ki") plt.ylabel(" - Kr") plt.legend(loc='best') plt.grid(True) alfa=0.7 Ki_1=[Ki(alfa,0.221,w) for w in n] Kr_1=[Kr(alfa,0.221,w) for w in n] Ki_2=[Ki(alfa,0.366,w) for w in n] Kr_2=[Kr(alfa,0.366,w) for w in n] Ki_3=[Ki(alfa,0,w) for w in n] Kr_3=[Kr(alfa,0,w) for w in n] plt.figure() plt.axis([0.0, round(max(Kr_3),3), 0.0, round(max(Ki_3),3)]) plt.title(" \n alfa=%s"%alfa) plt.plot(Kr_1, Ki_1, label=' m=%s'%m1) plt.plot(Kr_2, Ki_2, label=' m=%s'%m) plt.plot(Kr_3, Ki_3, label=' m=0') plt.xlabel(" - Ki") plt.ylabel(" - Kr") plt.legend(loc='best') plt.grid(True) alfa=1.2 Ki_1=[Ki(alfa,0.221,w) for w in n] Kr_1=[Kr(alfa,0.221,w) for w in n] Ki_2=[Ki(alfa,0.366,w) for w in n] Kr_2=[Kr(alfa,0.366,w) for w in n] Ki_3=[Ki(alfa,0,w) for w in n] Kr_3=[Kr(alfa,0,w) for w in n] plt.figure() plt.title(" \n alfa=%s"%alfa) plt.axis([0.0, round(max(Kr_3),3), 0.0, round(max(Ki_3),3)]) plt.plot(Kr_1, Ki_1, label=' m=%s'%m1) plt.plot(Kr_2, Ki_2, label=' m=%s'%m) plt.plot(Kr_3, Ki_3, label=' m=0') plt.xlabel(" - Ki") plt.ylabel(" - Kr") plt.legend(loc='best') plt.grid(True) plt.figure() plt.title(" \n m=%s"%m) alfa=0.2 Ki_2=[Ki(alfa,m,w) for w in n] Kr_2=[Kr(alfa,m,w) for w in n] plt.plot(Kr_2, Ki_2,label=' allfa=Td/Ti =%s'%alfa) alfa=0.4 Ki_2=[Ki(alfa,m,w) for w in n] Kr_2=[Kr(alfa,m,w) for w in n] plt.plot(Kr_2, Ki_2,label=' allfa=Td/Ti =%s'%alfa) alfa=0.7 Ki_2=[Ki(alfa,m,w) for w in n] Kr_2=[Kr(alfa,m,w) for w in n] plt.plot(Kr_2, Ki_2,label=' allfa=Td/Ti =%s'%alfa) alfa=1.2 Ki_2=[Ki(alfa,m,w) for w in n] Kr_2=[Kr(alfa,m,w) for w in n] plt.plot(Kr_2, Ki_2,label=' allfa=Td/Ti =%s'%alfa) plt.axis([0.0, round(max(Kr_2),3), 0.0, round(max(Ki_2),3)]) plt.legend(loc='best') plt.grid(True) plt.figure() plt.title(" Ki=f(w)") Ki_1=[Ki(0.2,m,w) for w in n1] Ki_2=[Ki(0.7,m,w) for w in n1] Ky=max([round(max(Ki_1),4),round(max(Ki_2),4)]) plt.axis([0.0,round(max(n1),4),0.0, Ky]) plt.plot(n1, Ki_1,label='allfa=Td/Ti =0.2, m=0.366') plt.plot(n1, Ki_2,label='allfa=Td/Ti =0.7, m=0.366') plt.legend(loc='best') plt.grid(True) maxKi=max( [Ki(0.7,m,w) for w in n1]) wa=round([w for w in n1 if Ki(0.7,m,w)==maxKi][0],3) Ki1=round(Ki(0.7,m,wa),3) Kr1=round(Kr(0.7,m,wa),3) Ti1=round(Kr1/Ki1,3) Td1=round(0.7*Ti1,3) d={} d[0]= " โ1 (wa =%s,m=0.366,alfa=0.7): Kr=%s; Ti=%s; Ki=%s; Td=%s "%(wa,Kr1,Ti1,Ki1,Td1) print(d[0]) maxKi=max( [Ki(0.2,m,w) for w in n1]) wa=round([w for w in n1 if Ki(0.2,m,w)==maxKi][0],3) Ki2=round(Ki(0.2,m,wa),3) Kr2=round(Kr(0.2,m,wa),3) Ti2=round(Kr2/Ki2,3) Td2=round(0.2*Ti2,3) d[1]= " โ2 (wa =%s,m=0.366,alfa=0.2): Kr=%s; Ti=%s; Ki=%s; Td=%s "%(wa,Kr2,Ti2,Ki2,Td2) print(d[1]) wa=fsolve(lambda w:Ki(0.7,m,w)-0.14,0.07)[0] wa=round(wa,3) Ki3=round(Ki(0.7,m,wa),3) Kr3=round(Kr(0.7,m,wa),3) Ti3=round(Kr3/Ki3,3) Td3=round(0.7*Ti3,3) d[2]= " โ3 (wa =%s,m=0.366,alfa=0.7): Kr=%s; Ti=%s; Ki=%s; Td=%s "%(wa,Kr3,Ti3,Ki3,Td3) print(d[2]) def Wsys(w,Kr,Ti,Td): j=(-1)**0.5 return (WO(0,w)*WR(w,Kr,Ti,Td)/(1+WO(0,w)*WR(w,Kr,Ti,Td))) Wsys_1=[abs(Wsys(w,Kr1,Ti1,Td1)) for w in n2] Wsys_2=[abs(Wsys(w,Kr2,Ti2,Td2)) for w in n2] Wsys_3=[abs(Wsys(w,Kr3,Ti3,Td3)) for w in n2] plt.figure() plt.title("- \n ") plt.plot(n2, Wsys_1,label=' โ1 ') plt.plot(n2, Wsys_2,label=' โ2 ') plt.plot(n2, Wsys_3,label=' โ3 ') plt.legend(loc='best') plt.grid(True) def ReWsys(w,t,Kr,Ti,Td): return(2/np.pi)* (WO(0,w)*WR(w,Kr,Ti,Td)/(1+WO(0,w)*WR(w,Kr,Ti,Td))).real*(np.sin(w*t)/w) def h(t,Kr,Ti,Td): return quad(lambda w: ReWsys(w,t,Kr,Ti,Td),0,0.6)[0] tt=np.arange(0,300,3) h1=[h(t,Kr1,Ti1,Td1) for t in tt] h2=[h(t,Kr2,Ti2,Td2) for t in tt] h3=[h(t,Kr3,Ti3,Td3) for t in tt] I1=round(quad(lambda t: h(t,Kr1,Ti1,Td1), 0,200)[0],3) I11=round(quad(lambda t: h(t,Kr1,Ti1,Td1)**2,0, 200)[0],3) I2=round(quad(lambda t: h(t,Kr2,Ti2,Td2), 0,200)[0],3) I21=round(quad(lambda t: h(t,Kr2,Ti2,Td2)**2,0, 200)[0],3) I3=round(quad(lambda t: h(t,Kr3,Ti3,Td3), 0,200)[0],3) I31=round(quad(lambda t: h(t,Kr3,Ti3,Td3)**2,0, 200)[0],3) print(" I1 =%s ( โ1)"%I1) print(" I2 =%s ( โ1"%I11) print(" I1 =%s ( โ2 )"%I2) print(" I2 =%s ( โ2)"%I21) print(" I1 =%s ( โ3 )"%I3) print(" I2 =%s ( โ3)"%I31) Rez=[I1+I11,I2+I21,I3+I31] In=Rez.index(min(Rez)) print(" :\n %s"%d[In]) plt.figure() plt.title(" \n ") plt.plot(tt,h1,'r',linewidth=1,label=' โ1 ') plt.plot(tt,h2,'b',linewidth=1,label=' โ2 ') plt.plot(tt,h3,'g',linewidth=1,label=' โ3 ') plt.legend(loc='best') plt.grid(True) plt.show()
# -*- coding: utf8 -*- import numpy as np from scipy.integrate import quad from scipy.optimize import * import matplotlib.pyplot as plt T1=14;T2=18;T3=28;T=15;K=0.9;tau=6.4# T fmin=0.004 fmax=0.08 df=0.0001 n=np.arange(fmin,fmax,df) def W(w):# j=(-1)**0.5 return ((K*(np.exp(-tau*j*w))/((T1*j*w+1)*(T2*j*w+1)*(T3*j*w+1)))) def WO(w):# j=(-1)**0.5 return (1/(K*(T*j*w+1-np.exp(-tau*j*w))/((T1*j*w+1)*(T2*j*w+1)*(T3*j*w+1)))) def WR(w,c1,c2,c3):# j=(-1)**0.5 return (c1+c2/(j*w)+c3*j*w) def NF(c1,c2,c3):# return sum([((WO(w)).real-WR(w,c1,c2,c3).real)**2+((WO(w)).imag-WR(w,c1,c2,c3).imag)**2 for w in n]) def fun2(x): return NF(*x) x0=[1,1,1] res = minimize(fun2, x0) time=np.arange(0,300,1) e1=round(res['x'][0],3) e2=round(res['x'][1],3) e3=round(res['x'][2],3) Kp=round(res['x'][0],3) Ti=round((res['x'][0]/res['x'][1]),3) Ki=round((res['x'][0]/Ti),3) Td=round((res['x'][2]/res['x'][0]),3) print (" :",round(res['fun'],3)) print(" : Kp=%s; Ti=%s; Ki=%s; Td=%s "%(Kp,Ti,Ki,Td)) def h(t,e1,e2,e3): return quad(lambda w:(2/np.pi)*(((W(w))*WR(w,e1,e2,e3))/(1+(W(w))*WR(w,e1,e2,e3))).real*(np.sin(w*t)/w),0,max(n))[0] h1=[h(t,e1,e2,e3) for t in time] I1=round(quad(lambda t:h(t,e1,e2,e3), 0,300)[0],3)+round(quad(lambda t: h(t,e1,e2,e3)**2,0, 300)[0],3) Kp=2.747 Ti=50.87 Td=10.174 Ki=round(Kp/Ti,3) print(" : Kp=%s; Ti=%s; Ki=%s; Td=%s "%(Kp,Ti,Ki,Td)) e1=Kp e2=Kp/Ti e3=Td*Kp print (" [3]:",round(NF(e1,e2,e3),3)) h2=[h(t,e1,e2,e3) for t in time] I2=round(quad(lambda t:h(t,e1,e2,e3), 0,300)[0],3)+round(quad(lambda t: h(t,e1,e2,e3)**2,0, 300)[0],3) plt.title(" ( ) \n ") plt.plot(time,h1,'b',linewidth=2,label=' - %s ( )'%I1) plt.plot(time,h2,'g',linewidth=2,label=' - %s ( )'%I2) plt.legend(loc='best') plt.grid(True) plt.show()
# -*- coding: utf8 -*- import numpy as np from scipy.integrate import quad from scipy.optimize import * import matplotlib.pyplot as plt T1=14;T2=18;T3=28;T=15;K=0.9;tau=6.4 fmin=0.004 fmax=0.08 df=0.0001 n=np.arange(fmin,fmax,df) def W(w):# j=(-1)**0.5 return ((K*(np.exp(-tau*j*w))/((T1*j*w+1)*(T2*j*w+1)*(T3*j*w+1)))) def WO(w):# j=(-1)**0.5 return (1/(K*(T*j*w+1-np.exp(-tau*j*w))/((T1*j*w+1)*(T2*j*w+1)*(T3*j*w+1)))) def WR(w,c1,c2,c3,c4):# j=(-1)**0.5 return (c1+c2/(j*w)+c3*j*w-c4*w**2) def NF(c1,c2,c3,c4): return sum([((WO(w)).real-WR(w,c1,c2,c3,c4).real)**2+((WO(w)).imag-WR(w,c1,c2,c3,c4).imag)**2 for w in n]) def fun2(x): return NF(*x) x0=[1,1,1,1] res = minimize(fun2, x0) time=np.arange(0,300,1) e1=round(res['x'][0],3) e2=round(res['x'][1],3) e3=round(res['x'][2],3) e4=round(res['x'][3],3) print (" :",round(res['fun'],3)) def h(t,e1,e2,e3,c4): return quad(lambda w:(2/np.pi)*(((W(w))*WR(w,e1,e2,e3,e4))/(1+(W(w))*WR(w,e1,e2,e3,e4))).real*(np.sin(w*t)/w),0,max(n))[0] h1=[h(t,e1,e2,e3,e4) for t in time] I1=round(quad(lambda t:h(t,e1,e2,e3,e4), 0,300)[0],3)+round(quad(lambda t: h(t,e1,e2,e3,e4)**2,0, 300)[0],3) plt.title(" ") plt.plot(time,h1,'r',linewidth=2,label=' - %s'%I1) plt.legend(loc='best') plt.grid(True) plt.show()
Source: https://habr.com/ru/post/350030/
All Articles