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

📄 dmctutorial.html

📁 采用动态矩阵控制方法对热水器出口温度进行控制的Matlab源代码
💻 HTML
字号:
<!DOCTYPE html  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"><html xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">   <head>      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">         <!--This HTML is auto-generated from an M-file.To make changes, update the M-file and republish this document.      -->      <title>Dynamic Matrix Control Tutorial</title>      <meta name="generator" content="MATLAB 7.6">      <meta name="date" content="2008-04-07">      <meta name="m-file" content="dmctutorial"><style>body {  background-color: white;  margin:10px;}h1 {  color: #990000;   font-size: x-large;}h2 {  color: #990000;  font-size: medium;}/* Make the text shrink to fit narrow windows, but not stretch too far in wide windows. */ p,h1,h2,div.content div {  max-width: 600px;  /* Hack for IE6 */  width: auto !important; width: 600px;}pre.codeinput {  background: #EEEEEE;  padding: 10px;}@media print {  pre.codeinput {word-wrap:break-word; width:100%;}} span.keyword {color: #0000FF}span.comment {color: #228B22}span.string {color: #A020F0}span.untermstring {color: #B20000}span.syscmd {color: #B28C00}pre.codeoutput {  color: #666666;  padding: 10px;}pre.error {  color: red;}p.footer {  text-align: right;  font-size: xx-small;  font-weight: lighter;  font-style: italic;  color: gray;}  </style></head>   <body>      <div class="content">         <h1>Dynamic Matrix Control Tutorial</h1>         <introduction>            <p>Dynamic Matrix Control (DMC) was the first Model Predictive Control (MPC) algorithm introduced in early 1980s. Nowadays, DMC               is available in almost all commercial industrial distributed control systems and process simulation software packages. This               tutorial intends to explain the features of DMC using the dmc function developed by the author.            </p>         </introduction>         <h2>Contents</h2>         <div>            <ul>               <li><a href="#1">Example: A Water Heater</a></li>               <li><a href="#3">The Step Response Model</a></li>               <li><a href="#4">DMC without Setpoint Prediction</a></li>               <li><a href="#5">DMC with Setpoint Prediction</a></li>               <li><a href="#6">DMC with Different Control Weight</a></li>               <li><a href="#7">Reference</a></li>            </ul>         </div>         <h2>Example: A Water Heater<a name="1"></a></h2>         <p>Consider a water heater as shown in the following figure, where the cold water is heated by means of a gas burner. The aim            of DMC is by manipulating valve to control the gas flow so that the outlet temperature is at desired level.         </p>         <p><img vspace="5" hspace="5" src="WaterHeater.PNG"> </p>         <h2>The Step Response Model<a name="3"></a></h2>         <p>The DMC algorithm works with a step response model. The first step to design a DMC controller is to perform a step test on            the plant to generate a step response model. The step response of the water heater is obtained through such a test and given            as follows:         </p><pre class="codeinput">p.sr = [0;0;0.271;0.498;0.687;0.845;0.977;1.087;1.179;1.256;<span class="keyword">...</span>        1.320;1.374;1.419;1.456;1.487;1.513;1.535;1.553;1.565;1.581;<span class="keyword">...</span>        1.592;1.600;1.608;1.614;1.619;1.632;1.627;1.630;1.633;1.635];<span class="comment">% The response is converged after 30 steps.</span></pre><h2>DMC without Setpoint Prediction<a name="4"></a></h2>         <p>Setup the DMC</p><pre class="codeinput">N=120;  <span class="comment">% Total simulation length (samples)</span>p.p=10; <span class="comment">% Prediction horizon</span>p.m=5;  <span class="comment">% Moving horizon</span>p.la=1; <span class="comment">% Control weight</span><span class="comment">% Reference (setpoint)</span>R=[ones(30,1);zeros(30,1);ones(30,1);zeros(30,1)];p.y=0;  <span class="comment">% Initial output</span>p.v=[]; <span class="comment">% empty past input to indicate initialization</span><span class="comment">% buffer of input to cope with time delay</span>u=zeros(3,1);<span class="comment">% Initialization of variables for results</span>Y=zeros(N,1);U=zeros(N,1);<span class="comment">% DMC Simulation</span><span class="keyword">for</span> k=1:120    p.a=0;    p.r=R(k);   <span class="comment">% DMC only knows current setpoint</span>    <span class="keyword">if</span> k&gt;60     <span class="comment">% change smoothing factor for second half simulation</span>        p.a=0.7;    <span class="keyword">end</span>    p=dmc(p);    Y(k)=p.y;    U(k)=p.u;    u=[u(2:3);p.u];    p.y=0.8351*p.y+0.2713*u(1); <span class="comment">% actual plant output</span><span class="keyword">end</span><span class="comment">% DMC results</span>subplot(211)plot(1:N,Y,<span class="string">'b-'</span>,1:N,R,<span class="string">'r--'</span>,[60 60],[-0.5 1.5],<span class="string">':'</span>,<span class="string">'linewidth'</span>,2)title(<span class="string">'solid: output, dashed: reference'</span>)text(35,1,<span class="string">'\alpha=0'</span>)text(95,1,<span class="string">'\alpha=0.7'</span>)axis([0 120 -0.5 1.5])subplot(212)[xx,yy]=stairs(1:N,U);plot(xx,yy,<span class="string">'-'</span>,[60 60],[-0.5 1.5],<span class="string">':'</span>,<span class="string">'linewidth'</span>,2)axis([0 120 -0.5 1.5])title(<span class="string">'input, \lambda=1'</span>)xlabel(<span class="string">'time, min'</span>)</pre><img vspace="5" hspace="5" src="dmctutorial_01.png"> <h2>DMC with Setpoint Prediction<a name="5"></a></h2>         <p>Setup the DMC</p><pre class="codeinput">N=120;  <span class="comment">% Total simulation length (samples)</span>p.p=10; <span class="comment">% Prediction horizon</span>p.m=5;  <span class="comment">% Moving horizon</span>p.la=1; <span class="comment">% Control weight</span><span class="comment">% Reference (setpoint)</span>R=[ones(30,1);zeros(30,1);ones(30,1);zeros(30,1)];p.y=0;  <span class="comment">% Initial output</span>p.v=[]; <span class="comment">% empty past input to indicate initialization</span><span class="comment">% buffer of input to cope with time delay</span>u=zeros(3,1);<span class="comment">% Initialization of variables for results</span>Y=zeros(N,1);U=zeros(N,1);<span class="comment">% DMC Simulation</span><span class="keyword">for</span> k=1:120    p.a=0;    p.r=R(k:min(N,k+p.p)); <span class="comment">% DMC knows future setpoint</span>    <span class="keyword">if</span> k&gt;60     <span class="comment">% change smoothing factor for second half simulation</span>        p.a=0.7;    <span class="keyword">end</span>    p=dmc(p);    Y(k)=p.y;    U(k)=p.u;    u=[u(2:3);p.u];    p.y=0.8351*p.y+0.2713*u(1); <span class="comment">% actual plant output</span><span class="keyword">end</span><span class="comment">% DMC results</span>subplot(211)plot(1:N,Y,<span class="string">'b-'</span>,1:N,R,<span class="string">'r--'</span>,[60 60],[-0.5 1.5],<span class="string">':'</span>,<span class="string">'linewidth'</span>,2)title(<span class="string">'solid: output, dashed: reference'</span>)text(35,1,<span class="string">'\alpha=0'</span>)text(95,1,<span class="string">'\alpha=0.7'</span>)axis([0 120 -0.5 1.5])subplot(212)[xx,yy]=stairs(1:N,U);plot(xx,yy,<span class="string">'-'</span>,[60 60],[-0.5 1.5],<span class="string">':'</span>,<span class="string">'linewidth'</span>,2)axis([0 120 -0.5 1.5])title(<span class="string">'input, \lambda=1'</span>)xlabel(<span class="string">'time, min'</span>)</pre><img vspace="5" hspace="5" src="dmctutorial_02.png"> <h2>DMC with Different Control Weight<a name="6"></a></h2>         <p>Setup the DMC</p><pre class="codeinput">N=120;  <span class="comment">% Total simulation length (samples)</span>p.p=10; <span class="comment">% Prediction horizon</span>p.m=5;  <span class="comment">% Moving horizon</span>p.la=0.1; <span class="comment">% Control weight</span><span class="comment">% Reference (setpoint)</span>R=[ones(30,1);zeros(30,1);ones(30,1);zeros(30,1)];p.y=0;  <span class="comment">% Initial output</span>p.v=[]; <span class="comment">% empty past input to indicate initialization</span><span class="comment">% buffer of input to cope with time delay</span>u=zeros(3,1);<span class="comment">% Initialization of variables for results</span>Y=zeros(N,1);U=zeros(N,1);<span class="comment">% DMC Simulation</span><span class="keyword">for</span> k=1:120    p.a=0;    p.r=R(k:min(N,k+p.p)); <span class="comment">% DMC knows future setpoint</span>    <span class="keyword">if</span> k&gt;60     <span class="comment">% change smoothing factor for second half simulation</span>        p.a=0.7;    <span class="keyword">end</span>    p=dmc(p);    Y(k)=p.y;    U(k)=p.u;    u=[u(2:3);p.u];    p.y=0.8351*p.y+0.2713*u(1); <span class="comment">% actual plant output</span><span class="keyword">end</span><span class="comment">% DMC results</span>subplot(211)plot(1:N,Y,<span class="string">'b-'</span>,1:N,R,<span class="string">'r--'</span>,[60 60],[-0.5 1.5],<span class="string">':'</span>,<span class="string">'linewidth'</span>,2)title(<span class="string">'solid: output, dashed: reference'</span>)text(35,1,<span class="string">'\alpha=0'</span>)text(95,1,<span class="string">'\alpha=0.7'</span>)axis([0 120 -0.5 1.5])subplot(212)[xx,yy]=stairs(1:N,U);plot(xx,yy,<span class="string">'-'</span>,[60 60],[-0.5 1.5],<span class="string">':'</span>,<span class="string">'linewidth'</span>,2)axis([0 120 -1 2])title(<span class="string">'input, \lambda=0.1'</span>)xlabel(<span class="string">'time, min'</span>)</pre><img vspace="5" hspace="5" src="dmctutorial_03.png"> <h2>Reference<a name="7"></a></h2>         <p>Camacho, E.F. and Bordons, C., Model Predictive Control, Springer-Verlag, 1999.</p>         <p class="footer"><br>            Published with MATLAB&reg; 7.6<br></p>      </div>      <!--##### SOURCE BEGIN #####%% Dynamic Matrix Control Tutorial
% Dynamic Matrix Control (DMC) was the first Model Predictive Control (MPC)
% algorithm introduced in early 1980s. Nowadays, DMC is available in almost
% all commercial industrial distributed control systems and process
% simulation software packages. This tutorial intends to explain the
% features of DMC using the dmc function developed by the author.

