(毕业论文)《控制系统计算机仿真》上机实验报告.doc
兰 州 理 工 大 学控制系统计算机仿真上机实验报告院系: 电信学院 班级: 10级自动化五班 姓名: 学号: 时间: 2013 年 5 月 12 日电气工程与信息工程学院2-2.用MATLAB语言求下列系统的状态方程、传递函数、零极点增益和部分分式形式的模型参数,并分别写出其相应的数学模型表达式:(1)(2) 解:(1)传递函数转化为状态方程: num=1,7,24,24num = 1 7 24 24den=1,10,35,50,24den = 1 10 35 50 24A,B,C,D=tf2ss(num,den)A = -10 -35 -50 -24 1 0 0 0 0 1 0 0 0 0 1 0B = 1 0 0 0C = 1 7 24 24D = 0G2=ss(A,B,C,D) a = x1 x2 x3 x4 x1 -10 -35 -50 -24 x2 1 0 0 0 x3 0 1 0 0 x4 0 0 1 0 b = u1 x1 1 x2 0 x3 0 x4 0 c = x1 x2 x3 x4 y1 1 7 24 24 d = u1 y1 0状态方程为: 传递函数转换为零极点增益:>> num=7,24,24num = 7 24 24den=10,35,50,24den = 10 35 50 24Z,P,K=tf2zp(num,den)Z = -2.7306 + 2.8531i -2.7306 - 2.8531i -1.5388 P = -4.0000 -3.0000 -2.0000 -1.0000K = 1 G1=zpk(Z,P,K) Zero/pole/gain:(s+1.539) (s2 + 5.461s + 15.6)- (s+4) (s+3) (s+2) (s+1)零极点增益方程为:传递函数转换为部分分时形式:>> num=7,24,24num = 7 24 24den=10,35,50,24 den = 10 35 50 24 R,P,H=residue(num,den)R = 4.0000 -6.0000 2.0000 1.0000P = -4.0000 -3.0000 -2.0000 -1.0000H = G3=residue(R,P,H)G3 =1.0000 7.0000 24.0000 24.0000部分分式形式为:(2) 解:状态方程转换为传递函数为:>> A=2.25,-5,-1.25,-0.5;2.25,-4.25,-1.25,-0.5;0.25,-0.5,-1.25,-1;1.25,-1.75,-0.25,-0.75A = 2.2500 -5.0000 -1.2500 -0.5000 2.2500 -4.2500 -1.2500 -0.5000 0.2500 -0.5000 -1.2500 -1.0000 1.2500 -1.7500 -0.2500 -0.7500B=4,2,2,0'B = 4 2 2 0C=0,2,0,2C = 0 2 0 2D=0D = 0num,den=ss2tf(A,B,C,D)num = 0 4.0000 14.0000 19.7500 13.0000den = 1.0000 4.0000 5.8125 4.1562 1.5937G1=tf(num,den) Transfer function: 4 s3 + 14 s2 + 19.75 s + 13-s4 + 4 s3 + 5.812 s2 + 4.156 s + 1.594传递函数为:状态方程转换成零极点:>> A=2.25,-5,-1.25,-0.5;2.25,-4.25,-1.25,-0.5;0.25,-0.5,-1.25,-1;1.25,-1.75,-0.25,-0.75A = 2.2500 -5.0000 -1.2500 -0.5000 2.2500 -4.2500 -1.2500 -0.5000 0.2500 -0.5000 -1.2500 -1.0000 1.2500 -1.7500 -0.2500 -0.7500B=4,2,2,0'B = 4 2 2 0C=0,2,0,2C = 0 2 0 2D=0D = 0Z,P,K=ss2zp(A,B,C,D)Z = -0.8835 + 1.0463i -0.8835 - 1.0463i -1.7331 P = -0.4318 + 0.6803i -0.4318 - 0.6803i -1.6364 -1.5000 K = 4.0000G2=zpk(Z,P,K) Zero/pole/gain:4 (s+1.733) (s2 + 1.767s + 1.875)-(s+1.5) (s+1.636) (s2 + 0.8636s + 0.6493)零极点增益方程为:3)转换成部分分式形式:>> R,P,H=residue(num,den)R = -2.4618 6.2857 0.0880 - 2.5548i 0.0880 + 2.5548iP = -1.6364 -1.5000 -0.4318 + 0.6803i -0.4318 - 0.6803iH = G3=residue(R,P,H)G3 =4.0000 14.0000 19.7500 13.0000部分分式形式的方程为:2-3. 用殴拉法求下列系统的输出响应在上,时的数值解。,要求保留4位小数,并将结果与真解比较。解:(1). >> h=0.1;disp('y=');y=1;for t=0:h:1m=y;disp(y);y=m-m*h;endy= 1 0.9000 0.8100 0.7290 0.6561 0.5905 0.5314 0.4783 0.4305 0.38740.3487(2). >> h=0.1;disp('y=');for t=0:h:1y=exp(-t);disp(y);endy= 1 0.9048 0.8187 0.7408 0.6703 0.6065 0.5488 0.4966 0.4493 0.40660.3679 比较欧拉方法求解与真值的差别欧拉10.90000.81000.72900.65610.59050.53140.47830.43050.38740.3487真值10.90480.81870.74080.67030.60650.54880.49660.44930.40660.3679误差0-0.0048-0.00070.01180.01420.01600.01740.0180.0188-0.0192-0.0192显然误差与h2为同阶无穷小,欧拉法具有一阶计算精度,精度较低,但算法简单2-5. 用四阶龙格库塔法求解2-3的数值解,并与前两题结果比较。解:(1)>> h=0.1;disp('y=');y=1;for t=0:h:1disp(y);K1=-y;K2=-(y+K1*h/2);K3=-(y+K2*h/2);K4=-(y+K3*h);y=y+(K1+2*K2+2*K3+K4)*h/6;endy= 1 0.9048 0.8187 0.7408 0.6703 0.6065 0.5488 0.4966 0.4493 0.40660.3679(2) 比较这几种方法:对于四阶龙格-库塔方法真值10.90480.81870.7408 0.6703 0.6065 0.54880.4966 0.4493 0.40660.3679龙库10.90480.81870.7408 0.6703 0.6065 0.54880.4966 0.44930.40660.3679误差00000000000 显然四阶龙格-库塔法求解精度很高,基本接近真值。三种方法比较可以得到精度(四阶) 精度(二阶) 精度(欧拉)。3-2.设典型闭环结构控制系统如下图所示,当阶跃输入幅值时,用sp3_1.m求取输出y(t)的响应。y(t)r(t)_2 解:>> a=0.016 0.864 3.27 3.42 1;b=30 25;X0=0 0 0 0;V=2;n=4;T0=0;Tf=10;h=0.01;R=20;b=b/a(1);a=a/a(1);A=a(2: n+1);A=rot90(rot90(eye(n-1,n);-fliplr(A);B=zeros(1,n-1),1'm1=length(b);C=fliplr(b),zeros(1,n-m1);Ab=A-B*C*V;X=X0'y=0;t=T0;N=round(Tf-T0)/h);for i=1:N;K1=Ab*X+B*R;K2=Ab*(X+h*K1/2)+B*R;K3=Ab*(X+h*K2/2)+B*R;K4=Ab*(X+h*K3/2)+B*R;X=X+h*(K1+2*K2+2*K3+K4)/6;y=y,C*X;t=t,t(i)+h;endplot(t,y)3-5. 下图中,若各环节的传递函数已知为:但;重新列写联接矩阵和非零元素矩阵,将程序sp3_2.m完善后,应用sp3_2.m求输出的响应曲线。解:P=1 0.01 1 0;0 0.085 1 0.17;1 0.01 1 0;0 0.051 1 0.15;1 0.0067 70 0;1 0.15 0.21 0;0 1 130 0;1 0.01 0.1 0;1 0.01 0.0044 0;W=0 0 0 0 0 0 0 0 0;1 0 0 0 0 0 0 0 -1 ; 0 1 0 0 0 0 0 0 0 ; 0 0 1 0 0 0 0 -1 0;0 0 0 1 0 0 0 0 0 ;0 0 0 0 1 0 0 0 0 ;0 0 0 0 0 1 0 0 0 ;0 0 0 0 0 1 0 0 0 ;0 0 0 0 0 0 1 0 0 ;W0=1;0;0;0;0;0;0;0;0;WIJ=1 0 1;2 1 1;2 9 -1;3 2 1;4 3 1 ;4 8 -1;5 4 1;6 5 1;6 10 -1;7 6 1 ;8 6 1 ;9 7 1;n=9;Y0=1;Yt0=0 0 0 0 0 0 0 0 0 ;h=0.01;L1=1;T0=0;Tf=10;nout=7;A=diag(P(:,1);B=diag(P(:,2);C=diag(P(:,3);D=diag(P(:,4); 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:L1; K1=Ab*Y+b1*Y0 K2=Ab*(Y+h*K1/2)+b1*Y0 K3=Ab*(Y+h*K2/2)+b1*Y0 K4=Ab*(Y+h*K3)+b1*Y0 Y=Y+h*(K1+2*K2+2*K3+K4)/6; end y=y,Y(nout); t=t,t(i)+h*L1;endplot(t,y)3-7.用离散相似法仿真程序sp3_4.m重求上题输出的数据与曲线,并与四阶龙格库塔法比较精度。解:P=1 0.01 1 0;0 0.085 1 0.17;1 0.01 1 0;0 0.051 1 0.15;1 0.0067 70 0;1 0.15 0.21 0;0 1 130 0;1 0.01 0.1 0;1 0.01 0.0044 0; W=0 0 0 0 0 0 0 0 0;1 0 0 0 0 0 0 0 -1; 0 1 0 0 0 0 0 0 0; 0 0 1 0 0 0 0 -1 0;0 0 0 1 0 0 0 0 0 ;0 0 0 0 1 0 -0.212 0 0;0 0 0 0 0 1 0 0 0;0 0 0 0 0 1 0 0 0;0 0 0 0 0 0 1 0 0 ;W0=1;0;0;0;0;0;0;0;0;n=9;Y0=1;Yt0=0 0 0 0 0 0 0 0 0;h=0.01;L1=10;T0=0;Tf=20;nout=7;A=diag(P(:,1);B=diag(P(:,2);C=diag(P(:,3);D=diag(P(:,4);for i=1:n if(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); else end else FI(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); else end end end Y=zeros(n,1);X=Y;y=0;Uk=zeros(9,1);Ub=Uk; t=T0:h*L1:Tf;N=length(t); for k=1:N-1 for l=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)hold onQ=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:L1; K1=Ab*Y+b1*Y0 K2=Ab*(Y+h*K1/2)+b1*Y0 K3=Ab*(Y+h*K2/2)+b1*Y0 K4=Ab*(Y+h*K3)+b1*Y0 Y=Y+h*(K1+2*K2+2*K3+K4)/6; end y=y,Y(nout); t=t,t(i)+h*L1;endt',y'plot(t,y,'*r')3-8.求下图非线性系统的输出响应y(t),并与无非线性环节情况进行比较。y(t)e(t)r(t)=105-5P=0.1 1 0.5 1;0 1 20 0;2 1 1 0;10 1 1 0;WIJ=1 0 1;1 4 -1;2 1 1;3 2 1;4 3 1 ;Z=0 0 0 0;S=0 0 0 0;h=0.01;L1=25;n=4;T0=0Tf=20;nout=4;Y0=10;sp3_8; plot(t,y,'r') hold onZ=4 0 0 0;S=5 0 0 0;sp3_8;plot(t,y,'-')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饱和非线性函数satu.m 为:function Uc=satu(Ur,S1)if(abs(Ur)>=S1)if(Ur>0)Uc=S1;else Uc=-S1;endelse Uc=Ur;end从图中可以清楚的地看出,饱和非线性环节对线性系统输出响应的影响。