3381
|
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. |
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(...) |
3381
|
36 |
|
37 ## Written by John Ingram July 1996 |
|
38 ## updated for variable number of arguments by A. S. Hodel July 1999 |
3213
|
39 |
|
40 save_val = implicit_str_to_num_ok; # save for later |
|
41 implicit_str_to_num_ok = 1; |
|
42 |
3279
|
43 if(nargin < 1) |
|
44 usage("sysmult: sys = sysmult(Asys{,Bsys,...})"); |
3213
|
45 endif |
|
46 |
3381
|
47 ## collect all arguments |
3279
|
48 arglist = list(); |
|
49 va_start(); |
|
50 for kk=1:nargin |
|
51 arglist(kk) = va_arg(); |
|
52 if(!is_struct(nth(arglist,kk))) |
|
53 error("sysadd: argument %d is not a data structure",kk); |
|
54 endif |
|
55 endfor |
|
56 |
3381
|
57 ## check system dimensions |
3279
|
58 [n,nz,mg,pg,Gyd] = sysdimensions(nth(arglist,1)); |
|
59 for kk=2:nargin |
|
60 [n,nz,mh,ph,Hyd] = sysdimensions(nth(arglist,kk)); |
|
61 if(mh != pg) |
|
62 error("arg %d has %d outputs; arg %d has vs %d inputs",kk,ph,kk-1,mg); |
|
63 endif |
|
64 [n,nz,mg,pg,Gyd] = sysdimensions(nth(arglist,kk)); # for next iteration |
|
65 endfor |
3213
|
66 |
3381
|
67 ## perform the multiply |
3279
|
68 if(nargin == 2) |
|
69 Asys = nth(arglist,1); Bsys = nth(arglist,2); |
|
70 |
|
71 [An,Anz,Am,Ap] = sysdimensions(Asys); |
|
72 [Bn,Bnz,Bm,Bp] = sysdimensions(Bsys); |
|
73 |
|
74 [Aa,Ab,Ac,Ad,Atsam,An,Anz,Astname,Ainname,Aoutname,Ayd] = sys2ss(Asys); |
|
75 [Ba,Bb,Bc,Bd,Btsam,Bn,Bnz,Bstname,Binname,Boutname,Byd] = sys2ss(Bsys); |
|
76 |
|
77 if(Byd) |
3381
|
78 ## check direct feed-through of inputs through discrete outputs |
3279
|
79 alist = find(Byd); |
|
80 if(An) |
|
81 bd = Ab(1:An)* Bd(alist,:); |
|
82 if(norm(bd,1)) |
|
83 warning("sysmult: inputs -> Bsys discrete outputs -> continous states of Asys"); |
|
84 endif |
|
85 endif |
3381
|
86 ## check direct feed-through of continuous state through discrete outputs |
3279
|
87 if(Bn) |
|
88 bc = Ab(1:An)* Bc(alist,1:(Bn)); |
|
89 if( norm(bc,1) ) |
|
90 warning("sysmult: Bsys states -> Bsys discrete outputs -> continuous states of Asys"); |
|
91 endif |
3213
|
92 endif |
|
93 endif |
3279
|
94 |
3381
|
95 ## change signal names to avoid spurious warnings from sysgroup |
3279
|
96 Asys = syssetsignals(Asys,"in",sysdefioname(Am,"A_sysmult_tmp_name")); |
|
97 Bsys = syssetsignals(Bsys,"out",sysdefioname(Bp,"B_sysmult_tmp_name")); |
|
98 |
|
99 sys = sysgroup(Asys,Bsys); |
|
100 |
3381
|
101 ## connect outputs of B to inputs of A |
3279
|
102 sys = sysconnect(sys,Ap+(1:Bp),1:Am); |
|
103 |
3381
|
104 ## now keep only outputs of A and inputs of B |
3279
|
105 sys = sysprune(sys,1:Ap,Am+(1:Bm)); |
3213
|
106 |
3279
|
107 else |
3381
|
108 ## multiple systems (or a single system); combine together one by one |
3279
|
109 sys = nth(arglist,1); |
|
110 for kk=2:length(arglist) |
|
111 sys = sysmult(sys,nth(arglist,kk)); |
|
112 endfor |
|
113 endif |
3213
|
114 implicit_str_to_num_ok = save_val; # restore value |
|
115 endfunction |
|
116 |