fdd1459dc4439efe8934adfe4f91309e595cb506
[scilab.git] / scilab / modules / cacsd / macros / augment.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) INRIA -
3 //
4 // Copyright (C) 2012 - 2016 - Scilab Enterprises
5 //
6 // This file is hereby licensed under the terms of the GNU GPL v2.0,
7 // pursuant to article 5.3.4 of the CeCILL v.2.1.
8 // This file was originally licensed under the terms of the CeCILL v2.1,
9 // and continues to be available under such terms.
10 // For more information, see the COPYING file which you should have received
11 // along with this program.
12
13
14 function [P,r]=augment(G,SRT,flag)
15     // Augmented plants P
16     // flag='output' (default) :
17     //
18     //       [ I | -G]   -->'S'
19     //       [ 0 |  I]   -->'R'
20     //   P = [ 0 |  G]   -->'T'
21     //       [-------]
22     //       [ I | -G]
23     //
24     //
25     // flag='input' :
26     //
27     //       [ I | -I]   -->'S'
28     //       [ G | -G]   -->'R'
29     //   P = [ 0 |  I]   -->'T'
30     //       [-------]
31     //       [ G | -G]
32     //!
33
34     [LHS,RHS]=argn(0);
35     if RHS <= 2 then flag="output";end
36     select part(flag,1)
37     case "o"
38         G1=G(1);
39         if RHS==1 then SRT="SRT";end
40         r=size(G);
41         [ny,nu]=size(G);Iu=eye(nu,nu);Iy=eye(ny,ny);
42         Ouy=zeros(nu,ny);Oyu=zeros(ny,nu);Ouu=zeros(nu,nu);
43         Oyy=zeros(ny,ny);
44         ssSRT=0;
45         if G1(1)=="r" then ssSRT=1;end
46         long=length(SRT);
47         select long
48         case 3 then
49             // 'SRT'
50             if SRT<>"SRT" then
51                 error(msprintf(gettext("%s: Wrong value for input argument #%d: ''%s'' expected.\n"), "augment",2,"SRT"),9999);
52             end
53             if ssSRT==0 then
54                 W1=[Iy,Oyu,Oyy;
55                 Ouy,Iu,Ouy;
56                 -Iy,Oyu,Iy;
57                 Iy,Oyu,Oyy];
58                 W2=[Iy,-G;
59                 Ouy,Iu;
60                 Iy,Oyu];
61                 P=W1*W2;
62             end
63             if ssSRT ==1 then
64                 P=[Iy,-G;
65                 Ouy,Iu;
66                 Oyy,G;
67                 Iy,-G]
68             end
69             return
70         case 2 then
71             if SRT=="SR" then
72                 if ssSRT==0 then
73                     W1=[Iy,Oyu,Oyy;
74                     Ouy,Iu,Ouy;
75                     Iy,Oyu,Oyy];
76                     W2=[Iy,-G;
77                     Ouy,Iu;
78                     Iy,Oyu];
79                     P=W1*W2;
80                 end
81                 if ssSRT==1 then
82                     P=[Iy,-G;
83                     Ouy,Iu;
84                     Iy,-G];
85                 end
86                 return
87             end
88             if SRT=="ST" then
89                 if ssSRT==0 then
90                     W1=[Iy,Oyu,Oyy;
91                     -Iy,Oyu,Iy;
92                     Iy,Oyu,Oyy];
93                     W2=[Iy,-G;
94                     Ouy,Iu;
95                     Iy,Oyu];
96                     P=W1*W2;
97                 end
98                 if ssSRT ==1 then
99                     P=[Iy, -G;
100                     Oyy, G;
101                     Iy, -G];
102                 end
103                 return
104             end
105             if SRT=="RT" then
106                 if ssSRT==0 then
107                     W1=[Ouy,Iu,Ouy;
108                     -Iy,Oyu,Iy;
109                     Iy,Oyu,Oyy];
110                     W2=[Iy,-G;
111                     Ouy,Iu;
112                     Iy,Oyu];
113                     P=W1*W2;
114                 end;
115                 if ssSRT ==1 then
116                     P=[Ouy,Iu;
117                     Oyy,G;
118                     Iy,-G];
119                 end
120                 return
121             end
122             error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
123             "augment",2, "''SR'',''ST'',''RT''"),9999);
124         case 1 then
125             if SRT=="S" then
126                 if ssSRT==0 then
127                     W1=[Iy,Oyu,Oyy;
128                     Iy,Oyu,Oyy];
129                     W2=[Iy,-G;
130                     Ouy,Iu;
131                     Iy,Oyu];
132                     P=W1*W2;
133                 end;
134                 if ssSRT ==1 then
135                     P=[Iy,-G;
136                     Iy,-G];
137                 end
138                 return
139             end
140             if SRT=="R" then
141                 if ssSRT==0 then
142                     W1=[Ouy,Iu,Ouy;
143                     Iy,Oyu,Oyy];
144                     W2=[Iy,-G;
145                     Ouy,Iu;
146                     Iy,Oyu];
147                     P=W1*W2;
148                 end
149                 if ssSRT ==1 then
150                     P=[Ouy,Iu;
151                     Iy,-G];
152                 end
153                 return
154             end
155             if SRT=="T" then
156                 if ssSRT==0 then
157                     W1=[-Iy,Oyu,Iy;
158                     Iy,Oyu,Oyy];
159                     W2=[Iy,-G;
160                     Ouy,Iu;
161                     Iy,Oyu];
162                     P=W1*W2;
163                 end
164                 if ssSRT ==1 then
165                     P=[Oyy,G;
166                     Iy,-G];
167                 end
168                 return
169             end
170         end
171     case "i"
172         G1=G(1);
173         if RHS==1 then SRT="SRT";end
174         r=size(G);
175         [ny,nu]=size(G);Iu=eye(nu,nu);Iy=eye(ny,ny);
176         Ouy=zeros(nu,ny);Oyu=zeros(ny,nu);Ouu=zeros(nu,nu);
177         Oyy=zeros(ny,ny);
178         ssSRT=0;
179         if G1(1)=="r" then ssSRT=1;end
180         long=length(SRT);
181         select long
182         case 3 then
183             // 'SRT'
184             if SRT<>"SRT" then
185                 error(msprintf(gettext("%s: Wrong value for input argument #%d: ''%s'' expected.\n"), "augment",2,"SRT"),9999);
186             end;
187             if ssSRT==0 then
188                 W1=[Iu,-Iu;
189                 Oyu,Oyu;
190                 Ouu,Iu;
191                 Oyu,Oyu];
192                 W2=[Ouy;Iy;Ouy;Iy];
193                 W3=[Iu,-Iu];
194                 P=W1+W2*G*W3;
195             end
196             if ssSRT ==1 then
197                 P=[Iu,-Iu;
198                 G,-G;
199                 Ouu,Iu;
200                 -G,G]
201             end
202             return
203         case 2 then
204             if SRT=="SR" then
205                 if ssSRT==0 then
206                     W1=[Iu,-Iu;
207                     Oyu,Oyu;
208                     Oyu,Oyu];
209                     W2=[Ouy;Iy;Iy];
210                     W3=[Iu,-Iu];
211                     P=W1+W2*G*W3;
212                 end
213                 if ssSRT==1 then
214                     P=[Iu,-Iu;
215                     G,-G;
216                     -G,G]
217                 end
218                 return
219             end
220             if SRT=="ST" then
221                 if ssSRT==0 then
222                     W1=[Iu,-Iu;
223                     Ouu,Iu;
224                     Oyu,Oyu];
225                     W2=[Ouy;Ouy;Iy];
226                     W3=[Iu,-Iu];
227                     P=W1+W2*G*W3;
228                 end
229                 if ssSRT ==1 then
230                     P=[Iu,-Iu;
231                     Ouu,Iu;
232                     -G,G]
233                 end
234                 return
235             end
236             if SRT=="RT" then
237                 if ssSRT==0 then
238                     W1=[Oyu,Oyu;
239                     Ouu,Iu;
240                     Oyu,Oyu];
241                     W2=[Iy;Ouy;Iy];
242                     W3=[Iu,-Iu];
243                     P=W1+W2*G*W3;
244                 end;
245                 if ssSRT ==1 then
246                     P=[G,-G;
247                     Ouu,Iu;
248                     -G,G]
249                 end
250                 return
251             end
252
253             error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
254             "augment",2, "''SR'',''ST'',''RT''"),9999);
255
256         case 1 then
257             if SRT=="S" then
258                 if ssSRT==0 then
259                     W1=[Iu,-Iu;
260                     Oyu,Oyu];
261                     W2=[Ouy;Iy];
262                     W3=[Iu,-Iu];
263                     P=W1+W2*G*W3;
264
265                 end;
266                 if ssSRT ==1 then
267                     P=[Iu,-Iu;
268                     -G,G]
269                 end
270                 return
271             end
272             if SRT=="R" then
273                 if ssSRT==0 then
274                     W1=[Oyu,Oyu;
275                     Oyu,Oyu];
276                     W2=[Iy;Iy];
277                     W3=[Iu,-Iu];
278                     P=W1+W2*G*W3;
279                 end
280                 if ssSRT ==1 then
281                     P=[G,-G;
282                     -G,G]
283                 end
284                 return
285             end
286             if SRT=="T" then
287                 if ssSRT==0 then
288                     W1=[Ouu,Iu;
289                     Oyu,Oyu];
290                     W2=[Ouy;Iy];
291                     W3=[Iu,-Iu];
292                     P=W1+W2*G*W3;
293                 end
294                 if ssSRT ==1 then
295                     P=[Ouu,Iu;
296                     -G,G]
297                 end
298                 return
299             end
300         end
301     end
302 endfunction