7017
|
1 ## Copyright (C) 1996, 1999, 2000, 2002, 2004, 2005, 2006, 2007 |
|
2 ## Auburn University. All rights reserved. |
3430
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
7016
|
7 ## under the terms of the GNU General Public License as published by |
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
3430
|
10 ## |
7016
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
3430
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
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 |
7136
|
42 if (nargin < 1) |
6046
|
43 print_usage (); |
3430
|
44 endif |
|
45 |
|
46 ## collect all arguments |
4771
|
47 arglist = {}; |
7136
|
48 for kk = 1:nargin |
4771
|
49 arglist{kk} = varargin{kk}; |
7136
|
50 if (! isstruct (arglist{kk})) |
|
51 error ("sysadd: argument %d is not a data structure", kk); |
3430
|
52 endif |
|
53 endfor |
|
54 |
|
55 ## check system dimensions |
7136
|
56 [n, nz, mg, pg, Gyd] = sysdimensions (arglist{1}); |
|
57 for kk = 2:nargin |
|
58 [n, nz, mh, ph, Hyd] = sysdimensions (arglist{kk}); |
3664
|
59 if(ph != mg) |
7136
|
60 error ("arg %d has %d outputs; arg %d has %d inputs", kk, ph, kk-1, mg); |
3430
|
61 endif |
7136
|
62 [n, nz, mg, pg, Gyd] = sysdimensions (arglist{kk}); # for next iteration |
3430
|
63 endfor |
|
64 |
|
65 ## perform the multiply |
7136
|
66 if (nargin == 2) |
4771
|
67 Asys = arglist{1}; |
|
68 Bsys = arglist{2}; |
3430
|
69 |
7136
|
70 [An, Anz, Am, Ap] = sysdimensions (Asys); |
|
71 [Bn, Bnz, Bm, Bp] = sysdimensions (Bsys); |
3430
|
72 |
7136
|
73 [Aa, Ab, Ac, Ad, Atsam, An, Anz, ... |
|
74 Astname, Ainname, Aoutname, Ayd] = sys2ss(Asys); |
3430
|
75 |
7136
|
76 [Ba, Bb, Bc, Bd, Btsam, Bn, Bnz, ... |
|
77 Bstname, Binname, Boutname, Byd] = sys2ss(Bsys); |
|
78 |
|
79 if (Byd) |
3430
|
80 ## check direct feed-through of inputs through discrete outputs |
7136
|
81 alist = find (Byd); |
|
82 if (An) |
|
83 bd = Ab(1:An) * Bd(alist,:); |
|
84 if (norm (bd, 1)) |
|
85 warning ("sysmult: inputs -> Bsys discrete outputs -> continuous states of Asys"); |
3430
|
86 endif |
|
87 endif |
|
88 ## check direct feed-through of continuous state through discrete outputs |
7136
|
89 if (Bn) |
|
90 bc = Ab(1:An) * Bc(alist,1:(Bn)); |
|
91 if (norm (bc, 1)) |
|
92 warning ("sysmult: Bsys states -> Bsys discrete outputs -> continuous states of Asys"); |
3430
|
93 endif |
|
94 endif |
|
95 endif |
|
96 |
|
97 ## change signal names to avoid spurious warnings from sysgroup |
7136
|
98 Asys = syssetsignals (Asys, "in", |
|
99 __sysdefioname__ (Am, "A_sysmult_tmp_name")); |
3430
|
100 |
7136
|
101 Bsys = syssetsignals (Bsys, "out", |
|
102 __sysdefioname__ (Bp, "B_sysmult_tmp_name")); |
|
103 |
|
104 sys = sysgroup (Asys, Bsys); |
3430
|
105 |
|
106 ## connect outputs of B to inputs of A |
7136
|
107 sys = sysconnect (sys, Ap+(1:Bp), 1:Am); |
3430
|
108 |
|
109 ## now keep only outputs of A and inputs of B |
7136
|
110 sys = sysprune (sys, 1:Ap, Am+(1:Bm)); |
3430
|
111 |
|
112 else |
|
113 ## multiple systems (or a single system); combine together one by one |
4771
|
114 sys = arglist{1}; |
7136
|
115 for kk = 2:length(arglist) |
|
116 sys = sysmult (sys, arglist{kk}); |
3430
|
117 endfor |
|
118 endif |
|
119 |
|
120 endfunction |
|
121 |