%% Example: A Water Heater
% Consider a water heater as shown in the following figure, where the cold
% water is heated by means of a gas burner. The aim of DMC is by
% manipulating valve to control the gas flow so that the outlet temperature
% is at desired level.
%%
% 
% <<WaterHeater.PNG>>
% 

%% The Step Response Model
% The DMC algorithm works with a step response model. The first step to
% design a DMC controller is to perform a step test on the plant to
% generate a step response model. The step response of the water heater is
% obtained through such a test and given as follows:
p.sr = [0;0;0.271;0.498;0.687;0.845;0.977;1.087;1.179;1.256;...
        1.320;1.374;1.419;1.456;1.487;1.513;1.535;1.553;1.565;1.581;...
        1.592;1.600;1.608;1.614;1.619;1.632;1.627;1.630;1.633;1.635];

% The response is converged after 30 steps.

%% DMC without Setpoint Prediction
% Setup the DMC
N=120;  % Total simulation length (samples)
p.p=10; % Prediction horizon
p.m=5;  % Moving horizon
p.la=1; % Control weight
% Reference (setpoint)
R=[ones(30,1);zeros(30,1);ones(30,1);zeros(30,1)];
p.y=0;  % Initial output
p.v=[]; % empty past input to indicate initialization
% buffer of input to cope with time delay
u=zeros(3,1);
% Initialization of variables for results
Y=zeros(N,1);
U=zeros(N,1);
% DMC Simulation
for k=1:120
    p.a=0;
    p.r=R(k);   % DMC only knows current setpoint
    if k>60     % change smoothing factor for second half simulation
        p.a=0.7;
    end
    p=dmc(p);
    Y(k)=p.y;
    U(k)=p.u;
    u=[u(2:3);p.u];
    p.y=0.8351*p.y+0.2713*u(1); % actual plant output 
