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
|
function tex = pol2root2tex(pol)
## pol2tex: converts polynomial into LaTeX form as (s-z_1)..(s-z_n)
## tex = pol2root2tex(pol)
###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.1 1999/05/24 22:05:53 peterg
## Initial revision
##
###############################################################
n = length(pol)-1;
if n>0
r = sort(roots(pol));
endif
gain = pol(1);
complex=0;
tex = sprintf("%g", gain);
for i=1:n
if complex
complex=0
else
if imag(r(i))<eps
tex = sprintf("%s (s + %g)", tex, -r(i));
else
tex = sprintf("%s (s + %g \\pm %g)", tex, -real(r(i)), imag(r(i)));
complex=1;
endif
endif
endfor
endfunction
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
|
>
|
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
|
function tex = pol2root2tex(pol,name,f)
## pol2tex: converts polynomial into LaTeX form as (s-z_1)..(s-z_n)
## tex = pol2root2tex(pol,[name,f])
###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.1 2001/05/10 11:44:40 gawthrop
## Useful conversion functions
##
## Revision 1.1 1999/05/24 22:05:53 peterg
## Initial revision
##
###############################################################
if nargin<2
name = "s"
endif
if nargin<3
f = "%2.2f";
endif
n = length(pol)-1;
if n>0
r = sort(roots(pol));
endif
gain = pol(1);
complex=0;
if ((gain==1)&&(n>0))
tex="";
else
tex = sprintf("%g", gain);
endif
for i=1:n
if real(r(i))<0
r_plusminus = '+';
else
r_plusminus = '-';
endif
if imag(r(i))<0
i_plusminus = '+';
else
i_plusminus = '-';
endif
if complex
complex=0
else
if abs(imag(r(i)))<1e-5
ff = sprintf("%%s (%s %%s %s)",name, f);
tex = sprintf(ff, tex, r_plusminus, abs(r(i)));
else
ff = sprintf("%%s (%s %%s %s \\pm j %s)", name, f, f)
tex = sprintf(ff, tex, r_plusminus, abs(real(r(i))), imag(r(i)));
complex=1;
endif
endif
endfor
endfunction
|