assign.m
来自「国外专家做的求解LMI鲁棒控制的工具箱,可以相对高效的解决LMI问题」· M 代码 · 共 57 行
M
57 行
function assign(X,value,ls)
%ASSIGN Assigns a numerical value to an sdpvar
%
% ASSIGN(X,value) Tries to set the free variables in X so that
% double(X)=value. Notice that other variables
% sharing the same free variables will be affected.
% If the assignment is infeasible, an error message
% will be issued.
%
% ASSIGN(X,value,1) Least square assignment.
% Author Johan L鰂berg
% $Id: assign.m,v 1.2 2005/05/31 16:08:22 joloef Exp $
if nargin<3
ls = 0;
end
if ~isa(X,'sdpvar')
error('First argument should be an SDPVAR object.');
end
if ~isa(value,'double')
error('Second argument should be a DOUBLE.');
end
if ~isequal(size(X),size(value))
error('Both arguments must have same size')
end
if ~isa(X,'sdpvar')
error('First arguments must be an sdpvar object')
end
x_lmi_variables = X.lmi_variables;
b = value(:)-X.basis(:,1);
A = X.basis(:,2:end);
feas_var = A\b;
% Improve
e = A*feas_var-b;
de = A\e;
feas_var = feas_var-de;
if ~ls
if norm(A*feas_var-b)>sqrt(eps)
error('Inconsistent assignment')
end
end
sol = yalmip('getsolution');
keep_these = find(~ismember(sol.variables,x_lmi_variables));
sol.optvar = [sol.optvar(keep_these);feas_var(:)];
sol.variables = [sol.variables(keep_these);x_lmi_variables(:)];
yalmip('setallsolution',sol);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?