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
|
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution. The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
function txt=%p_string(p)
[m,n]=size(p)
s=stripblanks(varn(p))
txt=emptystr(2*m,n)
for l=1:m
for k=1:n
c=coeff(p(l,k))
knz=find(c<>0)
if knz==[] then
txt(2*l-1:2*l,k)=[" ";"0"];
else
c=c(knz)
//special case for i=1
if isreal(c(1),0) then
w=real(c(1))
if w<0 then
C(1)=" - "+string(abs(c(1))),
else
C(1)=string(c(1)),
end
else
w=string(c(1));
if knz(1)<> 1 then w="("+w+")",end
C(1)=w;
end
for i=2:size(c,"*"),
if isreal(c(i),0) then
w=real(c(i))
if w<0 then
C(i)=" - "+string(abs(c(i))),
else
C(i)=" + "+string(c(i)),
end
else
C(i)=" + ("+string(c(i))+")";
end
end
if knz(1)>1 then
C=C+s
else
C(2:$)=C(2:$)+s
end
i=min(find(knz>2))
blank=" "
e=blank(ones(1,i-1))
if size(knz,"*")>=i then e=[e string(knz(i:$)-1)],end
lc=cumsum(length(C))
C=strcat(C)
E="";
for i=1:size(c,"*"),E=E+part(" ",1:(lc(i)-length(E)))+e(i);end
txt(2*l-1:2*l,k)=[E;C];
end
end
end
endfunction
|