Rev | Line | |
---|
[37] | 1 | clc |
---|
| 2 | echo on |
---|
| 3 | %********************************************************* |
---|
| 4 | % |
---|
| 5 | % %Second order cone programming |
---|
| 6 | % |
---|
| 7 | %********************************************************* |
---|
| 8 | % |
---|
| 9 | % The problem is to find the point in the intersection of |
---|
| 10 | % two circles which is closest to the origin |
---|
| 11 | pause % Strike any key to continue. |
---|
| 12 | |
---|
| 13 | % The two circles are centered at a and b with radius 1, |
---|
| 14 | % and the point we are looking for will be denoted x |
---|
| 15 | a = [0;1]; |
---|
| 16 | b = [1;1]; |
---|
| 17 | x = sdpvar(2,1); |
---|
| 18 | pause % Strike any key to continue. |
---|
| 19 | |
---|
| 20 | % The point lies in both circles |
---|
| 21 | F = set('||x-a||<1')+set('||x-b||<1'); |
---|
| 22 | pause |
---|
| 23 | |
---|
| 24 | % An alternative way to define the SOCPs is |
---|
| 25 | F = set(cone(x-a,1))+set(cone(x-b,1)); |
---|
| 26 | pause |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | % The distance to the origin is limited |
---|
| 30 | % by a constant t |
---|
| 31 | t = sdpvar(1,1); |
---|
| 32 | F = F+set('||x||<t'); |
---|
| 33 | pause % Strike any key to continue. |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | % And we wish to minimize the distance |
---|
| 37 | sol = solvesdp(F,t); |
---|
| 38 | pause % Strike any key to continue. |
---|
| 39 | |
---|
| 40 | % Optimal point |
---|
| 41 | double(x) |
---|
| 42 | |
---|
| 43 | % Distance from origin |
---|
| 44 | double(t) |
---|
| 45 | |
---|
| 46 | % Which of-course equals ||x|| |
---|
| 47 | norm(double(x)) |
---|
| 48 | |
---|
| 49 | pause % Strike any key to continue. |
---|
| 50 | echo off |
---|
Note: See
TracBrowser
for help on using the repository browser.