⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 design2.m

📁 详细介绍了Mathlab的使用方法与技巧
💻 M
字号:
%**********************
%求给定状态观测器极点的增益向量L
wind_demo8=figure('color',[1,1,1],'position',[0.08*winw,0.05*winh,0.8*winw,0.9*winh],...
       'name','观测器设计:求给定状态观测器极点的增益向量L','numbertitle','off','menubar','none',...
        'resize','off','clipping','off');
color=[0.8;.8;.8];
uicontrol('style','frame','position',[0,0,1,1],...
   'units','normalized','backgroundcolor',color);
%*************
pos=[0.02,0.93,0.18,0.03];
showtext(pos,color,'当前系统状态空间:');
color=[.8;.8;0.8];
uicontrol('style','frame','position',[0.025,0.75,.75,.18],...
   'units','normalized','backgroundcolor',color);
pos=[0.03,0.88,0.02,0.03];
showtext(pos,color,'A:');
demo_edita=uicontrol(wind_demo8,'style','edit','pos',[0.055,0.88,0.71,0.04],...
        'string',mat2str(ak),'back',[0.95;.95;.95],'units','normalized');
pos=[0.03,0.84,0.02,0.03];
showtext(pos,color,'B:');
demo_editb=uicontrol(wind_demo8,'style','edit','pos',[0.055,0.84,0.71,0.04],...
        'string',mat2str(bk),'back',[0.95;.95;.95],'units','normalized');
pos=[0.03,0.8,0.02,0.03];
showtext(pos,color,'C:');
demo_editc=uicontrol(wind_demo8,'style','edit','pos',[0.055,0.8,0.71,0.04],...
        'string',mat2str(ck),'back',[0.95;.95;.95],'units','normalized');
pos=[0.03,0.76,0.02,0.03];
showtext(pos,color,'D:');
demo_editd=uicontrol(wind_demo8,'style','edit','pos',[0.055,0.76,0.71,0.04],...
        'string',mat2str(dk),'back',[0.95;.95;.95],'units','normalized');
%*************
color=[0.9;.9;.9];
pos=[0.02,0.7,0.18,0.03];
showtext(pos,color,'当前系统的开环极点为:');
color=[.8;.8;0.8];
uicontrol('style','frame','position',[0.025,0.64,.75,.06],...
   'units','normalized','backgroundcolor',color);
pos=[0.03,0.65,0.03,0.03];
showtext(pos,color,'PK:');
[z,p,k]=ss2zp(a,b,c,d,1);
pos=[0.055,0.65,.71,.03];
uicontrol(wind_demo8,'style','edit','pos',[0.0605,0.65,0.705,0.04],...
        'string',mat2str(pk),'back',[0.95;.95;.95],'units','normalized');
%*************
color=[0.9;.9;.9];
pos=[0.02,0.6,0.25,0.03];
showtext(pos,color,'输入系统希望观测器极点为:');
color=[.8;.8;0.8];
uicontrol('style','frame','position',[0.025,0.54,.75,.06],...
   'units','normalized','backgroundcolor',color);
pos=[0.03,0.55,0.03,0.03];
showtext(pos,color,'OP:');
demo_editp=uicontrol(wind_demo8,'style','edit','pos',[0.065,0.55,0.7,0.04],...
        'string','[   ]','back',[0.95;.95;.95],'units','normalized');
%***************
color=[0.9;.9;.9];
pos=[0.02,0.49,0.15,0.03];
showtext(pos,color,'系统的增益L为:');
color=[.8;.8;0.8];
uicontrol('style','frame','position',[0.025,0.43,.75,.06],...
   'units','normalized','backgroundcolor',color);
pos=[0.03,0.44,0.02,0.03];
showtext(pos,color,'L:');
%***************
color=[0.9;.9;.9];
pos=[0.02,0.39,0.18,0.03];
showtext(pos,color,'反馈后系统状态空间:');
color=[.8;.8;0.8];
uicontrol('style','frame','position',[0.025,0.21,.75,.18],...
   'units','normalized','backgroundcolor',color);
