3430
|
1 ## Copyright (C) 1996, 1999 Auburn University. All rights reserved. |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by the |
|
7 ## Free Software Foundation; either version 2, or (at your option) any |
|
8 ## later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 ## for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. |
|
18 |
|
19 ## -*- texinfo -*- |
3502
|
20 ## @deftypefn {Function File} {} sysmult (@var{asys}, @var{bsys}) |
3430
|
21 ## Compute @math{sys = Asys*Bsys} (series connection): |
|
22 ## @example |
|
23 ## @group |
|
24 ## u ---------- ---------- |
3502
|
25 ## --->| bsys |---->| asys |---> |
3430
|
26 ## ---------- ---------- |
|
27 ## @end group |
|
28 ## @end example |
|
29 ## A warning occurs if there is direct feed-through |
3502
|
30 ## from an input of Bsys or a continuous state of @var{bsys} through a |
|
31 ## discrete output of Bsys to a continuous state or output in @var{asys} |
|
32 ## (system data structure does not recognize discrete inputs). |
3430
|
33 ## @end deftypefn |
|
34 |
|
35 ## Author: John Ingram <ingraje@eng.auburn.edu> |
|
36 ## Created: July 1996 |
|
37 ## updated for variable number of arguments by A. S. Hodel July 1999 |
|
38 |
|
39 function sys = sysmult (...) |
|
40 |
|
41 if(nargin < 1) |
|
42 usage("sysmult: sys = sysmult(Asys{,Bsys,...})"); |
|
43 endif |
|
44 |
|
45 ## collect all arguments |
|
46 arglist = list(); |
|
47 va_start(); |
|
48 for kk=1:nargin |
|
49 arglist(kk) = va_arg(); |
|
50 if(!is_struct(nth(arglist,kk))) |
|
51 error("sysadd: argument %d is not a data structure",kk); |
|
52 endif |
|
53 endfor |
|
54 |
|
55 ## check system dimensions |
|
56 [n,nz,mg,pg,Gyd] = sysdimensions(nth(arglist,1)); |
|
57 for kk=2:nargin |
|
58 [n,nz,mh,ph,Hyd] = sysdimensions(nth(arglist,kk)); |
3664
|
59 if(ph != mg) |
|
60 error("arg %d has %d outputs; arg %d has %d inputs",kk,ph,kk-1,mg); |
3430
|
61 endif |
|
62 [n,nz,mg,pg,Gyd] = sysdimensions(nth(arglist,kk)); # for next iteration |
|
63 endfor |
|
64 |
|
65 ## perform the multiply |
|
66 if(nargin == 2) |
|
67 Asys = nth(arglist,1); Bsys = nth(arglist,2); |
|
68 |
|
69 [An,Anz,Am,Ap] = sysdimensions(Asys); |
|
70 [Bn,Bnz,Bm,Bp] = sysdimensions(Bsys); |
|
71 |
|
72 [Aa,Ab,Ac,Ad,Atsam,An,Anz,Astname,Ainname,Aoutname,Ayd] = sys2ss(Asys); |
|
73 [Ba,Bb,Bc,Bd,Btsam,Bn,Bnz,Bstname,Binname,Boutname,Byd] = sys2ss(Bsys); |
|
74 |
|
75 if(Byd) |
|
76 ## check direct feed-through of inputs through discrete outputs |
|
77 alist = find(Byd); |
|
78 if(An) |
|
79 bd = Ab(1:An)* Bd(alist,:); |
|
80 if(norm(bd,1)) |
|
81 warning("sysmult: inputs -> Bsys discrete outputs -> continous states of Asys"); |
|
82 endif |
|
83 endif |
|
84 ## check direct feed-through of continuous state through discrete outputs |
|
85 if(Bn) |
|
86 bc = Ab(1:An)* Bc(alist,1:(Bn)); |
|
87 if( norm(bc,1) ) |
|
88 warning("sysmult: Bsys states -> Bsys discrete outputs -> continuous states of Asys"); |
|
89 endif |
|
90 endif |
|
91 endif |
|
92 |
|
93 ## change signal names to avoid spurious warnings from sysgroup |
3438
|
94 Asys = syssetsignals(Asys,"in",__sysdefioname__(Am,"A_sysmult_tmp_name")); |
|
95 Bsys = syssetsignals(Bsys,"out",__sysdefioname__(Bp,"B_sysmult_tmp_name")); |
3430
|
96 |
|
97 sys = sysgroup(Asys,Bsys); |
|
98 |
|
99 ## connect outputs of B to inputs of A |
|
100 sys = sysconnect(sys,Ap+(1:Bp),1:Am); |
|
101 |
|
102 ## now keep only outputs of A and inputs of B |
|
103 sys = sysprune(sys,1:Ap,Am+(1:Bm)); |
|
104 |
|
105 else |
|
106 ## multiple systems (or a single system); combine together one by one |
|
107 sys = nth(arglist,1); |
|
108 for kk=2:length(arglist) |
|
109 sys = sysmult(sys,nth(arglist,kk)); |
|
110 endfor |
|
111 endif |
|
112 |
|
113 endfunction |
|
114 |