-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsosineq.m
executable file
·172 lines (154 loc) · 5.95 KB
/
sosineq.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
function sos = sosineq(sos,symexpr,info,info2)
% SOSINEQ --- Add a new inequality constraint f(x) >= 0
% to an SOS program
%
% SOSP = sosineq(SOSP,EXPR)
%
% SOSP is the sum of squares program.
% EXPR is the expression on the left hand side of the constraint, i.e., f(x).
%
% EXPR can be a column vector. In this case, several inequality
% constraints will be added simultaneously to the sum of
% squares program.
%
% SOSP = sosineq(SOSP,EXPR,[a b]) is used to specify the interval
% a <= x <= b where f(x) has to be non-negative. Currently, this is
% possible only if the sum of squares program is univariate, and the input
% is of type 'sym'. The lower limit a can be -Inf, and similarly b can be +Inf.
%
% SOSP = sosineq(SOSP,EXPR,'sparse') will use the fact that a polynomial
% is sparse to compute a sum of squares decomposition using an optimally
% reduced set of monomials, which makes the size of the resulting semidefinite
% program smaller.
%
% SOSP = sosineq(SOSP,EXPR,'sparsemultipartite',VARCELLS) will enable
% efficient exploitation of sparse multipartite structure. In this case,
% VARCELLS is a cell which describes the partition of the independent
% variables. For example
%
% SOSP = sosineq(SOSP,EXPR,'sparsemultipartite',{[x,y],[z]})
%
% corresponds to multipartite structure where the partition of the
% independent variables are {x,y} and {z}.
%
% This file is part of SOSTOOLS - Sum of Squares Toolbox ver 4.00.
%
% Copyright (C)2002, 2004, 2013, 2016, 2018, 2021
% A. Papachristodoulou (1), J. Anderson (1),
% G. Valmorbida (2), S. Prajna (3),
% P. Seiler (4), P. A. Parrilo (5),
% M. Peet (6), D. Jagt (6)
% (1) Department of Engineering Science, University of Oxford, Oxford, U.K.
% (2) Laboratoire de Signaux et Systmes, CentraleSupelec, Gif sur Yvette,
% 91192, France
% (3) Control and Dynamical Systems - California Institute of Technology,
% Pasadena, CA 91125, USA.
% (4) Aerospace and Engineering Mechanics Department, University of
% Minnesota, Minneapolis, MN 55455-0153, USA.
% (5) Laboratory for Information and Decision Systems, M.I.T.,
% Massachusetts, MA 02139-4307
% (6) Cybernetic Systems and Controls Laboratory, Arizona State University,
% Tempe, AZ 85287-6106, USA.
%
% Send bug reports and feedback to: [email protected]
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Change log and developer notes
% 03/20/02 - SP -- Interval info
% 12/15/21 - DJ -- Interval adjustment for dpvar case
if isfield(sos,'symvartable')
% Interval
if nargin > 2 & isnumeric(info)
if length(sos.symvartable) ~= 1
error('Not a univariate polynomial.');
end;
for i = 1:size(symexpr,1)
symexpr(i) = preprocess(symexpr(i),sos.symvartable,info);
sos = sosconstr(sos,'ineq',symexpr(i));
sos.expr.type{sos.expr.num} = 'posint';
end;
return;
end;
elseif nargin > 2 && isnumeric(info) % DJ, 12/15/21
if length(sos.vartable) ~= 1
error('Not a univariate polynomial.');
end
for i = 1:size(symexpr,1)
xvar = pvar(sos.vartable{1});
symexpr(i) = polypreprocess(symexpr(i),xvar,info);
sos = sosconstr(sos,'ineq',symexpr(i));
sos.expr.type{sos.expr.num} = 'posint';
end
return;
end;
% Sparse polynomial
if nargin > 2 & strcmp(info,'sparse');
for i = 1:size(symexpr,1)
sos = sosconstr(sos,'ineq',symexpr(i));
sos.expr.type{sos.expr.num} = 'sparse';
end;
return;
end;
% Sparse polynomial
if nargin > 2 & strcmp(info,'sparsemultipartite');
for i = 1:size(symexpr,1)
sos = sosconstr(sos,'ineq',symexpr(i));
sos.expr.type{sos.expr.num} = 'sparsemultipartite';
sos.expr.multipart{sos.expr.num} = info2;
end;
return;
end;
sos = sosconstr(sos,'ineq',symexpr);
% ============================================================
function newsymexpr = preprocess(symexpr,var,info)
% Get the maximum degree of the independent variable
maxdeg = 0;
dummy = diff(symexpr,var);
while dummy ~= 0
maxdeg = maxdeg+1;
dummy = diff(dummy,var);
end;
% Substitute var
if info(2)==Inf
newvar = var+info(1);
newsymexpr = subs(symexpr,var,newvar);
elseif info(1)==-Inf
newvar = -var+info(2);
newsymexpr = subs(symexpr,var,newvar);
else
newvar = (info(2)-info(1))/2*(1-var)/(1+var) + (info(2)+info(1))/2;
newsymexpr = subs(symexpr,var,newvar)*(1+var).^maxdeg;
end;
% ============================================================
function pnewsymexpr = polypreprocess(psymexpr,var,info)
% Get the maximum degree of the independent variable
maxdeg = 0;
dummy = diff(psymexpr,var);
while any(dummy.C ~= 0)
maxdeg = maxdeg+1;
dummy = diff(dummy,var);
end
% Substitute var
if info(1)==-Inf && info(2)==Inf
pnewsymexpr = psymexpr;
elseif info(2)==Inf
newvar = var+info(1);
pnewsymexpr = subs(psymexpr,var,newvar);
elseif info(1)==-Inf
newvar = -var+info(2);
pnewsymexpr = subs(psymexpr,var,newvar);
else
error('Imposing inequality on finite interval is not supported for pvar/dpvar implementation')
end