Skip to content

Tutorial

jruths edited this page Jun 21, 2024 · 15 revisions

This tutorial provides an introduction to zonoLab including:

  • creating zonotopes, constrained zonotopes, and hybrid zonotopes,
  • performing set-based operations,
  • visualizing sets in 2D and 3D, and
  • advanced operations requiring optimization.

The following examples provide code, which you can copy and run in MATLAB, along with images of the corresponding outputs and/or plots. Code for these examples is also provided in Tutorial.m.

Creating Sets

Sets of the hybZono, conZono, and zono classes can be created multiple ways, which are all described in more detail in the comments provided at the top of each class definition file. Here are some examples of how to define a zonotope, constrained zonotope, and hybrid zonotope.

MATLAB code Resulting output

Creating a zonotope:

G = [1 0 1;0 1 1];  % Generator matrix with 3 generators
c = zeros(2,1);     % Center at the origin
Z = zono(G,c)       % Creates a zonotope

zonotope

Creating a constrained zonotope:

G = [1 0 1;0 1 1];   % Generator matrix with 3 generators
c = zeros(2,1);      % Center at the origin
A = ones(1,3);       % Constraint matrix with 1 constraint
b = 1;               % Constraint offset vector
C = conZono(G,c,A,b) % Creates a constrained zonotope

constrained zonotope

Creating a hybrid zonotope:

Gc = [1 0 1;0 1 1];          % Continuous generator matrix with 3 generators
Gb = [1 2;2 1];              % Binary generator matrix with 2 generators
c = zeros(2,1);              % Center at the origin
Ac = ones(1,3);              % Continuous constraint matrix with 1 constraint
Ab = ones(1,2);              % Binary constraint matrix with 1 constraint
b = 1;                       % Constraint offset vector
H = hybZono(Gc,Gb,c,Ac,Ab,b) % Creates a hybrid zonotope

hybrid zonotope

Note that nGc and nGb properties denote the number of continuous and binary factors for the hybZono class corresponding to the continuous and binary generator and constraint matrices, Gc, Gb, Ac, and Ab. Alternatively, for the conZono class, nG is used to denote the number of (continuous) factors corresponding to the generator and constraint matrices G and A.

Set Operations

The abstractZono class is an abstract superclass for hybZono, conZono, and zono that enables many operations to be performed regardless of the type of zonotopic set. For more information, please see the complete list of functions. Here are some examples of how to compute linear mappings, Minkowski sums, and generalized intersections based on the sets defined above.

MATLAB code Resulting output

Linear mapping of a zonotope from 2D to 3D using overloaded * (mtimes) operator:

M = [1 0;0 1;1 1];  % 3x2 matrix
Zm = M*Z            % Linear mapping

mtimes

Minkowski sum of a zonotope and constrained zonotope using overloaded + (plus) operator:

ZC = Z + C   % Minkowski sum

plus

Intersection of a hybrid zonotope and a constrained zonotope using the overloaded & (and) operator:

HC = H & C   % Intersection

and

Plotting

Plotting in 2D and 3D for hybZono, conZono, and zono objects is based on identifying the vertices and faces needed to use the patch function in MATLAB. Here are two examples of how to plot sets.

MATLAB code Resulting output

Plot a random zonotope in 3D as transparent blue and output vertex and face information:

seed = 2;
n = 3;
nG = 3;
Zr = randomSet(seed,'zono',n,nG);
figure;
[v,f] = plot(Zr,'b',0.1)

mtimes

Plot a hybrid zonotope with custom options:

optsPlot = plotOptions;
optsPlot.FaceColor = 'r';
optsPlot.FaceAlpha = 0.5;
optsPlot.LineWidth = 3;
figure; 
plot(H,optsPlot)

plus

Note that the output v contains the vertices of the set where each row corresponds to a vertex and each column corresponds to a dimension. Currently, there is no effort to identify and remove duplicate vertices so some points may be repeated (like in the example above). The output f contains the faces of the set where the indices stored in ith row of f denote the rows of the v matrix for each vertex in the ith face. For hybZono and conZono objects, different faces may contain different numbers of vertices, in which case the rows of f are padded with NaN.

Clone this wiki locally