File: texprint.sci

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (108 lines) | stat: -rw-r--r-- 2,764 bytes parent folder | download | duplicates (2)
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
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
typ=type(a)

select typ
case 1 then  //scalars
  [m,n]=size(a)
  if norm(imag(a))<=%eps*norm(real(a)) then
    a=string(real(a))
  else
    a=string(a)
  end
  if m*n==0 then tt='{\pmatrix{}}',return,end
  if m*n<>1 then tt='{\pmatrix{',else tt='{{',end
  for l=1:m,tt=tt+strcat(a(l,:),'&')+'\cr '; end
  tt=part(tt,1:length(tt)-4)+'}}'
  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 4 then //booleans
  [m,n]=size(a)
  x='F'+emptystr(a);x(a)='T';a=x;
  if m*n<>1 then tt='{\pmatrix{',else tt='{{',end
  for l=1:m,tt=tt+strcat(a(l,:),'&')+'\cr '; end
  tt=part(tt,1:length(tt)-4)+'}}'
case 8 then //int
  [m,n]=size(a);a=string(a)
  if m*n<>1 then tt='{\pmatrix{',else tt='{{',end
  for l=1:m,tt=tt+strcat(a(l,:),'&')+'\cr '; end
  tt=part(tt,1:length(tt)-4)+'}}'

case 10 then //strings
  [m,n]=size(a)
  if m*n<>1 then tt='{\pmatrix{',else tt='{{',end
  for l=1:m,tt=tt+strcat(a(l,:),'&')+'\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)+'}}'
    tt=strsubst(tt,'%','')
  case 'lss' //linear state space
    if a(7)=='c' then der=' \dot{x}',else der=' \stackrel{+}{X}',end
    debut='\begin{eqnarray}';fin='\end{eqnarray}'
    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
  else
    execstr('tt=%'+a1(1)+'_texprint(a)','errcatch')
  end
case 17  then
  a1=getfield(1,a)
  execstr('tt=%'+a1(1)+'_texprint(a)','errcatch')
else
  execstr('tt=%'+typeof(a)+'_texprint(a)','errcatch')
end
endfunction