控制系统计算机仿真大作业.pdf
控制系统计算机仿真大作业控制系统计算机仿真大作业一、已知一阶系统的微分方程为:dy2y 10dt初始条件y(t0)y01,取仿真步长h=0.1,分别用欧拉法、梯形法和龙格 库塔法计算该系统仿真三步的值。解:原方程可变为:dy102ydtf(tk,yk)102yk即y01(1)用欧拉法计算根据欧拉公式,将函数表达式及其初始值代入后,可得该系统仿真第一步的值:y1 y0 hf(t0,y0)1 0.1(10 2 1)1.8(2)用梯形法计算:根据预报校正公式,将函数表达式及其初始值代入后,可得仿真第一步的值。用预报公式求起始值:y(0)1 y0 hf(t0,y0)10.1(1021)1.8再用校正公式得到系统仿真第一步的值:1y1 y0h f(t0,y0)f(t1,y(0)1)2110.1(1021)(1021.8)21.72(3)用二阶龙格库塔法计算根据公式先计算出两个系数,再计算仿真第一步的值:k1 f(t0,y0)102 y010218k2 f(t0h,y0hk1)102(y0hk1)102(10.18)6.4则系统仿真第一步的值为:hy1 y0(k1k2)2110.1(86.4)21.72(4)用四阶龙格库塔公式计算根据公式先计算出 4 个系数,再计算仿真第一步的值:k f(t h,y hk)3002k1 f(t0,y0)102y010218hhk2 f(t0,y0k1)22h102(y0k1)21102(10.18)2 7.222k4 f(t0h,y0hk3)102(y0hk3)102(10.17.28)6.544h102(y0k2)21102(10.17.2)2 7.28则系统仿真第一步的值为:hy1 y0(k12k22k3k4)6110.1(827.227.286.544)61.725067二、实验一 控制系统 MATLAB 仿真分析系统的结构图如下图所示。1、建立该系统的数学模型,可取 k=1G1=tf(0.7,1);G2=tf(1,1 0.3 1);G3=tf(0.4,1);G4=tf(0.4,2,1.2);G5=tf(1,1);Sys=append(G1,G2,G3,G4,G5);Q=1 5 0;2 1 4;3 2 0;4 3 0;5 2 0;INPUTS=1;OUTPUTS=2;G=connect(Sys,Q,INPUTS,OUTPUTS)Transfer function:0.7 s+0.42-s3+0.9 s2+0.48 s+0.1num=0.7 0.42;den=1 0.9 0.48 0.1;sys=tf(num,den)2、对系统进行时间响应分析:求其(1)阶跃响应函数(2)脉冲响应函数(3)给定输入 u=sin(t)cos(t)的响应函数t=0:0.01:10u=0.5*sin(2*t)lsim(sys,u,t)(4)极点和零点z=tzero(sys)z,gain=tzero(sys)pzmap(sys)p,z=pzmap(sys)p=pole(G)p=-0.2764+0.4601i -0.2764-0.4601i -0.3471 z=tzero(G)z=-0.6000(5)闭环系统的阻尼系数和固有频率 wn,zeta=damp(G)wn=0.3471 0.5367 0.5367zeta=1.0000 0.5150 0.5150(6)时域响应的稳态增益 k=dcgain(G)k=4.20003、系统频率响应分析(1)频域特性j=sqrt(-1)w=0:0.01:10Gw=polyval(num,j*w)./polyval(den,j*w)mag=abs(Gw)pha=angle(Gw)(2)Bode 图 bode(sys)(3)极坐标绘图函数(Nyquist 图)nyquist(sys)(4)幅值裕度和相角裕度 Gm,Pm,Wcg,Wcp=margin(G)Gm 为幅值裕度,20*log10(Gm)表示幅值裕度;Wcg 为幅值裕度对应的频率;Pm 为相角裕度;Wcp 为相角裕度对应的频率(穿越频率)Gm=InfPm=24.5068Wcg=InfWcp=0.96803、线性系统的根轨迹分析(1)绘制根轨迹rlocus(G)(2)主导极点的等 线和等 n 线sgrid(0.5,2,new)实验二、控制系统 MATLAB 仿真综合校正设单位反馈控制系统的开环传递函数为:。要求系统的稳态误差为Kv 100 s1原系统的伯德图,相角裕度 55,幅值裕度20lg Kg10dB,试确定该系统的校正装置。(使用频率法)幅值裕度和相角裕度首先根据稳态误差求开环增益,据题意可令K=10no1=10;do1=0.1 1 0;bode(no1,do1);grid onhold ongm,pm,wg,wp=margin(no1,do1)gm=Infpm=51.8273wg=Infwp=7.8615(2)设计超前校正装置相位裕度c17.54 5500。设计超前校正装置Gcs0.45s 10.11s 1nc=0.45 1;dc=0.11 1;bode(nc,dc);%超前校正装置的伯德图(3)分析校正后的系统no2=conv(no1,nc);do2=conv(do1,dc);bode(no2,do2);gm1,pm1,wg1,wp1=margin(no1,do1);gm1,pm1,wg1,wp1 gm2,pm2,wg2,wp2=margin(no2,do2);gm2,pm2,wg2,wp2ans=Inf 51.8273 Inf 7.8615ans=Inf 48.6727 Inf 17.74054)求校正前后系统的单位阶跃响应,体会超前校正对系统动态性能的改善。nc1,dc1=cloop(no1,do1);nc2,dc2=cloop(no2,do2);subplot(121);step(nc1,dc1);subplot(122);step(nc2,dc2);三、下图中,若各环节传递函数已知为:G1(s)110.17s,G2(s)1 0.01s0.085s10.15s0.210.10.0044,G4(s),G5(s),G6(s),但G3(s)0.0 5 1 s10.15s10.01s10.01sG7(s)0.212;试列写链接矩阵W、W0和非零元素阵 WIJ,并应用提供的程序求输出y4的响应曲线。(复杂连接的仿真)(用离散相似法仿真程序重求本题输出y4的数据与曲线,并与四阶龙格库塔法比较精度。)y0G1(s)G2(s)首先写出各环节输入输出关系:u1=y0u2=y1-y6u3=y2-y5u4=y3-0.212y4u5=y4u6=y4程序 sp4_2:P=1,0.01,1,0;0,0.085,1,0.17;0,0.051,1,0.15;1.04452,0.15,0.21,0;1,0.01,0.1,0;1,0.01,0.0044,0;WIJ=1,0,1;2,1,1;2,6,-1;3,2,1;3,5,-1;4,3,1;5,4,1;6,4,1;n=6;Y0=20;Yt0=0,0,0,0,0,0;h=0.01;y4G3(s)G5(s)G4(s)G7(s)G6(s)L1=10;T0=0;Tf=50;nout=4;A=diag(P(:,1);B=diag(P(:,2);C=diag(P(:,3);D=diag(P(:,4);m=length(WIJ(:,1);W0=zeros(n,1);W=zeros(n,n);for k=1:mif(WIJ(k,2)=0);W0(WIJ(k,1)=WIJ(k,3);else W(WIJ(k,1),WIJ(k,2)=WIJ(k,3);end;end;Q=B-D*W;Qn=inv(Q);R=C*W-A;V1=C*W0;Ab=Qn*R;b1=Qn*V1;Y=Yt0;y=Y(nout);t=T0;N=round(Tf-T0)/(h*L1);for i=1:N;for j=1:L1k1=Ab*Y+b1*Y0;k2=Ab*(Y+k1*h/2)+b1*Y0;k3=Ab*(Y+k2*h/2)+b1*Y0;k4=Ab*(Y+h*k3)+b1*Y0;Y=Y+(k1+2*k2+2*k3+k4)*h/6;end;y=y,Y(nout);t=t,t(i)+h*L1;end;t,y;plot(t,y)离散相似法 sp4_3:P=1,0.01,1,0;0,0.085,1,0.17;0,0.051,1,0.15;1.04452,0.15,0.21,0;1,0.01,0.1,0;1,0.01,0.0044,0;WIJ=1,0,1;2,1,1;2,6,-1;3,2,1;3,5,-1;4,3,1;5,4,1;6,4,1;n=6;Y0=20;Yt0=0,0,0,0,0,0;h=0.01;L1=10;T0=0;Tf=50;nout=4;A=diag(P(:,1);B=diag(P(:,2);C=diag(P(:,3);D=diag(P(:,4);m=length(WIJ(:,1);W0=zeros(n,1);W=zeros(n,n);for k=1:mif(WIJ(k,2)=0);W0(WIJ(k,1)=WIJ(k,3);else W(WIJ(k,1),WIJ(k,2)=WIJ(k,3);end;end;for i=1:nif(A(i,i)=0);FI(i,i)=1;FIM(i,i)=h*C(i,i)/B(i,i);FIJ(i,i)=h*h*C(i,i)/B(i,i)/2;FIC(i,i)=1;FID(i,i)=0;if(D(i,i)=0);FID(i,i)=D(i,i)/B(i,i);elseendelse FI(i,i)=exp(-h*A(i,i)/B(i,i);FIM(i,i)=(1-FI(i,i)*C(i,i)/A(i,i);FIJ(i,i)=h*C(i,i)/A(i,i)-FIM(i,i)*B(i,i)/A(i,i);FIC(i,i)=1;FID(i,i)=0;if(D(i,i)=0);FIC(i,i)=C(i,i)/D(i,i)-A(i,i)/B(i,i);FID(i,i)=D(i,i)/B(i,i);elseendendend Y=zeros(n,1);X=Y;y=0;Uk=zeros(n,1);Ub=Uk;t=T0:h*L1:Tf;N=length(t);for k=1:N-1for i=1:L1 Ub=Uk;Uk=W*Y+W0*Y0;Udot=(Uk-Ub)/h;Uf=2*Uk-Ub;X=FI*X+FIM*Uk+FIJ*Udot;Y=FIC*X+FID*Uf;end y=y,Y(nout);end plot(t,y,*r);hold onP=1,0.01,1,0;0,0.085,1,0.17;0,0.051,1,0.15;1.04452,0.15,0.21,0;1,0.01,0.1,0;1,0.01,0.0044,0;WIJ=1,0,1;2,1,1;2,6,-1;3,2,1;3,5,-1;4,3,1;5,4,1;6,4,1;n=6;Y0=20;Yt0=0,0,0,0,0,0;h=0.01;L1=10;T0=0;Tf=50;nout=4;A=diag(P(:,1);B=diag(P(:,2);C=diag(P(:,3);D=diag(P(:,4);m=length(WIJ(:,1);W0=zeros(n,1);W=zeros(n,n);for k=1:mif(WIJ(k,2)=0);W0(WIJ(k,1)=WIJ(k,3);else W(WIJ(k,1),WIJ(k,2)=WIJ(k,3);end;end;Q=B-D*W;Qn=inv(Q);R=C*W-A;V1=C*W0;Ab=Qn*R;b1=Qn*V1;Y=Yt0;y=Y(nout);t=T0;N=round(Tf-T0)/(h*L1);for i=1:N;for j=1:L1k1=Ab*Y+b1*Y0;k2=Ab*(Y+k1*h/2)+b1*Y0;k3=Ab*(Y+k2*h/2)+b1*Y0;k4=Ab*(Y+h*k3)+b1*Y0;Y=Y+(k1+2*k2+2*k3+k4)*h/6;end;y=y,Y(nout);t=t,t(i)+h*L1;end;t,y;plot(t,y)两图比较离散相似法的精度比四阶龙格-库塔法精度低四、设典型闭环结构控制系统如下图所示,当阶跃输入幅值R 20时,用 sp4_1.m 求取输出 y(t)的响应。y(t)r(t)1.875106s1.562106_s454s3204.2s2213.8s63.50.002程序:r=20;numo=1.875e6 1.562e6;deno=1 54 204.2 213.8 63.5;numh=0.002;denh=1;num,den=feedback(numo,deno,numh,denh);A,b,C,D=tf2ss(num,den);Tf=5;h=0.02;x=zeros(length(A),1);y=0;t=0;for i=1:Tf/hK1=A*x+b*r;K2=A*(x+h*K1/2)+b*r;K3=A*(x+h*K2/2)+b*r;K4=A*(x+h*K3)+b*r;x=x+h*(K1+2*K2+2*K3+K4)/6;y=y;C*x;t=t;t(i)+h;endplot(t,y)五、求下图非线性系统的输出响应y(t),并与无非线性环节情况进行比较。-5e(t)s0.5r(t)=10y(t)205s0.1s(s2)(s10)解:解:(1)不考虑非线性环节影响时,求解过程如下:1)先将环节编号标入图中。2)在 MATLAB命令窗口下,按编号依次将环节参数输入P 阵;P=0.1 1 0.5 1;0 1 20 0;2 1 1 0;10 1 1 0;P=0.1 1 0.5 1;0 1 20 0;2 1 1 0;10 1 1 0;3)按各环节相对位置和联接关系,有联接矩阵如下:01W 0010 0 11100 0 0,W0,所以非零元素矩阵W 2I J01 0 0 30 1 00 4014 11 1213 1 WIJ=1 0 1;1 4-1;2 1 1;3 2 1;4 3 1;WIJ=1 0 1;1 4-1;2 1 1;3 2 1;4 3 1;4)由于不考虑非线性影响,则非线性标志向量和参数向量均应赋零值;Z=0 0 0 0;S=0 0 0 0;Z=0 0 0 0;S=0 0 0 0;5)输入运行参数:开环截至频率L1c约为 1,故计算步长 h 取经验公式值,即h 1 0.02,取 h=0.01;每 0.25 秒输出一点。故取L1=25。50ch=0.01;L1=25;n=4;T0=0Tf=20;nout=4;Y0=10;sp4_4;plot(t,y,r)hold on运行结果如图中红色实线所示。(2)考虑非线性环节 N 影响时,只需将非线性标志向量 Z 和参数向量 S 的相应分量正确输入即可。在 MATLAB 命令窗口中输入下列语句:Z=4 0 0 0;S=5 0 0 0;sp4_4;plot(t,y,-)运行结果如图中蓝色虚线所示。从图中可以清楚的地看出,饱和非线性环节对线性系统输出响应的影响。附:sp4_4 函数为:A=P(:,1);B=P(:,2);C=P(:,3);D=P(:,4);m=length(WIJ(:,1);W0=zeros(n,1);W=zeros(n,n);for k=1:mif(WIJ(k,2)=0);W0(WIJ(k,1)=WIJ(k,3);else W(WIJ(k,1),WIJ(k,2)=WIJ(k,3);end;end;for i=1:nif(A(i)=0);FI(i)=1;FIM(i)=h*C(i)/B(i);FIJ(i)=h*h*(C(i)/B(i)/2;FIC(i)=1;FID(i)=0;if(D(i)=0);FID(i)=D(i)/B(i);elseendelseFI(i)=exp(-h*A(i)/B(i);FIM(i)=(1-FI(i)*C(i)/A(i);FIJ(i)=h*C(i)/A(i)-FIM(i)*B(i)/A(i);FIC(i)=1;FID(i)=0;if(D(i)=0);FIC(i)=C(i)/D(i)-A(i)/B(i);FID(i)=D(i)/B(i);elseendendendY=zeros(n,1);X=Y;y=0;Uk=zeros(n,1);Ubb=Uk;t=T0:h*L1:Tf;N=length(t);for k=1:N-1for i=1:L1Ub=Uk;Uk=W*Y+W0*Y0;for i=1:nif(Z(i)=0)if(Z(i)=1)Uk(i)=satu(Uk(i),S(i);endif(Z(i)=2)Uk(i)=dead(Uk(i),S(i);endif(Z(i)=3)Uk(i),Ubb(i)=backlash(Ubb(i),Uk(i),Ub(i),S(i);endendendUdot=(Uk-Ub)/h;Uf=2*Uk-Ub;X=FI.*X+FIM.*Uk+FIJ.*Udot;Yb=Y;Y=FIC.*X+FID.*Uf;for i=1:nif(Z(i)=0)if(Z(i)=4)Y(i)=satu(Y(i),S(i);endif(Z(i)=5)Y(i)=dead(Y(i),S(i);endif(Z(i)=6)Y(i),Ubb(i)=backlash(Ubb(i),Y(i),Yb(i),S(i);endendendendy=y,Y(nout);end