9bbbc0d7f41bf897df08baff549cb4306155ce52
[scilab.git] / scilab / modules / cacsd / macros / plzr.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) INRIA
3 // This file must be used under the terms of the CeCILL.
4 // This source file is licensed as described in the file COPYING, which
5 // you should have received as part of this distribution.  The terms
6 // are also available at
7 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
8
9 function plzr(a,b,c,d)
10     //
11     // Copyright INRIA
12     [lhs,rhs]=argn(0)
13
14     if rhs == 0 then
15         s=poly(0,"s");
16         n=[1+s, 2+3*s+4*s^2, 5;0, 1-s, s];
17         d=[1+3*s, 5-s^3, s+1;1+s, 1+s+s^2, 3*s-1];
18         h=syslin("c",n./d);
19         plzr(h);
20         return;
21     end
22
23     select typeof(a)
24     case "rational" then
25         if rhs<>1 then
26             error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"),"plzr",1)),
27         end
28         a=tf2ss(a),
29         dt=a.dt;
30         [a,b,c,d]=a(2:5)
31         if type(d)<>1 then
32             error(msprintf(gettext("%s: Wrong value of input argument #%d: Proper system expected.\n"),"plzr",1));
33         end
34     case "state-space" then
35         if rhs<>1 then
36             error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"),"plzr",1)),
37         end
38         dt=a(7);
39         [a,b,c,d]=a(2:5)
40         if type(d)<>1 then
41             error(msprintf(gettext("%s: Wrong value of input argument #%d: Proper system expected.\n"),"plzr",1));
42         end
43     case "constant" then
44         if rhs<>4 then
45             error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"plzr",4)),
46         end
47         if type(d)<>1 then
48             error(msprintf(gettext("%s: Wrong type for input argument #%d: Array of floating point numbers expected.\n"),..
49             "plzr",4));
50         end
51         dt=[];
52     else
53         if rhs==1 then
54             error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear dynamical system expected.\n"),"plzr",1))
55         else
56             error(msprintf(gettext("%s: Wrong type of input argument #%d: Array of floating point numbers expected.\n"),"plzr",1))
57         end
58     end
59     if type(d)<>1 then
60         error(msprintf(gettext("%s: Wrong type for input argument #%d: Array of floating point numbers expected.\n"),..
61         "plzr",4));
62     end
63
64     dr=spec(a)
65     [al,be]=tr_zer(a,b,c,d)
66     nr=al./be
67     ni=imag(nr);nr=real(nr)
68     di=imag(dr);dr=real(dr)
69     //
70     mxx=max([nr;dr;1]*1.1)
71     mnx=min([nr;dr;-1]*1.1)
72     my=max(abs([ni;di;1])*1.1)
73
74     rect=[mnx, -my, mxx, my];
75
76     wdim=get(gcf(),"axes_size")
77     dx=(mxx-mnx)/wdim(1);dy=2*my/wdim(2)
78     if dy>dx then
79         ax=(dy*wdim(1)-mxx+mnx)/2
80         mxx=mxx+ax;mnx=mnx-ax
81     elseif dy<dx then
82         ay=(dx*wdim(2)-2*my)/2
83         my=my+ay
84     end
85     rect=[mnx, -my, mxx, my];
86
87     fig=gcf();
88     immediate_drawing=fig.immediate_drawing;
89     fig.immediate_drawing="off";
90
91     ax=gca();
92     ax.data_bounds=[mnx, -my; mxx, my];
93     ax.axes_visible="on";
94
95     legs=[],lhandle=[]
96     if size(nr,"*")<>0 then
97         xpoly(nr,ni)
98         e=gce();e.line_mode="off";e.mark_mode="on";
99         e.mark_size_unit="point";e.mark_size=7;e.mark_style=5;
100         legs=gettext("Zeros")
101         lhandle=[e;lhandle]
102     end;
103     if size(dr,"*")<>0 then
104         xpoly(dr,di)
105         e=gce();e.line_mode="off";e.mark_mode="on";
106         e.mark_size_unit="point";e.mark_size=7;e.mark_style=2;
107         legs=[gettext("Poles");legs]
108         lhandle=[e;lhandle]
109     end
110     if dt == "d" then
111         ax.grid=ones(1,3)*color("gray")
112         ax.box = "on";
113         xarc(-1,1,2,2,0,360*64)
114         xtitle(gettext("Transmission zeros and poles"),gettext("Real axis"), ...
115         gettext("Imaginary axis"));
116     else
117         ax.grid=ones(1,3)*color("gray")
118         ax.box = "on";
119         ymin=ax.data_bounds(1,2);
120         ymax=ax.data_bounds(2,2);
121         xsegs([0,0],[ymin,ymax])
122         xtitle(gettext("Transmission zeros and poles"),gettext("Real axis"), ...
123         gettext("Imaginary axis"));
124     end
125
126     if legs<>[] then legend(lhandle,legs,1),end
127     fig.immediate_drawing=immediate_drawing;
128     show_window();
129 endfunction