source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/@sdpvar/sym.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 3.2 KB
Line 
1function symb_pvec = sdisplay(pvec,symbolicname)
2%SDISPLAY Symbolic display of SDPVAR expression
3%
4% Note that the symbolic display only work if all
5% involved variables are explicitely defined as
6% scalar variables.
7%
8% Variables that not are defined as scalars
9% will be given the name ryv(i). ryv means
10% recovered YALMIP variables, i indicates the
11% index in YALMIP (i.e. the result from getvariables)
12%
13% If you want to change the generic name ryv, just
14% pass a second string argument
15%
16% EXAMPLES
17%  sdpvar x y
18%  sdisplay(x^2+y^2)
19%    ans =
20%       'x^2+y^2'
21%
22%  t = sdpvar(2,1);
23%  sdisplay(x^2+y^2+t'*t)
24%    ans =
25%      'x^2+y^2+ryv(5)^2+ryv(6)^2'
26
27
28% Author Johan Löfberg
29% $Id: sym.m,v 1.1 2005/02/22 16:50:11 johanl Exp $
30allnames = {};
31for pi = 1:size(pvec,1)
32    for pj = 1:size(pvec,2)
33        Y.type = '()';
34        Y.subs = [{pi} {pj}];
35        p = subsref(pvec,Y);
36      %  p = pvec(pi,pj);
37       
38        if isa(p,'double')
39            symb_p = num2str(p);
40        else
41            LinearVariables = depends(p);
42            x = recover(LinearVariables);
43            exponent_p = full(exponents(p,x));
44            names = cell(length(x),1);
45            for i = 1:length(names)
46                names{i} = ['x' num2str(LinearVariables(i))];   
47                allnames{end+1} = names{i};
48            end
49           
50            symb_p = '';
51            if all(exponent_p(1,:)==0)
52                symb_p = num2str(full(getbasematrix(p,0)));
53                exponent_p = exponent_p(2:end,:);
54            end
55           
56            for i = 1:size(exponent_p,1)
57                coeff = full(getbasematrixwithoutcheck(p,i));
58                switch coeff
59                    case 1
60                        coeff='+';
61                    case -1
62                        coeff = '-';
63                    otherwise
64                        if isreal(coeff)
65                        if coeff >0
66                            coeff = ['+' num2str2(coeff)];
67                        else
68                            coeff=[num2str2(coeff)];
69                        end
70                        else
71                            coeff = ['+' '(' num2str2(coeff) ')' ];
72                        end
73                end         
74                symb_p = [symb_p coeff symbmonom(names,exponent_p(i,:))];                               
75            end
76            if symb_p(1)=='+'
77                symb_p = symb_p(2:end);
78            end
79        end
80        symb_pvec{pi,pj} = symb_p;
81    end
82end
83allnames = unique(allnames);
84for i = 1:length(allnames)
85    evalin('caller',['syms ' allnames{i}]);
86end
87
88
89S = '';
90for pi = 1:size(pvec,1)
91    ss = '';
92    for pj = 1:size(pvec,2)
93        ss = [ss ' ' symb_pvec{pi,pj} ','];
94    end
95    S = [S ss ';'];
96end
97S = ['[' S ']']   ;           
98symb_pvec = evalin('caller',S);
99
100
101function s = symbmonom(names,monom)
102s = '';
103for j = 1:length(monom)
104    if abs( monom(j))>0
105        s = [s names{j}];
106        if monom(j)~=1
107            s = [s '^' num2str(monom(j))];
108        end
109        s =[s '*'];
110    end
111   
112end
113if isequal(s(end),'*')
114    s = s(1:end-1);
115end
116
117function s = num2str2(x)
118s = num2str(full(x));
119if isequal(s,'1')
120    s = '';
121end
122if isequal(s,'-1')
123    s = '-';
124end
125
126       
Note: See TracBrowser for help on using the repository browser.