3279
|
1 # Copyright (C) 1996,1999 Auburn University. All Rights Reserved |
3213
|
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 |
3284
|
17 # Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. |
3346
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File } { @var{sys} =} sysmult( @var{Asys}, @var{Bsys}) |
|
21 ## Compute @math{sys = Asys*Bsys} (series connection): |
|
22 ## @example |
|
23 ## @group |
|
24 ## u ---------- ---------- |
|
25 ## --->| Bsys |---->| Asys |---> |
|
26 ## ---------- ---------- |
|
27 ## @end group |
|
28 ## @end example |
|
29 ## A warning occurs if there is direct feed-through |
|
30 ## from an input of Bsys or a continuous state of Bsys through a discrete |
|
31 ## output of Bsys to a continuous state or output in Asys (system data structure |
|
32 ## does not recognize discrete inputs). |
|
33 ## @end deftypefn |
|
34 |
3279
|
35 function sys = sysmult(...) |
3213
|
36 # Written by John Ingram July 1996 |
3279
|
37 # updated for variable number of arguments by A. S. Hodel July 1999 |
3213
|
38 |
|
39 save_val = implicit_str_to_num_ok; # save for later |
|
40 implicit_str_to_num_ok = 1; |
|
41 |
3279
|
42 if(nargin < 1) |
|
43 usage("sysmult: sys = sysmult(Asys{,Bsys,...})"); |
3213
|
44 endif |
|
45 |
3279
|
46 # collect all arguments |
|
47 arglist = list(); |
|
48 va_start(); |
|
49 for kk=1:nargin |
|
50 arglist(kk) = va_arg(); |
|
51 if(!is_struct(nth(arglist,kk))) |
|
52 error("sysadd: argument %d is not a data structure",kk); |
|
53 endif |
|
54 endfor |
|
55 |
|
56 # check system dimensions |
|
57 [n,nz,mg,pg,Gyd] = sysdimensions(nth(arglist,1)); |
|
58 for kk=2:nargin |
|
59 [n,nz,mh,ph,Hyd] = sysdimensions(nth(arglist,kk)); |
|
60 if(mh != pg) |
|
61 error("arg %d has %d outputs; arg %d has vs %d inputs",kk,ph,kk-1,mg); |
|
62 endif |
|
63 [n,nz,mg,pg,Gyd] = sysdimensions(nth(arglist,kk)); # for next iteration |
|
64 endfor |
3213
|
65 |
3279
|
66 # perform the multiply |
|
67 if(nargin == 2) |
|
68 Asys = nth(arglist,1); Bsys = nth(arglist,2); |
|
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 |
3213
|
91 endif |
|
92 endif |
3279
|
93 |
|
94 # change signal names to avoid spurious warnings from sysgroup |
|
95 Asys = syssetsignals(Asys,"in",sysdefioname(Am,"A_sysmult_tmp_name")); |
|
96 Bsys = syssetsignals(Bsys,"out",sysdefioname(Bp,"B_sysmult_tmp_name")); |
|
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)); |
3213
|
105 |
3279
|
106 else |
|
107 # multiple systems (or a single system); combine together one by one |
|
108 sys = nth(arglist,1); |
|
109 for kk=2:length(arglist) |
|
110 sys = sysmult(sys,nth(arglist,kk)); |
|
111 endfor |
|
112 endif |
3213
|
113 implicit_str_to_num_ok = save_val; # restore value |
|
114 endfunction |
|
115 |