[37] | 1 | function symb_pvec = polyprint(pvec) |
---|
| 2 | %POLYPRINT Pretty print polynomial expression |
---|
| 3 | % |
---|
| 4 | % POLYPRINT is obsolete. Use SDISPLAY instead. |
---|
| 5 | |
---|
| 6 | % Author Johan Löfberg |
---|
| 7 | % $Id: polyprint.m,v 1.6 2004/09/15 16:30:54 johanl Exp $ |
---|
| 8 | |
---|
| 9 | for pi = 1:size(pvec,1) |
---|
| 10 | for pj = 1:size(pvec,2) |
---|
| 11 | p = pvec(pi,pj); |
---|
| 12 | |
---|
| 13 | if isa(p,'double') |
---|
| 14 | symb_p = num2str(p); |
---|
| 15 | else |
---|
| 16 | LinearVariables = depends(p); |
---|
| 17 | x = recover(LinearVariables); |
---|
| 18 | exponent_p = full(exponents(p,x)); |
---|
| 19 | names = cell(length(x),1); |
---|
| 20 | W = evalin('caller','whos'); |
---|
| 21 | for i = 1:size(W,1) |
---|
| 22 | if strcmp(W(i).class,'sdpvar')% | strcmp(W(i).class,'lmi') |
---|
| 23 | thevars = evalin('caller',W(i).name) ; |
---|
| 24 | if is(thevars,'scalar') & is(thevars,'linear') & length(getvariables(thevars))==1 |
---|
| 25 | index_in_p = find(ismember(LinearVariables,getvariables(thevars))); |
---|
| 26 | if ~isempty(index_in_p) |
---|
| 27 | names{index_in_p}=W(i).name; |
---|
| 28 | end |
---|
| 29 | end |
---|
| 30 | end |
---|
| 31 | end |
---|
| 32 | |
---|
| 33 | symb_p = ''; |
---|
| 34 | if all(exponent_p(1,:)==0) |
---|
| 35 | symb_p = num2str(full(getbasematrix(p,0))); |
---|
| 36 | exponent_p = exponent_p(2:end,:); |
---|
| 37 | end |
---|
| 38 | |
---|
| 39 | for i = 1:size(exponent_p,1) |
---|
| 40 | coeff = full(getbasematrixwithoutcheck(p,i)); |
---|
| 41 | switch coeff |
---|
| 42 | case 1 |
---|
| 43 | coeff='+'; |
---|
| 44 | case -1 |
---|
| 45 | coeff = '-'; |
---|
| 46 | otherwise |
---|
| 47 | if isreal(coeff) |
---|
| 48 | if coeff >0 |
---|
| 49 | coeff = ['+' num2str2(coeff)]; |
---|
| 50 | else |
---|
| 51 | coeff=[num2str2(coeff)]; |
---|
| 52 | end |
---|
| 53 | else |
---|
| 54 | coeff = ['+' '(' num2str2(coeff) ')' ]; |
---|
| 55 | end |
---|
| 56 | end |
---|
| 57 | symb_p = [symb_p coeff symbmonom(names,exponent_p(i,:))]; |
---|
| 58 | end |
---|
| 59 | if symb_p(1)=='+' |
---|
| 60 | symb_p = symb_p(2:end); |
---|
| 61 | end |
---|
| 62 | end |
---|
| 63 | symb_pvec{pi,pj} = symb_p; |
---|
| 64 | end |
---|
| 65 | end |
---|
| 66 | |
---|
| 67 | function s = symbmonom(names,monom) |
---|
| 68 | s = ''; |
---|
| 69 | for j = 1:length(monom) |
---|
| 70 | if abs( monom(j))>0 |
---|
| 71 | s = [s names{j}]; |
---|
| 72 | if monom(j)~=1 |
---|
| 73 | s = [s '^' num2str(monom(j))]; |
---|
| 74 | end |
---|
| 75 | end |
---|
| 76 | end |
---|
| 77 | |
---|
| 78 | function s = num2str2(x) |
---|
| 79 | s = num2str(full(x)); |
---|
| 80 | if isequal(s,'1') |
---|
| 81 | s = ''; |
---|
| 82 | end |
---|
| 83 | if isequal(s,'-1') |
---|
| 84 | s = '-'; |
---|
| 85 | end |
---|
| 86 | |
---|
| 87 | |
---|