1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
function []=ssprint(sl,out)
//ssprint(sl [,out]) pretty print of a linear system in state-space form
// sl=(A,B,C,D) syslin list.
// out=output (default out=%io(2))
// See also texprint.
//Examples:
// a=[1 1;0 1];b=[0 1;1 0];c=[1,1];d=[3,2];
// ssprint(syslin('c',a,b,c,d))
// ssprint(syslin('d',a,b,c,d))
//!
// Copyright INRIA
[lhs,rhs]=argn(0)
mess='system cannot be displayed in this page'
fil=%f
if rhs==1 then
out=%io(2),
else
if type(out)==10 then
out=file('open',out,'unknown')
fil=%t
end
end
deff('[ta]=%cv(x)',['[m,n]=size(x);';
'if m*n==0 then ta='' '',return,end';
'frmt=format();frmt=10**frmt(2)/maxi([1,norm(coeff(x))]);';
'x=round(frmt*x)/frmt;';
't=[];for k=1:m,t=[t;''|''],end;';
'ta=t;for k=1:n,';
' aa=string(x(:,k)),';
' for l=1:m,';
' if part(aa(l),1)<>''-'' then ';
' aa(l)='' ''+aa(l),';
' end,';
' end,';
' n=maxi(length(aa)),';
' aa=part(aa+blank,1:n),';
' ta=ta+aa+part(blank,1),';
'end;ta=ta+t;'])
//
// d(x)=ax + bu
//-------------
write(out,' ')
sgn='.';if sl(7)<>'c' then sgn='+',end
ll=lines();ll=ll(1)
[a,b,c,d]=sl(2:5)
na=size(a,'r')
[nc,nb]=size(d)
if na>0 then
blank=[];for k=1:na,blank=[blank;' '],end
ta=%cv(a);
tb=%cv(b);
//
blank=part(blank,1:4)
if na==1 then
t=[sgn+' ';'x = ']+[' ';ta]+[' ';'x']
else
blank([na/2,na/2+1])=[sgn+' ';'x = ']
t=blank+ta;
end
if nb>0 then
if na==1 then
t=t+[' ';' + ']+[' ';tb]+[' ';'u ']
else
blank([na/2,na/2+1])=[' ';'x + ']
t=t+blank+tb
t(na/2+1)=t(na/2+1)+'u '
end
end
n1=maxi(length(t))+1
//
n2=maxi(length(t))
if n2<ll then
write(out,t)
else
if n1<ll,
if n2-n1<ll then
write(out,part(t,1:n1)),
write(out,' ')
write(out,part(t,n1+1:n2),'(3x,a)')
else
error(mess)
end;
else
error(mess)
end;
end;
end
//
//y = cx + du
//-----------
if nc==0 then if fil then file('close',out);end;return,end
write(out,' ')
blank=[];for k=1:nc,blank=[blank;' '],end
if na==0 then
td=%cv(d)
if nc==1 then
t='y = '+td+'u'
else
blank(nc/2+1)='y = '
t=blank+td
t(nc/2+1)=t(nc/2+1)+'u '
end
n1=maxi(length(t))+1
else
tc=%cv(c);td=%cv(d)
blank=part(blank,1:4);
if nc==1 then
t='y = '+tc
else
blank(nc/2+1)='y = '
t=blank+tc;
end
withd=d<>[]
if withd then withd=norm(d,1)>0,end
if withd then
if nc==1 then
t=t+'x + '+td
else
blank(nc/2+1)='x + '
t=t+blank+td
t(nc/2+1)=t(nc/2+1)+'u '
end
n1=maxi(length(t))+1
else
if nc==1 then
t=t+'x '
else
t(nc/2+1)=t(nc/2+1)+'x '
end
end;
end
n2=maxi(length(t))
if n2<ll then
write(out,t)
else
if n1<ll,
if n2-n1<ll then
write(out,part(t,1:n1)),
write(out,' ')
write(out,part(t,n1+1:n2),'(3x,a)')
else
error(mess)
end
else
error(mess)
end
end
if fil then file('close',out),end
endfunction
|