Hide minor edits - Show changes to markup
Now we want to verify how the controller performs if connected to a different system, say x^+ = A x + B u
with A = [1 1; 0.2 1]
, B = [1; 0.8]
:
Now we want to verify how the controller performs if connected to a different system, say {$ x^+ = A x + B u $} with {$ A = \begin{bmatrix} 1 & 1 \\ 0.2 & 1 \end{bmatrix} $}, {$ B = \begin{bmatrix} 1 \\ 0.8 \end{bmatrix} $}:
A = [1 1; 0 1]
, B = [1; 0.5]
[-5; -5] <= x <= [5; 5]
-1 <= u <= 1
As an example, consider MPC for a linear system x^+ = A x + B u
with following properties:
As an example, consider MPC for a linear system {$ x^+ = A x + B u$} with following properties:
NOTE: if you change the controller and/or the system in your MATLAB workspace, the change(s) will automatically propagate to the closed-loop object without the need to re-create it. In other words, in the example above we can as well do:
-1 <= x <= 1
-1 <= u <= 1
prediction_model.x.penalty = Penalty([1 0; 0 1], 2); prediction_model.u.penalty = Penalty(1, 2);
prediction_model.x.penalty = QuadFunction([1 0; 0 1]); prediction_model.u.penalty = QuadFunction(1);
MPT3 introduces a special object to represent closed-loop systems, consisting of a dynamical system and an MPC controller:
(:source lang=MATLAB -getcode:)loop = ClosedLoop(mpc, sys)
where mpc
represents an MPC controller (either on-line or explicit MPC), and sys
describes the dynamical system.
After a closed-loop object is constructed, you can simulate it by
(:source lang=MATLAB -getcode:)data = loop.simulate(x0, Nsim)
where x0
is the initial state for the simulation, and Nsim
is the number of simulation steps.
As an example, consider MPC for a linear system x^+ = A x + B u
with following properties:
A = [1 1; 0 1]
, B = [1; 0.5]
[-5; -5] <= x <= [5; 5]
-1 <= x <= 1
prediction_model = LTISystem('A', [1 1; 0 1], 'B', [1; 0.5]); prediction_model.x.min = [-5; -5]; prediction_model.x.max = [5; 5]; prediction_model.u.min = -1; prediction_model.u.max = 1; prediction_model.x.penalty = Penalty([1 0; 0 1], 2); prediction_model.u.penalty = Penalty(1, 2); N = 4; mpc = MPCController(prediction_model, N);
Now we want to verify how the controller performs if connected to a different system, say x^+ = A x + B u
with A = [1 1; 0.2 1]
, B = [1; 0.8]
:
simulation_model = LTISystem('A', [1 1; 0.2 1], 'B', [1; 0.8]); loop = ClosedLoop(mpc, simulation_model); x0 = [4; 0]; Nsim = 20; data = loop.simulate(x0, Nsim) data = X: [2x21 double] U: [1x20 double] Y: [] cost: [1x20 double] plot(data.X')
mpc.N = 10; data = loop.simulate(x0, Nsim)
and the simulation will automatically use the new controller with prediction horizon 10
.