TomSym example sdp - tomSym SDP demonstration

From TomWiki
Jump to navigationJump to search

Notice.png

This page is part of the TomSym Manual. See TomSym Manual.

An SDP example, from Wikipedia article about semidefinite programming

Minimize rac subject to [1 rab rac; rab 1 rbc; rac rbc 1] positive semidefinite -0.2 <= rab <= -0.1 0.4 <= rbc <= 0.5

% Variables
toms rab rac rbc

% Objective function
f = rac;

% Constraints
M = [1 rab rac; rab 1 rbc; rac rbc 1]
con = { positiveSemidefinite(M), ...
    -0.2 <= rab <= -0.1, ...
    0.4 <= rbc <=  0.5};

% Initial conditions
x0 = struct('rab',-0.15,'rbc',0.45,'rac',0);
 
M = tomSym(3x3):
 
   [[1 rab rac];[rab 1 rbc];[rac rbc 1]]
 

Compile and solve problem as a NLP

options = struct;
options.type = 'con';
options.name = 'SDP example';
solution = ezsolve(f,con,x0,options);

% Evaluate M using the returned solution
M_opt = subs(M,solution)
Warning: A semidefinite constraint is converted to a nonlinear constraint
involving 9 additional unknowns. 
Time for symbolic processing: 0.064665 seconds
Starting numeric solver
===== * * * =================================================================== * * *
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31
=====================================================================================
Problem: ---  1: SDP example                    f_k      -0.977997772830131120
                                       sum(|constr|)      0.000000000010720591
                              f(x_k) + sum(|constr|)     -0.977997772819410470
                                              f(x_0)      0.000000000000000000

Solver: snopt.  EXIT=0.  INFORM=1.
SNOPT 7.2-5 NLP code
Optimality conditions satisfied

FuncEv   11 GradEv    9 ConstrEv    9 ConJacEv    9 Iter    7 MinorIter   14
CPU time: 0.015600 sec. Elapsed time: 0.014000 sec. 
M_opt =
    1.0000   -0.2000   -0.9780
   -0.2000    1.0000    0.4000
   -0.9780    0.4000    1.0000

Compile and solve problem as a SDP

options.type = 'sdp';
solution = ezsolve(f,con,x0,options);

% Evaluate M using the returned solution
M_opt = subs(M,solution)
Time for symbolic processing: 0.018392 seconds
Starting numeric solver
===== * * * =================================================================== * * *
TOMLAB - TOMLAB Development license  999007. Valid to 2011-12-31
=====================================================================================
Problem: ---  1: SDP example                    f_k      -0.977997772825720870
                                              f(x_0)      0.000000000000000000

Solver: PENSDP.  EXIT=0.  INFORM=0.
LMI Solver PENSDP 2.2
Solution obtained.

FuncEv   17 GradEv   17 Iter   17 MinorIter   44
Elapsed time: 0.002000 sec. 
M_opt =
    1.0000   -0.2000   -0.9780
   -0.2000    1.0000    0.4000
   -0.9780    0.4000    1.0000

Check the eigenvalues

The eigenvalues should all be positive, even though small negative ones may occur due to tolerances.

eigenvalues = eigs(M_opt)
eigenvalues =
    2.1376
    0.8624
    0.0000