Syntax |
c = binary(x) |
c:
|
sdpvar object (only useful in
set) |
x:
|
sdpvar object |
|
Description |
binary is used to constrain a variables to be binary. |
Examples |
Setting up a binary linear program {min cTx
subject to Ax≤b} can be done as
x = binvar(n,1);
solvesdp(set(A*x<b),c'*x)
|
or
x = sdpvar(n,1);
solvesdp(set(A*x<b)+set(binary(x)),c'*x)
|
Note, the binary constraint is imposed on the involved variables,
not the actual sdpvar object. Hence,
the following two constraints are equivalent
F = set(binary(x));
F = set(binary(pi+sqrt(2)*x));
|
|
Related commands |
intvar,
sdpvar,
binvar, set |
|
Syntax
|
x = binvar(n,m,'field','type') |
n:
|
Height |
m:
|
Width |
'field':
|
char {'real','complex'} |
'type':
|
char {'symmetric','full','hermitian','toeplitz','hankel','skew'} |
|
Description |
binvar is used to define symbolic decision variables
with binary elements. |
Examples |
A scalar binary variable is defined with
For more examples, see sdpvar.
|
Related commands |
intvar,
sdpvar,
integer,
binary, set |
|
Syntax |
[p,d] = checkset(F) |
F:
|
set object |
p:
|
Primal constraint residuals |
d:
|
Dual constraint residuals |
|
Description |
checkset is used to examine satisfaction of constraints
in a set object. |
Examples |
After solving a problem, we can easily check how
well the constraints are satisfied.
solvesdp(F,objective);
checkset(F)
|
The constraint residuals are defined as smallest eigenvalue, smallest
element, negated largest absolute-value element and largest distance
to an integer for semidefinite, element-wise, second order cone and
integrality constraints respectively. Hence, a solution is feasible
if all residuals related to inequalities are non-negative and residuals
related to equalities are sufficiently close to zero.
Sometimes it might be convenient to have the numerical values of
the constraint violations
|
Related commands |
set,
solvesdp |
|
Syntax |
y = clean(x,tol) |
y:
|
sdpvar object |
x:
|
sdpvar object |
tol:
|
double (tolerance) |
|
Description |
clean is used to remove base matrices in an
sdpvar object that are small (mainly
used together with solvesos) |
Examples |
Removing nuisance variables
x1 = sdpvar(n,1);
x2 = sdpvar(n,1);
x = x1+1e-8*x2;
y = clean(x,1e-6);
polyprint(y)
ans
'x1'
|
|
Related commands |
sos,
sdpvar |
|
|
c = cone(x,y) |
c:
|
sdpvar object (only useful in set object) |
x:
|
sdpvar object (vector) |
y:
|
sdpvar object (scalar) |
|
Description |
cone is used to define the constraints
||x||≤y |
Examples |
Constraining the Euclidean norm of a vector to
be less than 1 is done with
x = sdpvar(n,1);
F = set(cone(x,1));
|
Of-course, arbitrary complicated constructs are possible, such
as constraining the norm of the diagonal to be less than the sum of
the off-diagonal terms in a matrix!
x = sdpvar(n,n);
F = set(cone(diag(x),sum(sum(x-diag(diag(x))))))
|
An alternative is to use the nonlinear norm operator instead
(see the examples on nonlinear
operators for details)
x = sdpvar(n,n);
F = set(norm(diag(x)) < sum(sum(x-diag(diag(x)))))
|
|
Related commands |
rcone,
set, sdpvar |
|
Syntax
|
F = cut(X,'tag') |
F:
|
set object |
X:
|
sdpvar or constraint object, or string |
'tag':
|
char |
|
Description |
cut is used to define user-specified cuts for the
global BMI solver. |
Example |
The result from this command is nothing but a
set object.
P = sdpvar(2,2);
F = cut((P-eye(2))*(P-eye(2))>0);
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| ID| Constraint| Type|
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| #1| Numeric value| Matrix inequality (quadratic) 2x2|
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
The only difference is that this constraint will not be used in
the upper bound problem in the branch & bound procudure. The constraint
will thus only be used to improve the relaxations. See the examples
in global solutions of bilinear
programs.
|
Related commands |
set |
|
Syntax |
Y = double(X) |
Y:
|
double |
X:
|
sdpvar or set object |
|
Description |
double is used to extract the numerical value of
a decision variable, or the residual of a constraint |
Examples |
After solving an optimization problem we might,
e.g., extract the optimal objective value.
solvesdp(F,obj);
optobj = double(obj);
|
It can also be used to extract the residual of a constraint
solvesdp(F,obj);
res = double(F(1));
|
|
Related commands |
sdpvar,
solvesdp,
setsdpvar |
|
Syntax |
Z = dual(F) |
Z:
|
double |
F:
|
set object (with one constraint) |
|
Description |
dual is used to extract the dual variable related
to a constraint |
Examples |
After solving an optimization problem we might,
e.g., extract the dual variable of the 2nd constraint.
solvesdp(F,obj);
Z2 = dual(F(2));
|
If the constraints in the set object have been tagged, we can use
the tag instead
solvesdp(F,obj);
Z2 = dual(F('Lyapunov constraint'));
|
|
Related commands |
set,
solvesdp,
sdpvar |
|
Syntax |
[Fd,objd,y,X] = dualize(F,obj) |
F:
|
set object in primal SDP form |
obj:
|
sdpvar object (primal cost) |
Fd:
|
set object in dual SDP form |
objd:
|
sdpvar object (dual cost) |
y:
|
sdpvar object (dual variables) |
X:
|
cell of sdpvar objects (primal variables) |
|
Description |
dualize is used to convert a SDP problem given
in primal form to the corresponding dual problem. |
Examples |
Consider the following SDP problem in primal
form.
X = sdpvar(3,3);
Y = sdpvar(3,3);
F = set(X>0) + set(Y>0);
F = F + set(X(1,3)==9) + set(Y(1,1)==X(2,2)) + set(sum(sum(X))+sum(sum(Y)) == 20);
obj = trace(X)+trace(Y);
|
We can solve this in the given format. This will however be
very inefficient in YALMIP, since the matrices X and Y will be
explicitely parameterized, and the problem will be solved in a
dual form with equality constraints. Instead, we note that the
problem is an SDP in standard primal form. We therefor let YALMIP
extract this primal model, and return the dual of this. If we
solve this problem, the dual of this will be the original primal.
Confused yet? (note that the dual objective should be maximized)
[Fd,objd,y,XX] = dualize(F,obj);
solvesdp(Fd,-objd);
|
To obtain our original variables, we extract the duals
setsdpvar(XX{1},dual(Fd(1));
setsdpvar(XX{2},dual(Fd(2));
|
|
Related commands |
dual,
set,
solvesdp,
sdpvar |
|
Syntax
|
[model,recoverymodel]
= export(F,h,ops) |
model:
|
Output structure. |
recoverymodel: |
Output structure. |
F:
|
set object describing the constraints. |
h:
|
sdpvar-object describing the objective function. |
ops:
|
options structure from sdpsettings. |
|
Description |
export is used to export YALMIP models to
various solver formats (note : not all
solvers are supported yet) |
Examples |
Consider a Lyapunov stability problem
A = randn(5,5);A = -A*A';
P = sdpvar(5,5);
F = set(A'*P+P*A < 0) + set(P>eye(5));
obj = trace(P);
|
Exporting this to a model in SeDuMi format is done by
specifying the solver as 'sedumi' and calling export in the same way
as solvesdp would have ben called.
[model,recoverymodel] = export(F,obj,sdpsettings('solver','sedumi'));
model =
A: [50x15 double]
b: [15x1 double]
C: [50x1 double]
K: [1x1 struct]
pars: [1x1 struct]
|
The data in recoverymodel can be used to relate a solution
obtained from using the exported model, to the actual variables in
YALMIP.
[x,y] = sedumi(model.A,model.b,model.C,model.K);
setsdpvar(recover(recoverymodel.used_variables),y);
|
Some solvers do not support equality constraints. One way to
handle this in YALMIP is to use sdpsettings('remove',1) .
If this is done, YALMIP derives basis and
solves the problem in the reduced variables. This basis is
communicated through the structure recoverymodel .
[model,recoverymodel] = export(F+set(trace(P)==10),obj,sdpsettings('solver','sedumi','remove',1));
[x,y] = sedumi(model.A,model.b,model.C,model.K);
setsdpvar(recover(recoverymodel.used_variables),recoverymodel.x_equ + recoverymodel.H*y);
|
|
Related commands |
solvesdp |
|
Syntax |
H = hessian(f,x) |
H:
|
sdpvar object |
f:
|
scalar sdpvar object |
x:
|
sdpvar object |
|
Description |
jacobian calculates the Jacobian d2f/dx2 |
Examples |
With only 1 argument, the differentiation is performed
with respect to all involved variables
x1 = sdpvar(1,1);
x2 = sdpvar(1,1);
f = x1^4+5*x2^2;
polyprint(hessian(f))
ans =
'12x1^2' '0'
'0' '10'
|
Giving a second argument controls what variables to differentiate
with respect to
polyprint(hessian(f,x1))
ans =
'12x1^2'
|
|
Related commands |
jacobian,
polyprint,
sdpvar |
|
Syntax |
c = integer(x) |
c:
|
sdpvar object (only useful in set object) |
x:
|
sdpvar object |
|
Description |
integer is used to constrain a set of variable
to be integer. |
Examples |
Setting up a integer linear program {min
cTx subject to Ax≤b}
can be done as
x = intvar(n,1);
solvesdp(set(A*x<b),c'*x)
|
or
x = sdpvar(n,1);
solvesdp(set(A*x<b)+set(integer(x),c'*x)
|
Note, the integrality constraint is imposed on the involved variables,
not the actual sdpvar object. Hence, the following
two constraints are equivalent
F = set(integer(x));
F = set(integer(pi+sqrt(2)*x));
|
|
Related commands |
intvar,
sdpvar,
binvar, set |
|
Syntax |
x = intvar(n,m,'field','type') |
n:
|
Height |
m:
|
Width |
'field':
|
char {'real','complex'} |
'type':
|
char {'symmetric','full','hermitian','toeplitz','hankel','skew'} |
|
Description |
intvar is used to define symbolic decision variables
with integer elements. |
Examples |
A scalar integer variable is defined with
For more examples, see sdpvar.
|
Related commands |
binvar,
sdpvar,
integer,
binary, set |
|
Syntax |
y = is(x,'property') |
y:
|
logical |
x:
|
sdpvar or set object |
property:
|
char {'real', 'symmetric', 'hermitian', 'scalar', 'linear',
'homogeneous', 'integer', 'binary'} for sdpvar objects,
{'elementwise', 'socc','lmi', 'linear', 'kyp'} on set objects |
|
Description |
is is used to check properties of sdpvar and set
objects. |
Examples |
Checking if an sdpvar
object is linear can be done with is
x = sdpvar(1,1);
y = [x;x*x];
is(y,'linear')
ans =
0
|
The command works almost in the same way on set
objects, with the difference that the check is performed on every
constraint in the set object separately,
so the output can be a vector
x = sdpvar(1,1);
F = set(x>1) + set([1 x;x 1]>0) + set(x<3);
is(F,'elementwise')
ans =
1
0
1
|
Hence, creating a set object containing only
the element-wise constraints is done with
F_element = F(is(F,'elementwise'));
|
|
Related commands |
sdpvar,
set |
|
Syntax |
J = jacobian(f,x) |
J:
|
sdpvar object |
f:
|
sdpvar object |
x:
|
sdpvar object |
|
Description |
jacobian calculates the Jacobian df/dx. |
Examples |
With only 1 argument, the differentiation is performed
with respect to all involved variables (more precisely, with respect
to the variables recover(depends(f)))
x1 = sdpvar(1,1);
x2 = sdpvar(1,1);
f = x1^2+5*x2^2;
polyprint(jacobian(f))
ans =
'2x1' '10x2'
|
Giving a second argument controls what variables to differentiate
with respect to
polyprint(jacobian(f,x2))
ans =
'10x2'
|
|
Related commands |
hessian,
polyprint,
sdpvar |
|
Syntax |
x = kyp(A,B,P,M) |
x:
|
sdpvar object (only useful in set) |
A:
|
double (square matrix) |
B:
|
double |
P:
|
sdpvar object (symmetric) |
M:
|
sdpvar object (symmetric) |
|
Description |
kyp is used to define LMIs related to the KYP-lemma
and Lyapunov equations |
Examples |
Defining the Lyapunov constraint
ATP+PA<0 can be done using
kyp
Tthe following command is equivalent
but the difference is that YALMIP does not know that the constraint
is a Lyapunov equation, hence it will not be able to use the dedicated
solver KYPD.
kyp can also be used to define more
complex constraints. The following two commands generate the constraint
[ATP+PA PB;BTP 0] + M(x)
< 0 (P and x are decision variables).
F = set([A'*P+P*A P*B;B'*P zeros(size(B,2))]+M < 0);
F = set(kyp(A,B,P,M) < 0);
|
The dedicated solver KYPD can only
be used if the variable P is symmetric matrix, obtained directly
from sdpvar,
used only in 1 constraint. This means that you cannot use
KYPD if you want to impose explicit
constraints (including positive definiteness) on P. However,
positive definiteness of P is in some cases implied by the
KYP constraint
|
Related commands |
sdpvar,
set |
|
Syntax |
h = linearize(p) |
h:
|
sdpvar object |
p:
|
sdpvar object |
|
Description |
Returns linearization p(double(x)) + dp(double(x))*(x-double(x))
where x is the sdpvar variables
defining the polynomial p(x). |
Examples |
The linearization is performed at the current value
of double(x)
x = sdpvar(1,1);
f = x^2;
setsdpvar(x,1);
polyprint(linearize(f))
ans =
'-1+2x'
setsdpvar(x,3);
polyprint(linearize(f))
ans =
'-9+6x'
|
The command of-course applies to matrices as well
p11 = sdpvar(1,1);p12 = sdpvar(1,1);p22 = sdpvar(1,1);
P = [p11 p12;p12 p22];
setsdpvar(P,[3 2;2 5])
polyprint(linearize(P*P))
ans =
'-13+6p11+4p12' '-16+2p11+8p12+2p22'
'-16+2p11+8p12+2p22' '-29+4p12+10p22'
|
|
Related commands |
jacobian,
hessian,
polyprint,
sdpvar |
|
Syntax |
p = logdet(x) |
p:
|
sdpvar object (only useful in
solvesdp) |
x:
|
sdpvar object |
|
Description |
logdet is used to define objective functions in
MAXDET problems. This command will likely become obsolete in a
future version. |
Examples |
See MAXDET example. |
Related commands |
solvesdp,
sdpvar |
|
Syntax |
H = lowrank(F,x) |
H:
|
set object (only useful in
solvesdp) |
F:
|
sdpvar object |
x: |
sdpvar object |
|
Description |
lowrank is used to declare that a semidefinite
constraint uses data with low rank. |
Examples |
Define a semidefinite constraint
with low-rank data matrices (both variables in x enter the
constraint via rank-2 matrices)
x = sdpvar(2,1);
C = randn(10,10);C = C*C';
R = randn(10,2);
F = set(C-R*diag(x)*R' > 0);
|
If a low-rank data exploiting solver is available (currently
only
SDPLR), we can ask YALMIP to extract low-rank
information and pass this to the solver.
solvesdp(F + lowrank(F),-sum(x),sdpsettings('solver','sdplr'));
|
In some cases, the low-rank structure is only with respect to
some variables, as here where y enters via a full rank matrix.
In this cases, it might be counter productive to try to exploit
the (non-existing) low rank.
x = sdpvar(2,1);
y = sdpvar(1,1);
C = randn(10,10);C = C*C';
R = randn(10,2);
S = randn(10,10);S = S+S';
F = set(C-R*diag(x)*R'-y*S > 0);
|
In this case, it is possible to tell YALMIP which variables
enter in a low-rank fashion, here x.
solvesdp(F+lowrank(F,x),-sum(x)-y,sdpsettings('solver','sdplr'));
|
An alternative way to work with low rank data matrices is to
use the option sdpsettings('sdprl.maxrank'). By changing this
setting from it default value of 0, YALMIP will automatically
check all data matrices for low rank structure, and send low rank
data to the solver if the rank is less than the value of
sdpsettings('sdprl.maxrank'). Hence, YALMIP will exploit low rank
w.r.t x but not y in the following solution.
solvesdp(F,-sum(x)-y,sdpsettings('solver','sdplr','sdplr.maxrank',2));
|
|
Related commandss |
solvesdp |
|
Syntax
|
p = plot(F,x,c,n,options) |
F:
|
set object |
x:
|
sdpvar variable |
c:
|
char or double |
n:
|
double |
options: |
options structure from sdpsettings |
|
Description |
plot is used to plot the (projection) of the feasible
set |
Examples |
Define a set in R3
x = sdpvar(3,1);
F = set([1 x(2);x(2) x(1)])+set(3 > x);
F = F + set([1 x';x eye(3)]>0) + set(sum(x)>x'*x);
|
Plot the feasible set, projected on (x1,x3)
By default, the feasible set is projected on the first two variables
(lowest index in YALMIP)
Why not the feasible set on x1=0.5
plot(replace(F,x(1),0.5))
|
A third argument can be used to control the color
A fourth argument can be used to control the accuracy
The fifth argument can be used to pass an options structure for
the solver
plot(F,[],[],[],sdpsettings('solver','sedumi'));
|
|
Related commands |
set |
|
Description |
Polyprint is obsolete and replaced with
sdisplay |
|
Syntax
|
c = rcone(x,y,z) |
c:
|
sdpvar object (only useful in set object) |
x:
|
sdpvar object (vector) |
y:
|
sdpvar object (scalar) |
z:
|
sdpvar object (scalar) |
|
Description |
rcone is used to define the constraints zTz<2xy,
x,y>0 (The rotated Lorentz cone) |
Examples |
Constraining the squared Euclidean norm of a vector
to be less than 2 is done with
x = sdpvar(n,1);
F = set(rcone(x,1,1));
|
|
Related commands |
cone,
set,
sdpvar |
|
Syntax
|
saveampl(F,h,filename) |
F:
|
set object describing the constraints |
h:
|
sdpvar object describing the objective function |
filename:
|
char (can be []) |
|
Description |
saveampl exports a YALMIP model to an AMPL model. |
Examples |
Well, not much to say. Here is a simple MILP exported
to an AMPL model
x = sdpvar(3,1);
A = randn(5,3);
b = randn(5,1);
c = randn(3,1);
F = set(A*x < b) + set(integer(x(2:3)));
saveampl(F,c'*x,'myamplmodel.mod');
|
|
Related commands |
sdpvar,
solvesdp |
|
Syntax |
t =
sdisplay(p) |
t:
|
cell array of chars |
p:
|
sdpvar object |
|
Description |
Tries to display an sdpvar object in symbolic
form |
Examples |
The command is useful for displaying polynomial
sdpvar objects
x = sdpvar(1,1);y = sdpvar(1,1);
f = [x;x^2+y+x*y];
sdisplay(f)
ans =
'x'
'y+x^2+xy'
|
To be useful, all variables have to have been explicitly defined.
Hence, coding the function above using an
sdpvar object of length two instead
would not give any useful display (this might be fixed in future versions)
x = sdpvar(2,1);
f = [x(1);x(1)^2+x(2)+x(1)*x(2)];
sdisplay(f)
ans =
''
'+^2+'
|
|
Related commands |
sdpvar,
jacobian,
hessian |
|
Syntax
|
options =
sdpsettings('field',value,'field','value',...) |
'field':
|
Option to be modified |
'value':
|
New setting |
|
Description |
sdpsettings is used to set parameters to control
the behavior of the solvers and YALMIP |
Examples |
The easiest way to see what the possible options
are is to define a options structure and display it
ops = sdpsettings
ops =
solver: ''
verbose: 1
warning: 1
beeponproblem: [-2 -1 4 5 6 7 8 9 10 11]
showprogress: 0
cachesolvers: 0
saveduals: 1
removeequalities: 0
savesolveroutput: 0
savesolverinput: 0
convertconvexquad: 1
radius: inf
shift: 0
relax: 0
usex0: 0
sos: [1x1 struct]
bnb: [1x1 struct]
maxdet: [1x1 struct]
sdpt3: [1x1 struct]
sdpa: [1x1 struct]
sedumi: [1x1 struct]
dsdp: [1x1 struct]
csdp: [1x1 struct]
glpk: [1x1 struct]
pensdp: [1x1 struct]
penbmi: [1x1 struct]
miqp: [1x1 struct]
kypd: [1x1 struct]
quadprog: [1x1 struct]
linprog: [1x1 struct]
|
Changing a value from the default settings is done as
ops = sdpsettings('solver','dsdp','verbose',0)
|
In the code above, we told YALMIP to use the solver DSDP, and to
run in silent mode. The possible values to give to the field
solver can be found in the introduction
to the solvers.
By setting verbose to 0, the solvers will run with
minimal display. By increasing the value, the display level is controlled
(typically 1 gives modest display level while 2 gives an awful amount
of information printed). The warning option can be used
to get a warning displayed when a solver has run into some kind of
problem (recommended to be used if the solver is run in silent mode).
The field beeponproblem contains a list of error codes
(see yalmiperror). YALMIP will beep if any of these errors occurs
(nice feature if you're taking a coffee break during heavy calculations).
When the field showprogress is set to 1, the user
can see what YALMIP currently is doing (might be a good idea for large-scale
problems).
Everytime solvesdp is called, YALMIP checks
for available solvers. This can take a while on some systems (some
networks), so it is possible to avoid doing this check every call.
Set cachesolvers to 1, and YALMIP will remember the solvers
(using a persistent variable) found in the first call to
solvesdp. If solvers are added to the path
after the first call, YALMIP will not detect this. Hence, after adding
a solver to the path the work-space must be cleared or
solvesdp must be called once with cachesolvers
set to 0.
When the field removeequalities is set to 1, YALMIP
removes equality constraints using a QR decomposition and reformulates
the problem using a smaller set of variables. With removeequalities
set to 2, equalities are removed by YALMIP by converting them to
double-sided inequalities. When set to 0, YALMIP does nothing if
the solver supports equalities. If the solver does not support
equalities, YALMIP uses double-sided inequalities.
If the field saveduals is set to 0, the dual variables
will not be saved in YALMIP. This might be useful for large sparse
problems with a dense dual variable. Setting the field to 0 will then
save some memory.
The fields savesolverinput and savesolveroutput
can be used to see what is actually sent to and returned from the
solver. This data will then be available in the output structure from
solvesdp.
With convertconvexquad set to 1, YALMIP will try to
convert quadratic constraints to second order cones.
A constraint ||x||≤radius
on the vector of all involved decision variables can be
added by changing the field radius to a finite positive
value. This can improve numerical performance in some cases. In fact,
the field radius may be an sdpvar
object.
Strict inequalities can be modelled in YALMIP by using the > and
< when defining constraints. The behaviour of this feature can be
altered using the option shift . For constraints definied
with strict constraints, a small perturbation is added (semidefinite
constraints F(x)>0 are changed to
F(x)≥shift*I, while element-wise
constraints are changed from F(x)>0
to F(x)≥shift). Note that the
use of this feature does not guarante a stricly feasible solution.
This depends on the solver.
If relax is set to 1, all nonlinearities and integrality
constraints will be disregarded. Integer variables are relaxed to
continuous variables and nonlinear variables are treated as independent
variables (i.e., x and x2 will be
treated as two separate variables).
The current solution (the value returned from the
double command) can be used as an initial guess
when solving an optimization problem. Setting the field usex0
to 1 tells YALMIP to supply the current values as an initial guess
to the solver.
The options structure also contains a number of structures with
parameters used in the specific solver. As an example, the following
parameters can be tuned for SeDuMi (for details, the user is referred
to the manual of the specific solver).
ops.sedumi
ans =
alg: 2
theta: 0.2500
beta: 0.5000
eps: 1.0000e-009
bigeps: 0.0010
numtol: 1.0000e-005
denq: 0.7500
denf: 10
vplot: 0
maxiter: 100
stepdif: 1
w: [1 1]
stopat: -1
cg: [1x1 struct]
chol: [1x1 struct]
|
Finally, a convenient way to alter a lot of options is to send
an existing options structure as the first input argument.
ops = sdpsettings('solver','sdpa');
ops = sdpsettings(ops,'verbose',0);
|
|
Related commands |
solvesdp |
|
Syntax
|
x = sdpvar(n,m,'field','type') |
n:
|
Height |
m:
|
Width |
'field':
|
char {'real','complex'} |
'type':
|
char {'symmetric','full','hermitian','toeplitz','hankel','skew'} |
|
Description |
sdpvar is used to define symbolic decision variables. |
Examples |
A scalar real-valued variable is defined with
A square real-valued symmetric matrix is obtained with
The commands above can be simplified by only giving one argument
when defining a symmetric matrix or a scalar (this might not work
on MATLAB 5.3 and earlier version).
We can also define the same matrix using a more verbose notation.
P = sdpvar(n,n,'symmetric')
|
A fully parameterized square matrix requires a third argument.
A square complex-valued fully parameterized matrix is obtained
with
P = sdpvar(n,n,'full','complex')
|
YALMIP tries to complete the third and fourth argument, so an equivalent
command is
P = sdpvar(n,n,'sy','co')
|
Finally, note that multiple scalars can be defined using command
line syntax.
|
Related commands |
setsdpvar,
binvar,
intvar,
set |
|
Syntax |
see(x) |
|
Description |
see is used to print the base matrices of an
sdpvar object. |
Examples |
A symmetric 2x2 matrix has the following base matrices
x = sdpvar(2,2);
see(x)
Constant matrix
0 0
0 0
Base matrices
1 0
0 0
0 1
1 0
0 0
0 1
Used variables
1 2 3
|
When an sdpvar object is altered,
the base matrices change
x = sdpvar(1,1);
see(2*x-3)
Constant matrix
-3
Base matrices
2
Used variables
4
|
|
Related commands |
getbase,
getbasematrix,
getvariables,
recover,
sdpvar |
|
Syntax
|
F = set(X,'tag') |
F:
|
set object |
X:
|
sdpvar or constraint object, or string |
'tag':
|
char |
|
Description |
set is used to define the constraints in a problem |
Example |
To begin with, note that it is possible to create
an empty set object (this can be useful
in some loop-constructs).
Secondly, do not confuse the set
object with the standard command set in MATLAB. Yes, it is confusing,
but set was the only relevant short word for defining the feasible
set that I could come up with...
Constraining a scalar variable to be larger than 5 is done with
x = sdpvar(1,1)
F = set(x > 5)
|
The variable F serves as a container for all constraints
here. Defining a matrix to be both positive definite and elementwise
positive is done with
P = sdpvar(n,n);
F = set(P > 0) + set(P(:) > 0);
|
A string-notation can also be used
F = set('P > 0') + set('P(:) > 0')
|
A set object can be tagged with
a description (which can be useful for referencing a particular constraint
in, e.g., dual)
F = set(P > 0,'positive definite');
F = F + set(P(:)>0,'positive elements')
|
Second order cone constraints ||Ax+b||<cTx+d
can be added with the function cone
F = set(cone(A*x+b,c'*x+d))
|
Equality constraints can also be defined. A constraint that the
sum of the vector components is equal to 1 is obtained with
In general, it should be remembered that YALMIP uses MATLAB standard
when it comes to comparison of matrices and scalars. Hence, the following
code will constrain all diagonal elements to be larger than 1.
Double-sided constraints and extensions can easily be defined.
F = set(2 > diag(P) > 1 > sum(sum(P)))
|
It is possible to have complex and integer valued constraints.
No special code is necessary. To create a complex-valued integer Hermitian
matrix and constrain it to be positive definite, we write
P = intvar(3,3,'hermitian','complex');
F = set(P > 0)
|
Finally, notice that set objects
can be referenced
F = set(P > 0) + set(A'*P+P*A < 0) + set(P(1,1) > 0)+set(P(1,:) > 0);
F_lmi = F(1:2)
F_element = F(find(is(F,'element-wise')))
|
|
Related commands |
sdpvar,
integer,
binary,
solvesdp |
|
Syntax |
setsdpvar(X,Y) |
X:
|
sdpvar object |
Y:
|
double |
|
Description |
setsdpvar is used to explicitly set the value obtained
when applying the command double on an
sdpvar object |
Examples |
Variables are initialized as NaNs
x = sdpvar(1,1);
double(x)
ans =
NaN
|
By using setsdpvar, this
value can be altered
setsdpvar(x,1)
double(x)
ans =
1
|
By default, inconsistent assignments generate an error message.
t = sdpvar(1,1);x = [t t];
setsdpvar(x,[1 2])
??? Error using ==> sdpvar/setsdpvar
Inconsistent assignment
|
With a third argument, a least squares assignment is obtained
t = sdpvar(1,1);x = [t t];
setsdpvar(x,[1 2],1)
double(x)
ans =
1.5000 1.5000
|
|
Related commands |
sdpvar |
|
Syntax
|
[mpsolution,diagnostic]
= solvemp(F,h,ops,x) |
mpsolution:
|
Multiparametric solution |
diagnostic:
|
Output structure |
F:
|
set object describing the constraints. Can be []. |
h:
|
sdpvar-object describing the objective function. Can be []. |
ops:
|
options structure from sdpsettings. Can be []. |
x:
|
parametric variables. |
|
Description |
solvemp is used for solving multiparametric problems. |
Examples |
solvemp is used in the same way as
solvesdp, the only difference being the fourth
additional argument to define the parametric variables. See the
multiparametric example for details. |
Related commands |
sdpvar,
set,
sdpsettings,
solvemoment,
solvesdp,
solvesos |
|
Syntax
|
[sol,xoptimal,momentdata] = solvemoment(F,h,options,d) |
sol:
|
diagnostics structure from solvesdp |
F:
|
set object describing the constraints |
xoptimal:
|
Extracted global solutions |
momentdata:
|
Momentmatrices etc. |
h:
|
sdpvar object describing objective |
options:
|
structure from sdpsettings |
d:
|
integer>0 |
|
Description |
solvemoment computes lower bounds to polynomial
programs using Lasserre's moment-method. |
Examples |
The command is used for finding lower bounds on
a polynomial h(x), subject to constraints F(x), where F(x) is a collection
of polynomial inequalities. The following example is taken from [?].
x1 = sdpvar(1,1);x2 = sdpvar(1,1);x3 = sdpvar(1,1);
h = -2*x1+x2-x3;
F = set(x1*(4*x1-4*x2+4*x3-20)+x2*(2*x2-2*x3+9)+x3*(2*x3-13)+24>0)
F = F + set(4-(x1+x2+x3)>0);
F = F + set(6-(3*x2+x3)>0);
F = F + set(2-x1>0);
F = F + set(3-x3>0);
F = F + set(x1>0);
F = F + set(x2>0);
F = F + set(x3>0);
solvemoment(F,h);
double(h)
ans =
-6.0000
|
In the code above, we solved the problem with the lowest possible
lifting (decided by YALMIP), and the lower bound turned out to be
-6. A higher order relaxation gives better bounds.
solvemoment(F,h,[],2);
double(h)
ans =
-5.69
solvemoment(F,h,[],3);
double(h)
ans =
-4.0685
solvemoment(F,h,[],4);
double(h)
ans =
-4.0000
|
For a more complete introduction, please study the extensive
examples. |
Related commands |
solvesdp,
solvesos,
sdpvar,
set,
polyprint |
|
Syntax
|
diagnostics
= solvesdp(F,h,ops) |
diagnostic:
|
Output structure |
F:
|
set object describing the constraints. Can be []. |
h:
|
sdpvar-object describing the objective function. Can be []. |
ops:
|
options structure from sdpsettings. Can be []. |
|
Description |
solvesdp is the common function for solving all
optimization problems. |
Examples |
A linear program {min c'x
subject to Ax<= b} can be solved with the following
piece of code
x = sdpvar(length(c),1);
F = set(A*x<b)
solvesdp(F,c'*x);
|
If we only look for a feasible solution, we can omit the objective
function
Solving the feasibility problem with the solver
QUADPROG can be done with
solvesdp(F,[],sdpsettings('solver','quadprog'));
|
Minimizing an objective function is done by passiing a second argument
For more examples, run yalmipdemo
and check out all the
examples.
|
Related commands |
sdpvar,
set,
logdet,
sdpsettings,
solvemoment,
solvemp,
solvesos |
|
Syntax
|
[sol,m,B]
= solvesos(F,h,options,params) |
sol:
|
diagnostics structure from solvesdp |
m:
|
sdpvar object |
B:
|
cell with double |
F:
|
set object (Constraints on parametric variables and SOS constraints) |
h:
|
sdpvar object (Objective function) |
options:
|
structure from sdpsettings |
params: |
sdpvar object (The parametric variables) |
|
Description |
solvesos calculates SOS (sum-of-squares) decompositions. |
Examples |
In its most simple form,
solvesos takes a SOS constrained
polynomial and calculates the SOS decomposition.
x = sdpvar(1,1);
p = x^4+x+5;
F = set(sos(p)); % Constrain p to be a SOS
solvesos(F);
|
The SOS-decompositions should give p(x)=v(x)Tv(x)
v = sosd(F);
sdisplay(p-v'*v)
ans =
'-1.7764e-015+7.7716e-016x-1.1102e-015x^4'
|
Obviously, not entirely true. However the coefficients are small
and most likely due to numerical inaccuracy. Remove all terms with
coeffients smaller than 1e-6 using the command
clean
sdisplay(clean(p-v'*v,1e-6))
ans =
'0'
|
Parameterized SOS problems are also possible. As an example,
a lower bound on the global minimum of p
is obtained by finding a SOS decomposition of
p-t, while maximizing
t. The full syntax is
t = sdpvar(1,1);
F = set(sos(p-t));
solvesos(F,-t,[],t);
double(t)
ans =
4.5275
|
Parametric variables (the last argument in the code above) are
automatically detected if they are part of the objective function
or part of non-SOS constraints. Hence, the problem above can be simplified.
t = sdpvar(1,1);
F = set(sos(p-t));
solvesos(F,-t);
double(t)
ans =
4.5275
|
For more examples, run yalmipdemo
and check out the
examples in this manual.
|
Related commands |
sdpvar,
solvesdp,
solvemoment,
polyprint,
clean |
|
Syntax |
s = sos(p) |
s:
|
sdpvar object (only useful in
set) |
p:
|
polynomial scalar sdpvar object |
|
Description |
sos is used to define sum-of-squares (SOS) constraints |
Examples |
Solving a simple SOS problem and extracting the
decomposition is done as
x = sdpvar(1,1);
p = x^8+x^7+1;
F = set(sos(p));
solvesos(F);
polyprint(sosd(F))
ans =
'0.12828-0.062411x+0.12427x^2-0.49555x^3-0.99602x^4'
'0.99174+0.008073x-0.018071x^2+0.072068x^3+0.089115x^4'
|
|
Related commands |
solvesos,
sdpvar,
sosd |
|
Syntax |
v = sosd(F) |
v:
|
sdpvar object |
F:
|
set object with a sos constraint |
|
Description |
sosd is used to extract the SOS decomposition from
a sum-of-squares (SOS) constraint. |
Examples |
Solving a simple SOS problem and extracting the
decomposition is done as
x = sdpvar(1,1);
p = x^8+x^7+1;
F = set(sos(p));
solvesos(F);
polyprint(sosd(F))
ans =
'0.12828-0.062411x+0.12427x^2-0.49555x^3-0.99602x^4'
'0.99174+0.008073x-0.018071x^2+0.072068x^3+0.089115x^4'
|
|
Related commands |
solvesos,
sdpvar,
sos |
|
Syntax |
x = sparse(i,j,s,n,m) |
x:
|
sdpvar object |
i:
|
double |
j:
|
double |
s:
|
sdpvar object |
n:
|
sdpvar object |
m: |
double |
|
Description |
sparse is used to create
sdpvar objects with a certain structure. |
Examples |
Creating a diagonal matrix with every second diagonal
element zero can be done as
x = sparse(1:2:2*n,1:2:2*n,sdpvar(n,1))
|
|
Related commands |
sdpvar |
|
Syntax |
yalmip(command) |
command: |
char {'clear','info','version'} |
|
Description |
yalmip can be used to perform some adminstrative
stuff. |
Examples |
To clear the internals of YALMIP
Version number and release-date can be obtained
[vernum,reldate] = yalmip('version');
|
Additional information can be displayed using the 'info' tag
ver = yalmip('info')
**********************************
- - - - YALMIP 3 - - - - - - - - -
**********************************
Variable Size
No SDPVAR objects found
SET
No SET objects found
|
|
Related commands |
sdpsettings |
|
|
yalmipdemo |
|
Description |
yalmipdemo runs a set of tutorial problems |
Examples |
To start the tutorial
|
Related commands |
yalmiptest |
|
Syntax |
yalmiperror(x) |
|
Description |
yalmiperror returns the error-text for a error-code. |
Examples |
To se all available error codes,
yalmiperror
Error codes
-5 License problems in solver
-4 Solver not applicable
-3 Solver not found
-2 No suitable solver
-1 Unknown error
0 No problems detected
1 Infeasible problem
2 Unbounded objective function
3 Maximum iterations exceeded
4 Numerical problems
5 Lack of progress
6 Initial solution infeasible
7 YALMIP sent incorrect input to solver
8 Feasibility cannot be determined
9 Unknown problem in solver
10 bigM failed (increase sp.Mfactor)
11 Other identified error
12 Infeasible or unbounded
13 YALMIP cannot determine status in solver
|
To see a particular error message,
yalmiperror(3)
ans =
Maximum iterations exceeded
|
|
Related commands |
solvesdp |
|
Syntax |
yalmiptest(ops) |
ops: |
sdpsettings structure |
|
Description |
yalmiptest runs a set of test examples to test
the installation |
Examples |
To test the default installation
To test a particular solver
yalmiptest(sdpsettings('solver','sdpt3'))
|
|
Related commands |
sdpsettings |
|
|