pos=[0.03,0.34,0.02,0.03];showtext(pos,color,'A:');
pos=[0.03,0.30,0.02,0.03];showtext(pos,color,'B:');
pos=[0.03,0.26,0.02,0.03];showtext(pos,color,'C:');
pos=[0.03,0.22,0.02,0.03];showtext(pos,color,'D:');
%***************
color=[0.9;.9;.9];
pos=[0.02,0.17,0.18,0.03];
showtext(pos,color,'反馈后系统传递函数:');
color=[.8;.8;0.8];
uicontrol('style','frame','position',[0.025,0.07,.75,.1],...
   'units','normalized','backgroundcolor',color);
pos=[0.03,0.12,0.045,0.03];showtext(pos,color,'分子:');
pos=[0.03,0.08,0.045,0.03];showtext(pos,color,'分母:');
%***************
str1=['set(demo8_1,''enable'',''on'');set(demo8_3,''enable'',''on'');set(demo8_4,''enable'',''on'');',...
      'demop=eval(get(demo_editp,''string''));',...
      'll=place(ak'',ck'',demop);',...
      'll=ll'';af=ak-ll*ck;bf=bk;cf=ck;df=dk;',...
      '[numf,denf]=ss2tf(af,bf,cf,df,1);',...
            'uicontrol(wind_demo8,''style'',''edit'',''pos'',[0.055,0.44,0.71,0.04],',...
      '              ''string'',mat2str(ll),''back'',[0.95;.95;0.95],''units'',''normalized'');'];
%      'pos=[0.055,0.44,0.71,0.03];showtext(pos,color,mat2str(ll));'];
str2=['set(demo8_2,''enable'',''on'');',...
         'uicontrol(wind_demo8,''style'',''edit'',''pos'',[0.055,0.34,0.71,0.04],',...
         '              ''string'',mat2str(af),''back'',[0.95;.95;.95],''units'',''normalized'');',...
         'uicontrol(wind_demo8,''style'',''edit'',''pos'',[0.055,0.30,0.71,0.04],',...
         '              ''string'',mat2str(bf),''back'',[0.95;.95;.95],''units'',''normalized'');',...
         'uicontrol(wind_demo8,''style'',''edit'',''pos'',[0.055,0.26,0.71,0.04],',...
         '              ''string'',mat2str(cf),''back'',[0.95;.95;.95],''units'',''normalized'');',...
         'uicontrol(wind_demo8,''style'',''edit'',''pos'',[0.055,0.22,0.71,0.04],',...
         '              ''string'',mat2str(df),''back'',[0.95;.95;.95],''units'',''normalized'');'];
str3=['set(demo8_5,''enable'',''on'');',...
         'uicontrol(wind_demo8,''style'',''edit'',''pos'',[0.08,0.12,0.685,0.04],',...
         '              ''string'',mat2str(numf),''back'',[0.95;.95;.95],''units'',''normalized'');',...
         'uicontrol(wind_demo8,''style'',''edit'',''pos'',[0.08,0.08,0.685,0.04],',...
         '              ''string'',mat2str(denf),''back'',[0.95;.95;.95],''units'',''normalized'');'];
str4=['wbode=figure(''color'',[.1,.7,.8],''position'',[0.1*winw,0.1*winh,0.8*winw,0.8*winh],',...
        '              ''name'',''反馈前后Bode图对比分析'',''numbertitle'',''off'',''menubar'',''figure'',''resize'',''off'');',...
        '[mag,phase,w]=bode(bnum,bden);',...
        'subplot(2,2,1);semilogx(w,20*log10(mag));',...
        'grid;ylabel(''幅值/db'');title(''系统反馈前Bode图之幅值图'');',...
        'subplot(2,2,2);semilogx(w,phase);',...
        'grid;ylabel(''相位/deg'');title(''系统反馈前Bode图之相位图'');',...
        '[mag,phase,w]=bode(numf,denf);',...
        'subplot(2,2,3);semilogx(w,20*log10(mag));',...
        'grid;xlabel(''频率'');ylabel(''幅值/db'');title(''系统反馈后Bode图之幅值图'');',...
        'subplot(2,2,4);semilogx(w,phase);',...
        'grid;xlabel(''频率'');ylabel(''相位/deg'');title(''系统反馈后Bode图之相位图'');'];
