3213
|
1 # Copyright (C) 1996 A. Scottedward Hodel |
|
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, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
18 |
|
19 function [sys] = sysmult(Asys,Bsys) |
|
20 # |
|
21 # [sys] = sysmult(Asys,Bsys) |
|
22 # |
|
23 # returns sys = Asys*Bsys |
|
24 # |
|
25 # This function takes two systems, Asys and Bsys, and multiplies them together. |
|
26 # This has the effect of connecting the outputs of Bsys to the inputs of Asys. |
|
27 # |
|
28 # |
|
29 # u ---------- ---------- |
|
30 # --->| Bsys |---->| Asys |---> |
|
31 # ---------- ---------- |
|
32 # |
|
33 # A warning occurs if there is direct feed-through |
|
34 # from an input of Bsys or a continuous state of Bsys through a discrete |
|
35 # output of Bsys to a continuous state or output in Asys (system data structure form |
|
36 # does not recognize discrete inputs) |
|
37 |
|
38 # Written by John Ingram July 1996 |
|
39 |
|
40 save_val = implicit_str_to_num_ok; # save for later |
|
41 implicit_str_to_num_ok = 1; |
|
42 |
|
43 if(nargin != 2) |
|
44 usage("sysmult: [sys] = sysmult(Asys,Bsys)"); |
|
45 endif |
|
46 |
|
47 # check inputs |
|
48 if(!is_struct(Asys) | !is_struct(Bsys)) |
|
49 error("Both Asys and Bsys must be in system data structure form") |
|
50 endif |
|
51 |
|
52 # check for compatibility |
|
53 [An,Anz,Am,Ap] = sysdimensions(Asys); |
|
54 [Bn,Bnz,Bm,Bp] = sysdimensions(Bsys); |
|
55 if(Bp != Am) |
|
56 error(["Bsys has ",num2str(Bp)," outputs, Asys has ",num2str(Am), ... |
|
57 " inputs; mismatch."]); |
|
58 endif |
|
59 |
|
60 [Aa,Ab,Ac,Ad,Atsam,An,Anz,Astname,Ainname,Aoutname,Ayd] = sys2ss(Asys); |
|
61 [Ba,Bb,Bc,Bd,Btsam,Bn,Bnz,Bstname,Binname,Boutname,Byd] = sys2ss(Bsys); |
|
62 |
|
63 if(Byd) |
|
64 # check direct feed-through of inputs through discrete outputs |
|
65 alist = find(Byd); |
|
66 if(An) |
|
67 bd = Ab(1:An)* Bd(alist,:); |
|
68 if(norm(bd,1)) |
|
69 warning("sysmult: inputs -> Bsys discrete outputs -> continous states of Asys"); |
|
70 endif |
|
71 endif |
|
72 # check direct feed-through of continuous state through discrete outputs |
|
73 if(Bn) |
|
74 bc = Ab(1:An)* Bc(alist,1:(Bn)); |
|
75 if( norm(bc,1) ) |
|
76 warning("sysmult: Bsys states -> Bsys discrete outputs -> continuous states of Asys"); |
|
77 endif |
|
78 endif |
|
79 endif |
|
80 |
3236
|
81 # change signal names to avoid spurious warnings from sysgroup |
|
82 Asys = syssetsignals(Asys,"in",sysdefioname(Am,"A_sysmult_tmp_name")); |
|
83 Bsys = syssetsignals(Bsys,"out",sysdefioname(Bp,"B_sysmult_tmp_name")); |
|
84 |
3213
|
85 sys = sysgroup(Asys,Bsys); |
|
86 |
|
87 # connect outputs of B to inputs of A |
|
88 sys = sysconnect(sys,Ap+(1:Bp),1:Am); |
|
89 |
|
90 # now keep only outputs of A and inputs of B |
|
91 sys = sysprune(sys,1:Ap,Am+(1:Bm)); |
|
92 |
|
93 implicit_str_to_num_ok = save_val; # restore value |
|
94 endfunction |
|
95 |