[37] | 1 | function 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 | |
---|
| 10 | for 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 |
---|
| 60 | end |
---|
| 61 | |
---|
| 62 | function s = symbmonom(names,monom) |
---|
| 63 | s = ''; |
---|
| 64 | for 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 | |
---|
| 79 | end |
---|
| 80 | |
---|
| 81 | function 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 | |
---|