end
% DMC results
subplot(211)
plot(1:N,Y,'b-',1:N,R,'rREPLACE_WITH_DASH_DASH',[60 60],[-0.5 1.5],':','linewidth',2)
title('solid: output, dashed: reference')
text(35,1,'\alpha=0')
text(95,1,'\alpha=0.7')
axis([0 120 -0.5 1.5])
subplot(212)
[xx,yy]=stairs(1:N,U);
plot(xx,yy,'-',[60 60],[-0.5 1.5],':','linewidth',2)
axis([0 120 -0.5 1.5])
title('input, \lambda=1')
xlabel('time, min')

%% DMC with Setpoint Prediction
% Setup the DMC
N=120;  % Total simulation length (samples)
p.p=10; % Prediction horizon
p.m=5;  % Moving horizon
p.la=1; % Control weight
% Reference (setpoint)
R=[ones(30,1);zeros(30,1);ones(30,1);zeros(30,1)];
p.y=0;  % Initial output
p.v=[]; % empty past input to indicate initialization
% buffer of input to cope with time delay
u=zeros(3,1);
% Initialization of variables for results
Y=zeros(N,1);
U=zeros(N,1);
% DMC Simulation
for k=1:120
    p.a=0;
    p.r=R(k:min(N,k+p.p)); % DMC knows future setpoint
    if k>60     % change smoothing factor for second half simulation
        p.a=0.7;
    end
    p=dmc(p);
    Y(k)=p.y;
    U(k)=p.u;
    u=[u(2:3);p.u];
    p.y=0.8351*p.y+0.2713*u(1); % actual plant output 
