UI /

# Stability

## Important note

This feature is currently only available in development releases of MPT3. To install the latest development version, run the following:

tbxmanager source add http://www.tbxmanager.com/package/unstable.xml/mpt
tbxmanager update

## Construction of Lyapunov functions

MPT3 allows to construct piecewise quadratic (PWQ) Lyapunov functions for autonomous PWA systems via the PWASystem/lyapunov() method.

Example which verifies closed-loop stability of an explicit MPC controller:

model = LTISystem('A', [1 1; 0 1], 'B', [1; 0.5]);
model.x.min = [-5; -5];
model.x.max = [5; 5];
model.u.min = -1;
model.u.max = 1;
model.x.penalty = QuadFunction(eye(2));
model.u.penalty = QuadFunction(1);
% add LQR terminal set and terminal penalty
model.x.with('terminalSet');
model.x.terminalSet = model.LQRSet();
model.x.with('terminalPenalty');
model.x.terminalPenalty = model.LQRPenalty();

N = 5; % prediction horizon
empc = MPCController(model, N).toExplicit();

% create a closed-loop system
loop = ClosedLoop(empc, model);

% convert the closed-loop system into an autonomous PWA system
autpwa = loop.toSystem();

% construct the PWQ Lyapunov function
L = autpwa.lyapunov('pwq');

% plot the PWQ Lyapunov function
L.fplot('lyapunov');

It is also possible to verify whether a given explicit MPC controller provides closed-loop stability when coupled with a different system:

% a different model will be used for the verification
anothermodel = LTISystem('A', [1 1; 0 0.9], 'B', [1; 0.5]);

% convert the closed-loop system into an autonomous PWA system
autpwa = ClosedLoop(empc, anothermodel).toSystem();

% construct the PWQ Lyapunov function
L = autpwa.lyapunov('pwq');

% plot the PWQ Lyapunov function
L.fplot('lyapunov');