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

📄 sdisplay.m

📁 国外专家做的求解LMI鲁棒控制的工具箱,可以相对高效的解决LMI问题
💻 M
字号:
function symb_pvec = sdisplay(pvec,symbolicname)
%SDISPLAY Symbolic display of SDPVAR expression
%
% Note that the symbolic display only work if all
% involved variables are explicitely defined as
% scalar variables.
%
% Variables that not are defined as scalars
% will be given the name ryv(i). ryv means
% recovered YALMIP variables, i indicates the 
% index in YALMIP (i.e. the result from getvariables)
%
% If you want to change the generic name ryv, just
% pass a second string argument
%
% EXAMPLES
%  sdpvar x y
%  sdisplay(x^2+y^2)
%    ans = 
%       'x^2+y^2'
%
%  t = sdpvar(2,1);
%  sdisplay(x^2+y^2+t'*t)
%    ans = 
%      'x^2+y^2+ryv(5)^2+ryv(6)^2'


% Author Johan L鰂berg
% $Id: sdisplay.m,v 1.5 2005/04/21 14:41:00 joloef Exp $

for pi = 1:size(pvec,1)
    for pj = 1:size(pvec,2)
        p = pvec(pi,pj);
        
        if isa(p,'double')
            symb_p = num2str(p);
        else
            LinearVariables = depends(p);
            x = recover(LinearVariables);
            exponent_p = full(exponents(p,x));
            names = cell(length(x),1);
            W = evalin('caller','whos');
            for i = 1:size(W,1)
                if strcmp(W(i).class,'sdpvar')% | strcmp(W(i).class,'lmi')
                    thevars = evalin('caller',W(i).name)    ;
                    if is(thevars,'scalar') & is(thevars,'linear') & length(getvariables(thevars))==1
                        index_in_p = find(ismember(LinearVariables,getvariables(thevars)));
                        if ~isempty(index_in_p)
                            names{index_in_p}=W(i).name;
                        end
                    else
                        % Hmm, let's be clever then and find out a name
                        vars = getvariables(thevars);
                        indicies = find(ismember(vars,LinearVariables));
                        for i = indicies%1:length(vars)
                            index_in_p = find(ismember(LinearVariables,vars(i)));
                            if ~isempty(index_in_p) & isempty(names{index_in_p})
                                names{index_in_p}=['ryv(' num2str(vars(i)) ')'];
                            end
                        end
                    end
                end
            end
            
            symb_p = '';
            if all(exponent_p(1,:)==0)
                symb_p = num2str(full(getbasematrix(p,0)));
                exponent_p = exponent_p(2:end,:);
            end
           
            for i = 1:size(exponent_p,1)
                coeff = full(getbasematrixwithoutcheck(p,i));
                switch coeff
                    case 1
                        coeff='+';
                    case -1
                        coeff = '-';
                    otherwise
                        if isreal(coeff)
                        if coeff >0
                            coeff = ['+' num2str2(coeff)];
                        else
                            coeff=[num2str2(coeff)];
                        end
                        else
                            coeff = ['+' '(' num2str2(coeff) ')' ];
                        end
                end                   
                symb_p = [symb_p coeff symbmonom(names,exponent_p(i,:))];
            end
            if symb_p(1)=='+'
                symb_p = symb_p(2:end);
            end
        end
        symb_pvec{pi,pj} = symb_p;
    end
end

if prod(size(symb_pvec))==1 & nargout==0

  display(symb_pvec{1,1});

  clear symb_pvec

end

function s = symbmonom(names,monom)
s = '';
for j = 1:length(monom)
    if abs( monom(j))>0
        s = [s names{j}];
        if monom(j)~=1
            s = [s '^' num2str(monom(j))];
        end
    end
end

function s = num2str2(x)
        s = num2str(full(x));
        if isequal(s,'1')
            s = '';
        end
        if isequal(s,'-1')
            s = '-';
        end
  
        

⌨️ 快捷键说明

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