Line | |
---|
1 | yalmip('clear'); |
---|
2 | clc |
---|
3 | echo on |
---|
4 | %********************************************************* |
---|
5 | % |
---|
6 | % Dual variables |
---|
7 | % |
---|
8 | %********************************************************* |
---|
9 | % |
---|
10 | % Dual variables can easily be extracted from the |
---|
11 | % optimal solution using YALMIP |
---|
12 | % |
---|
13 | pause |
---|
14 | |
---|
15 | % Let us solve a Lyapuov stability problem |
---|
16 | A = [-1 2;0 -2]; |
---|
17 | P = sdpvar(2,2); |
---|
18 | F = set(P>eye(2),'Normalize P') + set(A'*P+P*A<0,'Lyapunov stability'); |
---|
19 | pause % Strike any key to continue. |
---|
20 | |
---|
21 | % Find minimum trace solution |
---|
22 | solution = solvesdp(F,trace(P)); |
---|
23 | pause % Strike any key to continue. |
---|
24 | clc |
---|
25 | |
---|
26 | % The dual solutions are readily obtained using simple indexing |
---|
27 | dual(F(1)) |
---|
28 | dual(F(2)) |
---|
29 | pause |
---|
30 | clc |
---|
31 | |
---|
32 | % ... or with the tags |
---|
33 | dual(F('Normalize P')) |
---|
34 | dual(F('Lyapunov stability')) |
---|
35 | pause |
---|
36 | clc |
---|
37 | |
---|
38 | % Complementary slackness ... |
---|
39 | trace(double(F(1))*dual(F(1))) |
---|
40 | trace(double(F(2))*dual(F(2))) |
---|
41 | pause |
---|
42 | echo off |
---|
Note: See
TracBrowser
for help on using the repository browser.