source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/extras/parseLMI.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 3.2 KB
Line 
1function sdpvarExpr = parseLMI(X)
2%PARSELMI Internal function for dirty parsing of lmi string
3
4% Author Johan Löfberg
5% $Id: parseLMI.m,v 1.3 2004/07/27 14:11:57 johanl Exp $
6
7
8% Assume Error
9
10% TypeofConstraint = 1;
11
12% Check for obsolete notation .<, .>, =
13single_equality = findstr(X,'=');
14if isempty(findstr(X,'>=')) & isempty(findstr(X,'<=')) & (rem(length(single_equality),2) == 1) % There is a single =   
15    error('Obsolete constraint =, use == in equalities.');
16    %X = strrep(X,'=','==');
17    %X = strrep(X,'====','=='); % Whoops, == replaced with =====!
18end
19
20if ~isempty(findstr(X,'.<'))
21    disp(' ');
22    disp('Warning: Obsolete constraint .<, use < in equalities.');
23    disp('If you have a Hermitian matrix which you want to')
24    disp('constrain to have negative values, use ,e.g.,  P(:)<0')
25    disp('The constraint has been changed to <')
26    disp(' ');
27    X = strrep(X,'.<','<');
28end
29
30if ~isempty(findstr(X,'.>'))
31    disp(' ');
32    disp('Warning: Obsolete constraint .>, use > in equalities.');
33    disp('If you have a Hermitian matrix which you want to')
34    disp('constrain to have negative values, use e.g.  P(:)>0')
35    disp('The constraint has been changed to >')
36    disp(' ');
37    X = strrep(X,'.>','>');
38end
39
40% Any norm? If not, we're done!
41if isempty(findstr(X,'||'))
42    sdpvarExpr = X;
43    return
44end
45
46
47% The only actual parsing needed is for the ||Axplusb||<cx+d notation
48delimiters = {'.<','.>','<.','>.','<','>','==',''};
49delindex = 0;indtodel = [];
50while isempty(indtodel) & (delindex<=7)
51    delindex = delindex+1;
52    indtodel = findstr(X,delimiters{delindex});
53end
54
55switch delindex
56    case 5 %<
57        TypeofConstraint = 1;
58        ind_start =  indtodel-1;
59        ind_end   =  indtodel+1;
60        REVERSE   = 1;
61    case 6 %>
62        TypeofConstraint = 1;
63        ind_start =  indtodel-1;
64        ind_end   =  indtodel+1;
65        REVERSE   = 0;
66    case 7%=
67        TypeofConstraint = 3;
68        ind_start = indtodel-1;
69        ind_end   = indtodel+2;
70        REVERSE   = 0;
71    case {3,4}
72        error('Incorrect argument. Perhaps you mean .> or .<');
73    otherwise
74        error('Incorrect argument. Could not find <=>.>.<')
75end
76
77LeftHand   = X(1:ind_start);
78RightHand  = X(ind_end:end);
79
80if REVERSE
81    temp = LeftHand;
82    LeftHand = RightHand;
83    RightHand = temp;
84end
85
86% Search for a norm expression
87ind_norm_Right = findstr(RightHand,'||');
88ind_norm_Left  = findstr(LeftHand,'||');
89
90% Any norm at all, if not, we're done!
91if isempty(ind_norm_Right) & isempty(ind_norm_Left)
92    sdpvarExpr = [LeftHand '-(' RightHand ')'];
93    return
94end
95
96% Equality constrained norm?
97if (TypeofConstraint == 3) & (ind_norm_Right | ind_norm_Left)
98    error('Equality constraints cannot be used with ||..|| operator');
99end
100
101% Convex normconstraint?
102if ~isempty(ind_norm_Left)
103    error('Norm ||..|| must look like || column vector ||< scalar, or scalar>|| vector ||')
104end
105
106% Everthing seem ok in norm
107TypeofConstraint = 4;
108Axplusb = RightHand(2+ind_norm_Right(1):ind_norm_Right(2)-1);
109WithoutNorm = strrep(RightHand,RightHand(ind_norm_Right(1):ind_norm_Right(2)+1),'0');
110if length(WithoutNorm)==1
111    cxplusd = LeftHand;
112else
113    cxplusd = [LeftHand '-(' WithoutNorm ')'];
114end
115
116sdpvarExpr = ['cone( ' Axplusb ',' cxplusd ')'];
117
118
Note: See TracBrowser for help on using the repository browser.