习题3.4 m=2;n=3; A=[-1.174 -0.452 0.644]; B=[0.014 0.009 -0.005]; R=zeros(m+1,1); Y=zeros(n,1); T=0.2; M=100; yt=0;t=0; for k=1:M R(k)=1; R=[R(k);R(1:m)]; yk=-A*Y+B*R; Y=[yk;Y(1:n-1)]; yt=[yt,yk]; t=[t,k*T]; end plot(t,yt,'*k'); grid; xlabel('time(s)'); ylabel('y(kT)'); num=[0.014 0.009 -0.005]; den=[1 -1.174 -0.452 0.644]; dstep(num,den);grid; m=2;n=3; A=[-1.479 0.114 0.375]; B=[0.008 0.005 -0.003]; R=zeros(m+1,1); Y=zeros(n,1); T=0.2; M=100; yt=0;t=0; for k=1:M R(k)=1; R=[R(k);R(1:m)]; yk=-A*Y+B*R; Y=[yk;Y(1:n-1)]; yt=[yt,yk]; t=[t,k*T]; end plot(t,yt,'*k'); grid; xlabel('time(s)'); ylabel('y(kT)'); num=[0.008 0.005 -0.003]; den=[1 -1.479 0.114 0.375]; dstep(num,den);grid; 习题3.5 h=0.01; T1=1;T2=4; A=[-1/T1 0;1/T2 -1/T2]; B=[1/T1;0]; [G,H]=c2d(A,B,h); c=[0 1];T=0.1; N=round(T/h); TF=15; M=round(TF/T); x=[0;0]; u=1;t=0; xt=x; for i=1:M y=c*x; r(i)=1; e(i)=r(i)-y; if(i==1) u=u+15.2*e(i); else u=u+15.2*e(i)-15*e(i-1); end for j=1:N x=G*x+H*u; xt=[xt,x]; t=[t,j*h+(i-1)*T]; end end x1t=xt(1,:);x2t=xt(2,:); plot(t,x2t,'k');grid; 双循环的解 1.6 1.41.210.80.60.40.20051015simulink的解 1.510.5 0012345678910