📄 double.m
字号:
function sys=double(X)
%DOUBLE Returns current numerical value
% Author Johan L鰂berg
% $Id: double.m,v 1.18 2005/06/20 07:27:03 joloef Exp $
solution = yalmip('getsolution');
lmi_variables = X.lmi_variables;
opt_variables = solution.variables;
% Definition of nonlinear variables
[mt,variabletype] = yalmip('monomtable');
nonlinears = lmi_variables(find(variabletype(X.lmi_variables)));
if ~isempty(solution.values)
if max(lmi_variables) <= length(solution.values) & isempty(nonlinears)
if ~any(isnan(solution.values(lmi_variables(:))))
% Yihoo, we can do this really fast by
% re-using the old values
sys = X.basis*[1;solution.values(lmi_variables(:))];
if X.typeflag==10
sys = eig(full(reshape(sys,X.n,X.m)));
else
sys = full(reshape(sys,X.n,X.m));
end
return
end
end
end
% Okey, we could not do it really fast...
% Definition of nonlinear variables
allextended = yalmip('extvariables');
if isempty(nonlinears) & isempty(allextended) & all(ismembc(lmi_variables,solution.variables))
% speed up code for simple linear case
values = solution.values;
if isempty(solution.values)
values = zeros(size(mt,1),1);
values(solution.variables) = solution.optvar;
yalmip('setvalues',values);
else
if any(isnan(solution.values(lmi_variables(:))))
values = zeros(size(mt,1),1);
values(solution.variables) = solution.optvar;
yalmip('setvalues',values);
end
end
sys = X.basis*[1;values(lmi_variables(:))];
if X.typeflag==10
sys = eig(full(reshape(sys,X.n,X.m)));
else
sys = full(reshape(sys,X.n,X.m));
end
return
end
% All double values
values(size(mt,1),1)=nan;values(:)=nan;
values(solution.variables) = solution.optvar;
% Evaluate the extended operators
if ~isempty(allextended)
extended_variables = find(ismembc(X.lmi_variables,allextended));
if ~isempty(extended_variables)
for i = 1:length(extended_variables)
extvar = lmi_variables(extended_variables(i));
extstruct = yalmip('extstruct',extvar);
for k = 1:length(extstruct.arg)
if isa(extstruct.arg{k},'sdpvar') | isa(extstruct.arg{k},'constraint')
extstruct.arg{k} = double(extstruct.arg{k});
end
end
switch extstruct.fcn
case 'mpower' %
val = extstruct.arg{1};
case {'max','min'} % Cannot take several inputs, put everything in a vector
val = feval(extstruct.fcn,[extstruct.arg{:}]);
case {'or','and'}
try
val = feval(extstruct.fcn,extstruct.arg{:});
catch
val = nan;
end
otherwise % VAL = OPERATOR(X1,X2,...)
try
val = feval(extstruct.fcn,extstruct.arg{:});
catch
val = nan;
end
end
values(extvar) = full(val);
end
end
end
if ~isempty(nonlinears)
mt_t = mt'; %Working columnwise is faster
use_these = find(ismember(lmi_variables,nonlinears));
for i=use_these
monom_i = mt_t(:,lmi_variables(i));
used_in_monom = find(monom_i);
extended_variables = find(ismember(used_in_monom,yalmip('extvariables')));
if ~isempty(extended_variables)
for ii = 1:length(extended_variables)
extvar = used_in_monom(extended_variables(ii));
extstruct = yalmip('extstruct',extvar);
for k = 1:length(extstruct.arg)
if isa(extstruct.arg{k},'sdpvar')
extstruct.arg{k} = double(extstruct.arg{k});
end
end
switch extstruct.fcn
case 'mpower' %
val = extstruct.arg{1};
case {'max','min'} % Cannot take several inputs, put everything in a vector
val = feval(extstruct.fcn,[extstruct.arg{:}]);
otherwise % VAL = OPERATOR(X1,X2,...)
val = feval(extstruct.fcn,extstruct.arg{:});
end
values(extvar) = val;
end
end
the_product = 1;
for j = 1:length(used_in_monom)
the_product = the_product*values(used_in_monom(j))^monom_i(used_in_monom(j));
end
values(lmi_variables(i)) = the_product;
end
end
sys = X.basis*[1;values(lmi_variables(:))];
if X.typeflag==10
sys = eig(full(reshape(sys,X.n,X.m)));
else
sys = full(reshape(sys,X.n,X.m));
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -