File: texprint.sci

package info (click to toggle)
scilab 2.6-4
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 54,632 kB
  • ctags: 40,267
  • sloc: ansic: 267,851; fortran: 166,549; sh: 10,005; makefile: 4,119; tcl: 1,070; cpp: 233; csh: 143; asm: 135; perl: 130; java: 39
file content (100 lines) | stat: -rw-r--r-- 2,522 bytes parent folder | download
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
function [tt]=texprint(a)
// text = texprint(a) returns the Tex source code of the scilab variable a.
// a is a matrix (scalar, polynomial, rational) or a linear system
// (syslin list).
//!
//
// Copyright INRIA
debut='\begin{array}{l}';fin='\end{array}'
typ=type(a)

select typ
case 1 then  //scalars
  [m,n]=size(a)
  if m*n<>1 then tt='{\pmatrix{',else tt='{{',end
  if norm(imag(a))<=%eps*norm(real(a)) then
// matrice reelle
     a=string(real(a))
     for l=1:m,
       tt=tt+a(l,1)
       for k=2:n,tt=tt+'&'+a(l,k),end
       tt=tt+'\cr '
     end
     tt=part(tt,1:length(tt)-4)+'}}'
   else
       for l=1:m,
       tt=tt+string(a(l,1))
       for k=2:n,tt=tt+'&'+string(a(l,k)),end
       tt=tt+'\cr '
     end
     tt=part(tt,1:length(tt)-4)+'}}'
   end
   tt=strsubst(tt,'%','')
case 2 then //polynomials
   [m,n]=size(a)
   if m*n<>1 then tt='{\pmatrix{',else tt='{{',end
   z=varn(a)
   nz=1;while part(z,nz)<>' ' then nz=nz+1,end
   z=part(z,1:nz-1)
//
   for l=1:m
     for k=1:n,tt=tt+pol2tex(a(l,k))+'&',end
     tt=part(tt,1:length(tt)-1)+'\cr '
   end
   tt=part(tt,1:length(tt)-4)+'}}'
   tt=strsubst(tt,'%','')
case 10 then //strings
  [m,n]=size(a)
  if m*n<>1 then tt='{\pmatrix{',else tt='{{',end
     for l=1:m,
       tt=tt+a(l,1)
       for k=2:n,tt=tt+'&'+a(l,k),end
       tt=tt+'\cr '
     end
     tt=part(tt,1:length(tt)-4)+'}}'
 
case 16 then 
     a1=a(1)//transfer and linear systems
  select a1(1)
    case 'r' then //rationals
     num=a('num');a=a('den')
     [m,n]=size(a)
     if m*n<>1 then tt='{\pmatrix{',else tt='{{',end
     z=varn(a)
     nz=1;while part(z,nz)<>' ' then nz=nz+1,end
     z=part(z,1:nz-1)
//
     for l=1:m
       for k=1:n,
         if degree(a(l,k))==0 then
            num(l,k)=num(l,k)/coeff(a(l,k)),pol=1
         else
            pol=0
         end
         nlk=pol2tex(num(l,k));
         if nlk=='0' then
            tt=tt+'0&'
         else
           if pol==1 then
             tt=tt+nlk+'&'
           else
             dlk=pol2tex(a(l,k))
             tt=tt+'{'+nlk+'}\over{'+dlk+'}&',
           end
         end
       end
       tt=part(tt,1:length(tt)-1)+'\cr '
     end
     tt=part(tt,1:length(tt)-4)+'}}'
    case 'lss' //linear state space
     if a(7)=='c' then der=' \dot{x}',else der=' \stackrel{+}{X}',end
     tt=debut+der+' = '+texprint(a(2))+' X + '+...
         texprint(a(3))+'U \\ \\ Y = '+texprint(a(4))+' X '
     if norm(a(5),1)==0 then
       tt=tt+fin
     else
       tt=tt+' + '+texprint(a(5))+fin
     end
  end
 
end