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 |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301 USA. |
3430
|
19 |
|
20 ## -*- texinfo -*- |
5016
|
21 ## @deftypefn {Function File} {@var{sys} =} sysmult (@var{Asys}, @var{Bsys}) |
3430
|
22 ## Compute @math{sys = Asys*Bsys} (series connection): |
|
23 ## @example |
|
24 ## @group |
|
25 ## u ---------- ---------- |
5016
|
26 ## --->| Bsys |---->| Asys |---> |
3430
|
27 ## ---------- ---------- |
|
28 ## @end group |
|
29 ## @end example |
5016
|
30 ## A warning occurs if there is direct feed-through from an input |
|
31 ## or a continuous state of @var{Bsys}, through a discrete output |
|
32 ## of @var{Bsys}, to a continuous state or output in @var{Asys} |
3502
|
33 ## (system data structure does not recognize discrete inputs). |
3430
|
34 ## @end deftypefn |
|
35 |
|
36 ## Author: John Ingram <ingraje@eng.auburn.edu> |
|
37 ## Created: July 1996 |
|
38 ## updated for variable number of arguments by A. S. Hodel July 1999 |
|
39 |
3979
|
40 function sys = sysmult (varargin) |
3430
|
41 |
|
42 if(nargin < 1) |
|
43 usage("sysmult: sys = sysmult(Asys{,Bsys,...})"); |
|
44 endif |
|
45 |
|
46 ## collect all arguments |
4771
|
47 arglist = {}; |
3430
|
48 for kk=1:nargin |
4771
|
49 arglist{kk} = varargin{kk}; |
|
50 if(!isstruct(arglist{kk})) |
3430
|
51 error("sysadd: argument %d is not a data structure",kk); |
|
52 endif |
|
53 endfor |
|
54 |
|
55 ## check system dimensions |
4771
|
56 [n,nz,mg,pg,Gyd] = sysdimensions(arglist{1}); |
3430
|
57 for kk=2:nargin |
4771
|
58 [n,nz,mh,ph,Hyd] = sysdimensions(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 |
4771
|
62 [n,nz,mg,pg,Gyd] = sysdimensions(arglist{kk}); # for next iteration |
3430
|
63 endfor |
|
64 |
|
65 ## perform the multiply |
|
66 if(nargin == 2) |
4771
|
67 Asys = arglist{1}; |
|
68 Bsys = arglist{2}; |
3430
|
69 |
|
70 [An,Anz,Am,Ap] = sysdimensions(Asys); |
|
71 [Bn,Bnz,Bm,Bp] = sysdimensions(Bsys); |
|
72 |
|
73 [Aa,Ab,Ac,Ad,Atsam,An,Anz,Astname,Ainname,Aoutname,Ayd] = sys2ss(Asys); |
|
74 [Ba,Bb,Bc,Bd,Btsam,Bn,Bnz,Bstname,Binname,Boutname,Byd] = sys2ss(Bsys); |
|
75 |
|
76 if(Byd) |
|
77 ## check direct feed-through of inputs through discrete outputs |
|
78 alist = find(Byd); |
|
79 if(An) |
|
80 bd = Ab(1:An)* Bd(alist,:); |
|
81 if(norm(bd,1)) |
|
82 warning("sysmult: inputs -> Bsys discrete outputs -> continous states of Asys"); |
|
83 endif |
|
84 endif |
|
85 ## check direct feed-through of continuous state through discrete outputs |
|
86 if(Bn) |
|
87 bc = Ab(1:An)* Bc(alist,1:(Bn)); |
|
88 if( norm(bc,1) ) |
|
89 warning("sysmult: Bsys states -> Bsys discrete outputs -> continuous states of Asys"); |
|
90 endif |
|
91 endif |
|
92 endif |
|
93 |
|
94 ## change signal names to avoid spurious warnings from sysgroup |
3438
|
95 Asys = syssetsignals(Asys,"in",__sysdefioname__(Am,"A_sysmult_tmp_name")); |
|
96 Bsys = syssetsignals(Bsys,"out",__sysdefioname__(Bp,"B_sysmult_tmp_name")); |
3430
|
97 |
|
98 sys = sysgroup(Asys,Bsys); |
|
99 |
|
100 ## connect outputs of B to inputs of A |
|
101 sys = sysconnect(sys,Ap+(1:Bp),1:Am); |
|
102 |
|
103 ## now keep only outputs of A and inputs of B |
|
104 sys = sysprune(sys,1:Ap,Am+(1:Bm)); |
|
105 |
|
106 else |
|
107 ## multiple systems (or a single system); combine together one by one |
4771
|
108 sys = arglist{1}; |
3430
|
109 for kk=2:length(arglist) |
4771
|
110 sys = sysmult(sys,arglist{kk}); |
3430
|
111 endfor |
|
112 endif |
|
113 |
|
114 endfunction |
|
115 |