source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/extras/sdpvar2str.m @ 37

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

Added original make3d

File size: 2.4 KB
Line 
1function symb_pvec = sdpvar2str(pvec)
2%SDPVAR2STR Converts an SDPVAR object to MATLAB string representation
3%
4% S = SDPVAR2STR(P)
5%
6% S : String
7% P : SDPVAR object
8
9
10for pi = 1:size(pvec,1)
11    for pj = 1:size(pvec,2)
12        p = pvec(pi,pj);
13       
14        if isa(p,'double')
15            symb_p = num2str(p);
16        else
17            LinearVariables = depends(p);
18            x = recover(LinearVariables);
19            exponent_p = full(exponents(p,x));
20            names = cell(length(LinearVariables),1);
21            for i = 1:length(LinearVariables)
22                names{i}=['x(' num2str(LinearVariables(i)) ')'];
23            end
24           
25            symb_p = '';
26            if all(exponent_p(1,:)==0)
27                symb_p = num2str(getbasematrix(p,0));
28                exponent_p = exponent_p(2:end,:);
29            end
30           
31            for i = 1:size(exponent_p,1)
32                coeff = getbasematrixwithoutcheck(p,i);
33                switch full(coeff)
34                    case 1
35                        coeff='+';
36                    case -1
37                        coeff = '-';
38                    otherwise
39                        if coeff >0
40                            coeff = ['+' num2str2(coeff)];
41                        else
42                            coeff=[num2str2(coeff)];
43                        end
44                end   
45                if strcmp(symb_p,'') & (strcmp(coeff,'+') | strcmp(coeff,'-'))
46                        symb_p = [symb_p coeff symbmonom(names,exponent_p(i,:))];
47                    else
48                symb_p = [symb_p coeff '*' symbmonom(names,exponent_p(i,:))];
49            end
50            end
51            if symb_p(1)=='+'
52                symb_p = symb_p(2:end);
53            end
54        end
55       
56        symb_p = strrep(symb_p,'+*','+');
57        symb_p = strrep(symb_p,'-*','-');
58        symb_pvec{pi,pj} = symb_p;
59    end
60end
61
62function s = symbmonom(names,monom)
63s = '';
64for j = 1:length(monom)
65    if monom(j)~=0
66        if strcmp(s,'')
67            s = [s names{j}];
68        else
69            s = [s '*' names{j}];
70        end
71    end
72    if monom(j)~=1
73        s = [s '^' num2str(monom(j))];
74    end
75%      if monom(j)>1
76%        s = [s '^' num2str(monom(j))];
77%    end
78   
79end
80
81function s = num2str2(x)
82        s = num2str(x);
83        if isequal(s,'1')
84            s = '';
85        end
86        if isequal(s,'-1')
87            s = '-';
88        end
89 
Note: See TracBrowser for help on using the repository browser.