2022年部分源程序清单 .pdf
部分源程序清单D-9-1:stepchar() 计算时域响应的性能指标function pos,tr,ts,tp=stepchar(g0,delta) y,t=step(g0); mp,ind=max(y); dimt=length(t); yss=y(dimt); pos=100*(mp-yss)/yss; tp=t(ind); for i=1:dimt if y(i)=1 tr=t(i); break; end end; for i=1:length(y) if y(i)=(1+delta)*yss ts=t(i); end end D-9-2: hurwitz() 由特征多项式构造胡尔维茨矩阵function H=hurwitz(den) n=length(den)-1; for i=1:n, i1=floor(i/2); if i=i1*2, hsub1=den(1:2:n+1); i1=i1-1; else, hsub1=den(2:2:n+1); end l1=length(hsub1); H(i,:)=zeros(1,i1),hsub1,zeros(1,n-i1-l1); end D-9-3: routh() 由特征多项式构造劳斯阵列表function rtab,info=routh(den) info=; vec1=den(1:2:length(den); nrT=length(vec1); vec2=den(2:2:length(den)-1); rtab=vec1; vec2, zeros(1,nrT-length(vec2); for k=1:length(den)-2, alpha(k)=vec1(1)/vec2(1); for i=1:length(vec2), a3(i)=rtab(k,i+1)-alpha(k)*rtab(k+1,i+1); end if sum(abs(a3)=0 a3=polyder(vec2); info=info,All elements in row ,. 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 8 页 - - - - - - - - - int2str(k+2) are zeros; elseif abs(a3(1)eps a3(1)=1e-6; info=info,Replaced first element; end rtab=rtab; a3, zeros(1,nrT-length(a3); vec1=vec2; vec2=a3; end D-9-4: posdef() 判定矩阵的正定性function key,sdet=posdef(A) nr,nc=size(A); sdet=; for i=1:nr sdet=sdet,det(A(1:i,1:i); end key=1; if any(sdet0 phi_c=pi-theta; end if theta0; phi_c=-theta end theta_z=(phi+phi_c)/2; theta_p=(phi-phi_c)/2; z_c=real(s1)-imag(s1)/tan(theta_z); p_c=real(s1)-imag(s1)/tan(theta_p); nk=1 -z_c; varargout2=1 -p_c; kc=abs(p_c/z_c); if theta0 kc=-kc end varargout1=kc*nk; else 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 8 页 - - - - - - - - - error( 输出变量数目不正确!); end D-10-2: bpts2s( )计算满足性能指标的闭环主导极点function s=bpts2s(bp,ts,delta) kosi=sqrt(1-1./(1+(1./pi).*log(1./bp).2); wn=-log(delta.*sqrt(1-kosi.2)/(kosi.*ts); s=-kosi.*wn+j.*wn.*sqrt(1-kosi.2); D-10-3: kw2s( ) 根据阻尼比、无阻尼自振频率计算对应的闭环极点function s=kw2s(kosi,wn) s=-kosi.*wn+j*wn.*sqrt(1-kosi.2); D-10-4: s2kw( )计算闭环极点对应的阻尼比、无阻尼自振频率function kosi,wn=s2kw(s) kosi=1./sqrt(1+(imag(s)/real(s).2); wn=-real(s)./kosi; iwn=(wn0 dd=dd;j; end end if length(dd)=0 d(i)=n-1, else d(i)=min(dd); end end E=C(1,:)*Ad(1)*B; for i=2:m E=E;C(i,:)*Ad(i)*B; end L=inv(E); F=C(1,:)*A(d(1)+1); for i=2:m F=F;C(i,:)*A(d(i)+1); end K=L*F; AA=A-B*L*F;BB=B*L;CC=C;DD=zeros(m); G=tf(ss(AA,BB,CC,DD); D-11-7 : decoupling_s( )静态解耦控制算法function vv,K,L=decoupling_s(A,B,C,p,dd) m,n=size(C);ss=;CC=ctrb(A,B);nB=rank(CC); if nB=n,vv=1; else Ac,Bc,Cc=ctrbf(A,B,C);Anc=Ac(1:n-nB,1:n-nB);ee=eig(Anc); for i=1:length(ee) if real(ee(i)=0,ss=ss,ee(i);end,end if length(ss)0,vv=0; else,vv=1;end,end if (rank(A,B;C,zeros(m,m)=(n+m), vv=0;end p=-1;-2;-3;K=place(A,B,p);d=diag(dd); L=-(inv(C*(inv(A-B*K)*B)*d; D-11-8 : simobsv( )全维观测器设计function xh,x,t=simobsv(A,B,C,D,L) G=ss(A,B,C,D); y,t,x=step(G); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 8 页 - - - - - - - - - y1,xh1=step(A-L*C),B,C,D,1,t); y2,xh2=lsim(A-L*C),L,C,D,y,t); xh=xh1+xh2; plot(t,x,-,t,xh,:);grid on; D-11-9 : jiangweiguanceqi( ) 降维观测器设计function L,Az,By,Bu,Cz,Dy=jiangweiguanceqi(A,B,C,R,p) m,n=size(C); P=C;R;Q=inv(P); Q1=Q(:,1:m);Q2=Q(:,m+1:n); AA=P*A*Q;BB=P*B; AA11=AA(1:m,1:m);AA12=AA(1:m,m+1:n); AA21=AA(m+1:n,1:m);AA22=AA(m+1:n,m+1:n); BB1=BB(1:m,:);BB2=BB(m+1:n,:); KK=place(AA22,AA12,p);LL=KK; Az=AA22-LL*AA12; By=AA21-LL*AA11+(AA22-LL*AA12)*LL;Bu=BB2-LL*BB1; Cz=Q2;Dy=Q1+Q2*LL; L=LL; D-12-1: ode4( ) 计算定步长四阶龙格-库塔法function t,y=ode4(A,B,C,D,x0,h,r,v,t0,tf) Ab=A-B*v*C;B=B;C=C;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)+B*r; x=x+h*(k1+2*k2+2*k3+k4)/6; y=y,C*x;t=t,t(i)+h; end D-12-2: Saturation( ) 饱和非线性环节的仿真function uc=Saturation(ur,s1) if(abs(ur)=s1) if (ur0) uc=s1; else uc=-s1; end else uc=ur; end D-12-3: DeadZone( ) 死区非线性环节的仿真function uc= DeadZone(ur,s1) if(abs(ur)=s1) if (ur0) uc=ur-s1; else uc=ur+s1; end 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 8 页 - - - - - - - - - else uc=0; end D-12-4: backlash( ) 间隙非线性环节的仿真function uc,uss=backlash(urs,ur,ucs,s1) if(ururs) if(ur-s1)=ucs) uc=ur-s1; else uc=ucs; end else if(ururs) if (ur+s1)=ucs) uc=ur+s1; else uc=ucs; end else uc=ucs; end end uss=ur; D-12-5: diffstate( ) 离散系统仿真function t,xx=diffstate(G,H,x0,u0,N,T) xk=x0;u=u0;t=0 for k=1:N xk=G*xk+H*u; x(:,k)=xk; xx=x0,x;t=t,k*T; end; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 8 页 - - - - - - - - -