www.gusucode.com > mpc 案例源码 matlab代码程序 > mpc/SimulateMPCControlOfMISOPlantExample.m

    %% Simulate MPC Control of MISO Plant
% Simulate the MPC control of a MISO system. The system has one manipulated
% variable, one measured disturbance, one unmeasured disturbance, and one
% output.
%%
% Create the continuous-time plant model. This plant will be used as the
% prediction model for the MPC controller.

% Copyright 2015 The MathWorks, Inc.

sys = ss(tf({1,1,1},{[1 .5 1],[1 1],[.7 .5 1]}));
%%
% Discretize the plant model using a sampling time of 0.2 units.
Ts = 0.2;
sysd = c2d(sys,Ts);
%%
% Specify the MPC signal type for the plant input signals.
sysd = setmpcsignals(sysd,'MV',1,'MD',2,'UD',3);
%%
% Create an MPC controller for the |sysd| plant model. Use default
% values for the weights and horizons.
MPCobj = mpc(sysd);
%%
% Constrain the manipulated variable to the |[0 1]| range.
MPCobj.MV = struct('Min',0,'Max',1);
%%
% Specify the simulation stop time.
Tstop = 30;
%% 
% Define the reference signal and the measured disturbance signal.
num_sim_steps = round(Tstop/Ts);
r = ones(num_sim_steps,1);
v = [zeros(num_sim_steps/3,1); ones(2*num_sim_steps/3,1)];
%%
% The reference signal, |r|, is a unit step. The measured disturbance
% signal, |v|, is a unit step, with a 10 unit delay.
%%
% Simulate the controller.
sim(MPCobj,num_sim_steps,r,v)