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 |
7016
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
3430
|
9 ## |
7016
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
3430
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
3430
|
18 |
|
19 ## -*- texinfo -*- |
5016
|
20 ## @deftypefn {Function File} {@var{sys} =} sysmult (@var{Asys}, @var{Bsys}) |
3430
|
21 ## Compute @math{sys = Asys*Bsys} (series connection): |
|
22 ## @example |
|
23 ## @group |
|
24 ## u ---------- ---------- |
5016
|
25 ## --->| Bsys |---->| Asys |---> |
3430
|
26 ## ---------- ---------- |
|
27 ## @end group |
|
28 ## @end example |
5016
|
29 ## A warning occurs if there is direct feed-through from an input |
|
30 ## or a continuous state of @var{Bsys}, through a discrete output |
|
31 ## of @var{Bsys}, to a continuous state or output in @var{Asys} |
3502
|
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 |
3979
|
39 function sys = sysmult (varargin) |
3430
|
40 |
|
41 if(nargin < 1) |
6046
|
42 print_usage (); |
3430
|
43 endif |
|
44 |
|
45 ## collect all arguments |
4771
|
46 arglist = {}; |
3430
|
47 for kk=1:nargin |
4771
|
48 arglist{kk} = varargin{kk}; |
|
49 if(!isstruct(arglist{kk})) |
3430
|
50 error("sysadd: argument %d is not a data structure",kk); |
|
51 endif |
|
52 endfor |
|
53 |
|
54 ## check system dimensions |
4771
|
55 [n,nz,mg,pg,Gyd] = sysdimensions(arglist{1}); |
3430
|
56 for kk=2:nargin |
4771
|
57 [n,nz,mh,ph,Hyd] = sysdimensions(arglist{kk}); |
3664
|
58 if(ph != mg) |
|
59 error("arg %d has %d outputs; arg %d has %d inputs",kk,ph,kk-1,mg); |
3430
|
60 endif |
4771
|
61 [n,nz,mg,pg,Gyd] = sysdimensions(arglist{kk}); # for next iteration |
3430
|
62 endfor |
|
63 |
|
64 ## perform the multiply |
|
65 if(nargin == 2) |
4771
|
66 Asys = arglist{1}; |
|
67 Bsys = arglist{2}; |
3430
|
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)) |
7001
|
81 warning("sysmult: inputs -> Bsys discrete outputs -> continuous states of Asys"); |
3430
|
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 |
4771
|
107 sys = arglist{1}; |
3430
|
108 for kk=2:length(arglist) |
4771
|
109 sys = sysmult(sys,arglist{kk}); |
3430
|
110 endfor |
|
111 endif |
|
112 |
|
113 endfunction |
|
114 |