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

📄 design1.m

📁 详细介绍了Mathlab的使用方法与技巧
💻 M
字号:
%**********************
%求给定极点配置的状态反馈向量K
wind_demo6=figure('color',[1,1,1],'position',[0.05*winw,0.05*winh,0.9*winw,0.9*winh],...
       'name','控制器设计:求给定极点配置的状态反馈向量K','numbertitle','off','menubar','none',...
        'resize','on','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.03,0.03];
showtext(pos,color,'AK:');
demo_edita=uicontrol(wind_demo6,'style','edit','pos',[0.07,0.88,0.7,0.04],...
        'string',mat2str(ak),'back',[0.95;.95;0.95],'units','normalized');
pos=[0.03,0.84,0.03,0.03];
showtext(pos,color,'BK:');
demo_editb=uicontrol(wind_demo6,'style','edit','pos',[0.07,0.84,0.7,0.04],...
        'string',mat2str(bk),'back',[0.95;.95;0.95],'units','normalized');
pos=[0.03,0.8,0.03,0.03];
showtext(pos,color,'CK:');
demo_editc=uicontrol(wind_demo6,'style','edit','pos',[0.07,0.8,0.7,0.04],...
        'string',mat2str(ck),'back',[0.95;.95;0.95],'units','normalized');
pos=[0.03,0.76,0.03,0.03];
showtext(pos,color,'DK:');
demo_editd=uicontrol(wind_demo6,'style','edit','pos',[0.07,0.76,0.7,0.04],...
        'string',mat2str(dk),'back',[0.95;.95;0.95],'units','normalized');
%*************
color=[0.9;.9;.9];
pos=[0.02,0.7,0.24,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.06,0.65,.71,.03];
uicontrol(wind_demo6,'style','edit','pos',[0.07,0.65,0.7,0.04],...
        'string',mat2str(pk),'back',[0.95;.95;0.95],'units','normalized');
%*************
color=[0.9;.9;0.9];
pos=[0.02,0.6,0.34,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.02,0.03];
showtext(pos,color,'P:');
demo_editp=uicontrol(wind_demo6,'style','edit','pos',[0.07,0.55,0.7,0.04],...
        'string','[   ]','back',[0.95;.95;0.95],'units','normalized');
%***************
color=[0.9;.9;0.9];
pos=[0.02,0.49,0.15,0.03];
showtext(pos,color,'系统的增益K为:');
color=[.8;.8;0.8];
uicontrol('style','frame','position',[0.025,0.43,.75,.05],...
   'units','normalized','backgroundcolor',color);
pos=[0.03,0.44,0.02,0.03];
showtext(pos,color,'K:');
%***************
color=[0.9;.9;0.9];
pos=[0.02,0.39,0.2,0.03];
showtext(pos,color,'反馈后系统状态空间:');
color=[.8;.8;.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;0.9];
pos=[0.02,0.17,0.2,0.03];
showtext(pos,color,'反馈后系统传递函数:');
color=[.8;.8;0.8];
uicontrol('style','frame','position',[0.025,0.07,.75,.10],...
   '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(demo6_1,''enable'',''on'');set(demo6_3,''enable'',''on'');set(demo6_4,''enable'',''on'');',...
      'demop=eval(get(demo_editp,''string''));',...
      'kk=place(ak,bk,demop);',...                                  %MIMO极点配置
      'af=ak-bk*kk;bf=bk;cf=ck;df=dk;',...
      '[numf,denf]=ss2tf(af,bf,cf,df,1);bnum=numf;bden=denf;',...
      'uicontrol(wind_demo6,''style'',''edit'',''pos'',[0.055,0.44,0.71,0.04],',...
      '              ''string'',mat2str(kk),''back'',[0.95;.95;0.95],''units'',''normalized'');'];
      %      'pos=[0.055,0.44,0.71,0.03],',...
     %showtext(pos,color,mat2str(kk));'];
str2=['set(demo6_2,''enable'',''on'');',...
         'uicontrol(wind_demo6,''style'',''edit'',''pos'',[0.055,0.34,0.71,0.04],',...
         '              ''string'',mat2str(af),''back'',[0.95;.95;0.95],''units'',''normalized'');',...
         'uicontrol(wind_demo6,''style'',''edit'',''pos'',[0.055,0.30,0.71,0.04],',...
         '              ''string'',mat2str(bf),''back'',[0.95;.95;0.95],''units'',''normalized'');',...
         'uicontrol(wind_demo6,''style'',''edit'',''pos'',[0.055,0.26,0.71,0.04],',...
         '              ''string'',mat2str(cf),''back'',[0.95;.95;0.95],''units'',''normalized'');',...
         'uicontrol(wind_demo6,''style'',''edit'',''pos'',[0.055,0.22,0.71,0.04],',...
         '              ''string'',mat2str(df),''back'',[0.95;.95;0.95],''units'',''normalized'');'];
str3=['set(demo6_5,''enable'',''on'');',...
         'uicontrol(wind_demo6,''style'',''edit'',''pos'',[0.08,0.12,0.685,0.04],',...
         '              ''string'',mat2str(numf),''back'',[0.95;.95;0.95],''units'',''normalized'');',...
         'uicontrol(wind_demo6,''style'',''edit'',''pos'',[0.08,0.08,0.685,0.04],',...
         '              ''string'',mat2str(denf),''back'',[0.95;.95;0.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_demo6,'style','push','back',[0.95;.95;0.95],'string','求状态反馈向量K',...
       'position',[0.8,0.85,0.18,0.06],'units','normalized',...
      'callback',str1);
demo6_1=uicontrol(wind_demo6,'style','push','back',[0.95;.95;0.95],'string','求反馈后状态空间',...
       'position',[0.8,0.75,0.18,0.06],'units','normalized','enable','off',...
      'callback',str2);
demo6_2=uicontrol(wind_demo6,'style','push','back',[0.95;.95;0.95],'string','求反馈后闭环传递函数',...
       'position',[0.8,0.65,0.18,0.06],'units','normalized','enable','off',...
      'callback',str3);
demo6_3=uicontrol(wind_demo6,'style','push','back',[0.95;.95;0.95],'string','反馈前后闭环Bode图',...
       'position',[0.8,0.55,0.18,0.06],'units','normalized','enable','off',...
      'callback',str4);
demo6_4=uicontrol(wind_demo6,'style','push','back',[0.95;.95;0.95],'string','反馈前后Step图',...
       'position',[0.8,0.45,0.18,0.06],'units','normalized','enable','off',...
      'callback',str5);
demo6_5=uicontrol(wind_demo6,'style','push','back',[0.95;.95;0.95],'string','保存反馈后模型',...
       'position',[0.8,0.35,0.18,0.06],'units','normalized','enable','off',...
      'callback',str6);
uicontrol(wind_demo6,'style','push','back',[0.95;.95;0.95],'string','结束',...
       'position',[0.8,0.25,0.18,0.06],'units','normalized',...
      'callback','close(wind_demo6)');

⌨️ 快捷键说明

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