end
% DMC results
subplot(211)
plot(1:N,Y,'b-',1:N,R,'rREPLACE_WITH_DASH_DASH',[60 60],[-0.5 1.5],':','linewidth',2)
title('solid: output, dashed: reference')
text(35,1,'\alpha=0')
text(95,1,'\alpha=0.7')
axis([0 120 -0.5 1.5])
subplot(212)
[xx,yy]=stairs(1:N,U);
plot(xx,yy,'-',[60 60],[-0.5 1.5],':','linewidth',2)
axis([0 120 -0.5 1.5])
title('input, \lambda=1')
xlabel('time, min')

%% DMC with Different Control Weight
% Setup the DMC
N=120;  % Total simulation length (samples)
p.p=10; % Prediction horizon
p.m=5;  % Moving horizon
p.la=0.1; % Control weight
% Reference (setpoint)
R=[ones(30,1);zeros(30,1);ones(30,1);zeros(30,1)];
p.y=0;  % Initial output
p.v=[]; % empty past input to indicate initialization
% buffer of input to cope with time delay
u=zeros(3,1);
% Initialization of variables for results
Y=zeros(N,1);
U=zeros(N,1);
% DMC Simulation
for k=1:120
    p.a=0;
    p.r=R(k:min(N,k+p.p)); % DMC knows future setpoint
    if k>60     % change smoothing factor for second half simulation
        p.a=0.7;
    end
    p=dmc(p);
    Y(k)=p.y;
    U(k)=p.u;
    u=[u(2:3);p.u];
    p.y=0.8351*p.y+0.2713*u(1); % actual plant output 
end
% DMC results
subplot(211)
plot(1:N,Y,'b-',1:N,R,'rREPLACE_WITH_DASH_DASH',[60 60],[-0.5 1.5],':','linewidth',2)
title('solid: output, dashed: reference')
text(35,1,'\alpha=0')
text(95,1,'\alpha=0.7')
axis([0 120 -0.5 1.5])
subplot(212)
[xx,yy]=stairs(1:N,U);
plot(xx,yy,'-',[60 60],[-0.5 1.5],':','linewidth',2)
axis([0 120 -1 2])
title('input, \lambda=0.1')
xlabel('time, min')

%% Reference
% Camacho, E.F. and Bordons, C., Model Predictive Control, Springer-Verlag,
% 1999.
##### SOURCE END #####-->   </body></html>

⌨️ 快捷键说明

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