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

    %% Evaluate Scenario at Specific Time Instant 
%
%%
% Define a plant model.

% Copyright 2015 The MathWorks, Inc.

ts = 2;
Plant = ss(0.8,0.5,0.25,0,ts);
%%
% Create a model predictive controller with MV and MVRate constraints. The
% prediction horizon is ten intervals. The control horizon is blocked.
MPCobj = mpc(Plant, ts, 10, [2 3 5]);
MPCobj.MV(1).Min = -2;
MPCobj.MV(1).Max = 2;
MPCobj.MV(1).RateMin = -1;
MPCobj.MV(1).RateMax = 1;
%%
% Initialize an mpcstate object for simulation from a particular state.
x = mpcstate(MPCobj);
x.Plant = 2.8;
x.LastMove = 0.85;
%%
% Compute the optimal control at current time.
y = 0.25*x.Plant;
r = 1;
[u,Info] = mpcmove(MPCobj,x,y,r);
%%
% Analyze the predicted optimal sequences.
[ts,us] = stairs(Info.Topt,Info.Uopt);
plot(ts,us,'r-',Info.Topt,Info.Yopt,'b--')
legend('MV','OV')
%%
% |plot| ignores |Info.Uopt(end)| as it is NaN.
%%
% Examine the optimal cost.
Info.Cost