ME369-系统模型、分析与控制 4.5系统模型Matlab表达 School of Mechanical Engineering ME369-Lecture 4.5 Shanghai Jiao Tong University Fall 2015 Matlab Getstart “Matrix”+“Laboratory” 系统表达 Polynomial多项式表示 Getting residues留数求取 System Transfer function系统传递函数表示 Model transfer模型转换 系统连结 In series串联 In parallel并联 C1ose1oop闭环 Simulink Getstart School of Mechanical Engineering ME369-Lecture 4.5 Shanghai Jiao Tong University Fall 2015 1
1 ME369-Lecture 4.5 Fall 2015 School of Mechanical Engineering Shanghai Jiao Tong University 4.5 系统模型Matlab表达 ME 369– 系统模型、分析与控制 ME369-Lecture 4.5 Fall 2015 School of Mechanical Engineering Shanghai Jiao Tong University 系统表达 Polynomial多项式表示 System Transfer function系统传递函数表示 Model transfer 模型转换 系统连结 In series 串联 In parallel 并联 Close loop 闭环 Getting residues留数求取 Simulink Getstart “Matrix”+“Laboratory” Matlab Getstart
Matlab起步 sin/cos/tan/asin/acos/atan function 1og/10g10 max/min sqrt/abs clf p1ot(x1,y1,’,x2,2,’,) title(‘text') PLOT figure xlable(‘text') close 1og1g(,1,’,22,’}) y1able(‘text') semilogx grid (x1,y1,’’,x2,y2,’’) text(pl,p2,’taxt”) hold on semology subplot (m,n,1) (x1,yl,’’,2y2,’’) :point y今yellow o今circle \beta m今1 genta x今x-maxk \gramna c今cyan r→red plus \delta sold \zeta x=[0:0.1:10] g今green b>blue star y=sin(x) :>-dotted w二)力1te -.→Dashdot plot(x.y,) k→black -dashed School of Mechanical Engineering ME369-Lecture 4.5 Shanghai Jiao Tong University Fall 2015 多项式运算 poly() roots() conv( polyval() X(s)=52+25+3 Z= Y(s)=s+4 161112 r= -4.0000 -1.0000+1.4142i -1.0000.1.4142i x=[123y-[14: p= z=conv(x,y) 1.00006.000011.000012.0000 =可oots(Z) p-poly(r) V= v=polyval(z,3) 126 School of Mechanical Engineering ME369-Lecture 4.5 Shanghai Jiao Tong University Fall 2015 2
2 ME369-Lecture 4.5 Fall 2015 School of Mechanical Engineering Shanghai Jiao Tong University function sin/cos/tan/asin/acos/atan log/log10 max/min sqrt/abs PLOT plot(x1,y1,’’,x2,y2,’’) loglog(x1,y1,’’,x2,y2,’’) semilogx (x1,y1,’’,x2,y2,’’) semology (x1,y1,’’,x2,y2,’’) title(‘text’) xlable(‘text’) ylable(‘text’) text(p1,p2,’text’) clf figure close grid hold on yyellow mmagenta ccyan rred ggreen bblue wwhite kblack . point ocircle xx-maxk +plus -sold * star : -dotted -.Dashdot --dashed \alpha \beta \gramma \delta \zeta \eta \theta …. x=[0:0.1:10] y=sin(x) plot(x,y,' ') subplot(m,n,l) Matlab 起步 ME369-Lecture 4.5 Fall 2015 School of Mechanical Engineering Shanghai Jiao Tong University poly() roots() conv() polyval() x=[1 2 3]; y=[1 4]; z=conv(x,y) r=roots(z) p=poly(r) v=polyval(z,3) ( ) 2 3 2 X s s s Y(s) s 4 z = 1 6 11 12 r = -4.0000 -1.0000 + 1.4142i -1.0000 - 1.4142i p = 1.0000 6.0000 11.0000 12.0000 v = 126 多项式运算
求取留数 B(s) 2+…+ -+kS) [r,p,k]=residue(num,den) A(s)s-ps-p, S-P B(s) 2s3+5s2+3s+6_-6,-43 A(s) +6s2+s+6s+3+2++2 rl= -6.0000 -4.0000 numl=2536: 3.0000 pl= denl=[16116 -3.0000 [rl,pl,kl]=residue(numl,den1) -2.0000 -1.0000 k= 2 School of Mechanical Engineering ME369-Lecture 4.5 Shanghai Jiao Tong University Fall 2015 求取留数(续) B=5+5++-+k6) [r,p,k]=residue(num,den A(s)s-P1S-P2 s-Pn B(s)s+1 -0.5-0.2887j,-0.5+0.2887j1 A(s)s3+s2+ss+0.5-0.866js+0.5+0.866js 2= -0.5000-0.2887i -0.5000+0.2887i 1.0000 p2= num2=11]: -0.5000+0.8660i den2=1110l: -0.5000.0.8660i [r2,p2,k2]=residue(num2,den2) 0 k2= 0 School of Mechanical Engineering ME369-Lecture 4.5 Shanghai Jiao Tong University Fa2015 3
3 ME369-Lecture 4.5 Fall 2015 School of Mechanical Engineering Shanghai Jiao Tong University 2 s 1 3 s 2 4 s 3 6 s 6s 11s 6 2s 5s 3s 6 A(s) B(s) 3 2 3 2 num1=[2 5 3 6]; den1=[1 6 11 6]; [r1,p1,k1]=residue(num1,den1) r1 = -6.0000 -4.0000 3.0000 p1 = -3.0000 -2.0000 -1.0000 k1 = 2 k(s) s p r s p r s p r A(s) B(s) n n 2 2 1 1 [r,p,k]=residue(num,den) 求取留数 ME369-Lecture 4.5 Fall 2015 School of Mechanical Engineering Shanghai Jiao Tong University k(s) s p r s p r s p r A(s) B(s) n n 2 2 1 1 [r,p,k]=residue(num,den) s 1 s 0.5 0.866 j 0.5 0.2887 j s 0.5 0.866 j 0.5 0.2887 j s s s s 1 A(s) B(s) 3 2 num2=[ 1 1]; den2=[1 1 1 0]; [r2,p2,k2]=residue(num2,den2) r2 = -0.5000 - 0.2887i -0.5000 + 0.2887i 1.0000 p2 = -0.5000 + 0.8660i -0.5000 - 0.8660i 0 k2 = [] 求取留数(续)
求取留数(续) +5 [r,p,k]=residue(num,den A(s)s-P1 +++k) s-P2 S-P 对于重根部分 + + s-Pi(s-P:)2 +…+6-p,严 B(S)_s2+2s+3 r= 1 0 2 A阿s+3s+3s+打s++s++s++0 1.0000 0.0000 2.0000 p= -1.0000 num=[123小: -1.0000 den=[1331, -1.0000 [r.p,k]=residue(num,den) k= School of Mechanical Engineering ME369-Lecture 4.5 Shanghai Jiao Tong University Fall 2015 求取留数(续) B=5+5++5-+k6) [r,p,k]=residue(num,den) A(s)s-P1 s-P2 s-Pn 对于重根部分 +…+ s-Pi (s-Pi) (s-p:)m [num,den]=residue(r,p,k) B(9=1+ 0 2 52+25+3 A)s+1(s++(s+厅 s2+3s2+3s+1 =102 num p=[-1-1-1]: 123 k=0: den= [num,den]=residue(r,p,k) 1331 School of Mechanical Engineering ME369-Lecture 4.5 Shanghai Jiao Tong University Fall 2015 4
4 ME369-Lecture 4.5 Fall 2015 School of Mechanical Engineering Shanghai Jiao Tong University 0 (s 1) 2 (s 1) 0 s 1 1 s 3s 3s 1 s 2s 3 A(s) B(s) 3 2 2 3 2 m j j m 2 j j 1 j j (s p ) r (s p ) r s p r k(s) s p r s p r s p r A(s) B(s) n n 2 2 1 1 [r,p,k]=residue(num,den) num=[ 1 2 3]; den=[1 3 3 1]; [r,p,k]=residue(num,den) r = 1.0000 0.0000 2.0000 p = -1.0000 -1.0000 -1.0000 k = [] 求取留数(续) 对于重根部分 ME369-Lecture 4.5 Fall 2015 School of Mechanical Engineering Shanghai Jiao Tong University [num,den]=residue(r,p,k) m j j m 2 j j 1 j j (s p ) r (s p ) r s p r 对于重根部分 k(s) s p r s p r s p r A(s) B(s) n n 2 2 1 1 [r,p,k]=residue(num,den) 2 2 3 3 2 ( ) 1 0 2 2 3 ( ) 1 ( 1) ( 1) 3 3 1 B s s s A s s s s s s s r=[ 1 0 2]; p=[-1 -1 -1]; k=[]; [num,den]=residue(r,p,k) num = 1 2 3 den = 1 3 3 1 求取留数(续)
系统传递函数 G(s)= num sys=tf(num,den) den 10 sys1:G,()=s+2s+5 Transfer function: sys2:G2(s)=- 10 +1 sys3=sysl+sys2 s2+2s+5 Transfer function: numl=[101: den1=[1 25]; s+1 sysl=tf(numl,denl) num2=[1]; Transfer function: den2=[11] s2+12s+15 sys2=tf(num2,den2) sys3=sysl+sys2 s3+3s2+7s+5 School of Mechanical Engineering ME369-Lecture 4.5 Shanghai Jiao Tong University Fall 2015 系统传递函数(续) G6)=k-s-3(s-2) (s-p(s-p)..(s-p) sys=zpk (z,p,k) 2(s+2)(s+7) G(s)= (s+3)(s+7(s+9) 2z=[-2-7: Zero/pole/gain: p=3-7-9外: 2(s+2)(s+7 k=2; sys=zpk(zp.k) (s+3)(s+7](s+9) School of Mechanical Engineering ME369-Lecture 4.5 Shanghai Jiao Tong University Fall 2015 5
5 ME369-Lecture 4.5 Fall 2015 School of Mechanical Engineering Shanghai Jiao Tong University s 2s 5 10 G (s) 1 2 s 1 1 G (s) 2 sys1: sys2: sys3=sys1+sys2 sys=tf(num,den) den num G(s) Transfer function: 10 ------------- s^2 + 2 s + 5 Transfer function: 1 ----- s + 1 Transfer function: s^2 + 12 s + 15 --------------------- s^3 + 3 s^2 + 7 s + 5 num1=[10]; den1=[1 2 5]; sys1=tf(num1,den1) num2=[1]; den2=[1 1]; sys2=tf(num2,den2) sys3=sys1+sys2 系统传递函数 ME369-Lecture 4.5 Fall 2015 School of Mechanical Engineering Shanghai Jiao Tong University sys=zpk (z,p,k) 1 2 1 2 ( )( )...( ) ( ) ( )( )...( ) m n s z s z s z G s K s p s p s p ( 3)( 7)( 9) 2( 2)( 7) ( ) s s s s s G s z=[-2 -7]; p=[-3 -7 -9]; k=2; sys=zpk(z,p,k) Zero/pole/gain: 2 (s+2) (s+7) ----------------- (s+3) (s+7) (s+9) 系统传递函数(续)
模型转换 tf2zp: 传递函数模型转换为零极点增益模型 zp2tf: 零极点增益模型转换为传递函数模型 residue:传递函数模型与部分分式模型互换 ss2tf: 状态空间模型转换为传递函数模型 ss2zp: 状态空间模型转换为零极点增益模型 tf2ss: 传递函数模型转换为状态空间模型 zp2ss: 零极点增益模型转换为状态空间模型 School of Mechanical Engineering ME369-Lecture 4.5 Shanghai Jiao Tong University Fall 2015 模型转换(续) num p=ploe(sys) G(s)= (s-z)s-2).(s-2m) den (s-p)(s-p2)...(s-P) z=zero(sys) [p,z]=pzmap(sys) [z,p,k]=tf2zp(num,den) [p,z]=pzmap(num,den) [num,den]=zp2tf (z,p,k Transfer function: s+10 s2+2s+5 G(s)=(+10) (s2+2s+5) z= -10 numl=[110: p= denl=[125]: -1.0000+2.0000i sysl=tf(numl,denl) -1.0000-2.0000i [zp,k]=tf2zp(numl,den1) k= School of Mechanical Engineering ME369-Lecture 4.5 Shanghai Jiao Tong University Fall 2015 6
6 ME369-Lecture 4.5 Fall 2015 School of Mechanical Engineering Shanghai Jiao Tong University tf2zp: 传递函数模型转换为零极点增益模型 zp2tf: 零极点增益模型转换为传递函数模型 residue:传递函数模型与部分分式模型互换 ss2tf: 状态空间模型转换为传递函数模型 ss2zp: 状态空间模型转换为零极点增益模型 tf2ss: 传递函数模型转换为状态空间模型 zp2ss: 零极点增益模型转换为状态空间模型 模型转换 ME369-Lecture 4.5 Fall 2015 School of Mechanical Engineering Shanghai Jiao Tong University 1 2 1 2 ( )( )...( ) ( ) ( )( )...( ) m n num s z s z s z G s K den s p s p s p [z,p,k]=tf2zp(num,den) p=ploe(sys) z=zero(sys) [p,z]=pzmap(sys) [p,z]=pzmap(num,den) [num,den]= zp2tf (z,p,k ) 2 ( 10) ( ) ( 2 5) s G s s s num1=[1 10]; den1=[1 2 5]; sys1=tf(num1,den1) [z,p,k]=tf2zp(num1,den1) Transfer function: s + 10 ------------- s^2 + 2 s + 5 z = -10 p = -1.0000 + 2.0000i -1.0000 - 2.0000i k = 1 模型转换(续)
系统连结-串联 sys=series(sys1,sys2) - System 1 System 2 G1(x) G2(s) G()=+1 U(s) 1 R(S)一 s+2 Gs)=5003 ) numc=[1 1]: denc=[12}: Transfer function: sysc=tf(numc,denc); s+1 numg=[1]; deng[50000: 500s^3+1000s2 sysg=tf(numg,deng): sys=series(sysc,sysg) School of Mechanical Engineering ME369-Lecture 4.5 Shanghai Jiao Tong University Fall 2015 系统连结一并联 sys=parallel(sys1,sys2) System I G1( System 2 G(s) School of Mechanical Engineering ME369-Lecture 4.5 Shanghai Jiao Tong University Fall 2015 7
7 ME369-Lecture 4.5 Fall 2015 School of Mechanical Engineering Shanghai Jiao Tong University sys=series(sys1,sys2) numc=[1 1]; denc=[1 2]; sysc=tf(numc,denc); numg=[1]; deng=[500 0 0]; sysg=tf(numg,deng); sys=series(sysc,sysg) Transfer function: s + 1 ------------------ 500 s^3 + 1000 s^2 系统连结--串联 ME369-Lecture 4.5 Fall 2015 School of Mechanical Engineering Shanghai Jiao Tong University sys=parallel(sys1,sys2) 系统连结—并联
系统连结一反馈 sys=feedback(sysg,sysh,sign) +1 正反馈 -1 负反馈 default 负反馈 System I G) System2 H(s) (0- E G=07 numh=[11]; denh=[1 2]; sysh=tf(numh,denh) Transfer function: s+2 numg=[1]; deng-[500001: 500s3+1000s2+s+1 sysg-tf(numg,deng) sys-feedback(sysg.sysh) School of Mechanical Engineering ME369-Lecture 4.5 Shanghai Jiao Tong University Fall 2015 Simulink getstart 1 10 +1 x2+3s+1 Y(s) School of Mechanical Engineering ME369-Lecture 4.5 Shanghai Jiao Tong University Fall 2015 8
8 ME369-Lecture 4.5 Fall 2015 School of Mechanical Engineering Shanghai Jiao Tong University sys=feedback(sysg,sysh,sign) +1 正反馈 -1 负反馈 default 负反馈 numh=[1 1]; denh=[1 2]; sysh=tf(numh,denh) numg=[1]; deng=[500 0 0]; sysg=tf(numg,deng) sys=feedback(sysg,sysh) Transfer function: s + 2 -------------------------- 500 s^3 + 1000 s^2 + s + 1 系统连结—反馈 ME369-Lecture 4.5 Fall 2015 School of Mechanical Engineering Shanghai Jiao Tong University Simulink getstart