str5=['t=[0:0.01:20];',...
        'wstep=figure(''color'',[.1,0.7,.8],''position'',[0.1*winw,0.1*winh,0.8*winw,0.8*winh],',...
        '                 ''name'',''反馈前后Step阶跃响应对比分析'',''numbertitle'',''off'',''menubar'',''figure'',''resize'',''off'');',...
        'dcg=dcgain(a,b,c,d);',...
        '[yc x]=step(a,b,c,d,1,t);',...
        'yc1=yc/dcg;',...
        'subplot(2,1,1);',...
        'plot(t,x,''r'',t,yc1,''b'');',...
        'grid;xlabel(''s/t'');ylabel(''Y(t)和X(t)'');title(''反馈前蓝线:Y(t)阶跃响应;红线:X(t)状态曲线'');',...
        'dcg=dcgain(af,bf,cf,df);',...
        '[yc x]=step(af,bf,cf,df,1,t);',...
        'yc1=yc/dcg;',...
        'subplot(2,1,2);',...
        'plot(t,x,''r'',t,yc1,''b'');',...
        'grid;xlabel(''s/t'');ylabel(''Y(t)和X(t)'');title(''反馈后蓝线:Y(t)阶跃响应;红线:X(t)状态曲线'');'];
str6=['at=a;bt=b;ct=c;dt=d;numt=bnum;dent=bden;numt1=num;dent1=den;numt2=ffnum;dent2=ffden;',...
         'a=af;b=bf;c=cf;d=df;bnum=numf;bden=denf;[num,den]=cloop(bnum,bden,1);ffnum=1;ffden=1;',...
         '[ff,pp]=uiputfile(''*.mat'',''保存模型数据'',0.3*winw,0.4*winh);eval([''save '' pp,ff '' a b c d num den bnum bden ffnum ffden '']);test=1;',...
         'a=at;b=bt;c=ct;d=dt;bnum=numt;bden=dent;num=numt1;den=dent1;ffnum=numt2;ffden=dent2;'];
uicontrol(wind_demo8,'style','push','back',[0.95;.95;.95],'string','求观测器向量L',...
       'position',[0.8,0.85,0.18,0.06],'units','normalized',...
      'callback',str1);
demo8_1=uicontrol(wind_demo8,'style','push','string','求反馈后状态空间',...
       'position',[0.8,0.75,0.18,0.06],'units','normalized','enable','off',...
      'callback',str2);
demo8_2=uicontrol(wind_demo8,'style','push','string','求反馈后传递函数',...
       'position',[0.8,0.65,0.18,0.06],'units','normalized','enable','off',...
      'callback',str3);
demo8_3=uicontrol(wind_demo8,'style','push','string','反馈前后Bode图',...
       'position',[0.8,0.55,0.18,0.06],'units','normalized','enable','off',...
      'callback',str4);
demo8_4=uicontrol(wind_demo8,'style','push','string','反馈前后Step图',...
       'position',[0.8,0.45,0.18,0.06],'units','normalized','enable','off',...
      'callback',str5);
demo8_5=uicontrol(wind_demo8,'style','push','string','保存反馈后模型',...
       'position',[0.8,0.35,0.18,0.06],'units','normalized','enable','off',...
      'callback',str6);
uicontrol(wind_demo8,'style','push','back',[0.95;.95;.95],'string','结束',...
       'position',[0.8,0.25,0.18,0.06],'units','normalized',...
      'callback','close(wind_demo8)');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -