⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 replace.m

📁 国外专家做的求解LMI鲁棒控制的工具箱,可以相对高效的解决LMI问题
💻 M
字号:
function Z = replace(X,Y,W)
%REPLACE Substitutes variables
%
%Z = REPLACE(Y,X,W)  Replaces any occurence of the SDPVAR object Y 
%                    in the SDPVAR object X with the double W
%
% Example
%  x = sdpvar(1,1);
%  t = sdpvar(1,1);
%  Y = [1+t;1+x+t];
%  Y = replace(Y,x,2) generates Y=[1+t;3+t]

% Author Johan L鰂berg 
% $Id: replace.m,v 1.6 2005/02/13 18:29:31 johanl Exp $  

if ~isa(X,'sdpvar')
  error('First arguments must be an sdpvar object') 
end
if ~isa(Y,'sdpvar')
  error('Second arguments must be an sdpvar object') 
end
if ~is(Y,'linear')
  error('Second arguments must be linear') 
end
if ~isa(W,'double')
  error('Third arguments must be a double') 
end
if ~isequal(size(Y),size(W))
  error('Both arguments must have same size') 
end

y_lmi_variables = Y.lmi_variables;
b = W(:)-Y.basis(:,1);
A = Y.basis(:,2:end);
feas_var = A\b;
if norm(A*feas_var-b)>sqrt(eps)
  error('Inconsistent assignment')
end

x_lmi_variables = X.lmi_variables;
n = X.n;
m = X.m;

[monomtable,variabletype] = yalmip('monomtable');
if all(variabletype(x_lmi_variables)==0) % is(X,'linear')
    Z = X.basis(:,1);
    for i = 1:length(x_lmi_variables)
        j = find(x_lmi_variables(i) == y_lmi_variables);
        if isempty(j)
            Z = Z + recover(x_lmi_variables(i))*X.basis(:,i+1);
        else
            Z = Z + feas_var(j)*X.basis(:,i+1);
        end
    end
else
    replaced_vars = depends(Y);
   % used_variables = getvariables(X);
    used_variables = x_lmi_variables;
  %  monomtable = yalmip('monomtable');
    local_monom = monomtable(used_variables,replaced_vars);
    W = W(:)';
    for i = 1:length(used_variables)
        gain(i) = prod(W.^local_monom(i,:));
    end

    local_monoms_left = monomtable(used_variables,:);
    local_monoms_left(:,replaced_vars) = 0;
    used_left = find(sum(local_monoms_left,1));
    base = recovermonoms(local_monoms_left(:,used_left),recover(used_left));
    base = base.*gain(:);
    Z = X.basis(:,1);
    Z = Z + X.basis(:,2:end)*base;

end
if isa(Z,'sdpvar')
    Z.n = n;
    Z.m = m;
    Z.typeflag = X.typeflag;
else
    Z = reshape(full(Z),n,m);
end



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -