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 = sysadd(Gsys,Hsys) |
|
20 # |
|
21 # [sys] = sysadd(Gsys,Hsys) |
|
22 # |
|
23 # |
|
24 # returns transfer function sys = Gsys + Hsys |
|
25 # |
|
26 # Method: Gsys and Hsys are connected in parallel |
|
27 # The vector are connected to both systems; the outputs will be |
|
28 # added. The names given to the system will be the G systems names. |
|
29 # |
|
30 # ________ |
|
31 # ----| Gsys |--- |
|
32 # u | ---------- +| |
|
33 # ----- (_)----> y |
|
34 # | ________ +| |
|
35 # ----| Hsys |--- |
|
36 # -------- |
|
37 |
|
38 # Written by John Ingram July 1996 |
3229
|
39 # $Revision: 2.0.0.2 $ |
3213
|
40 |
|
41 save_val = implicit_str_to_num_ok; # save for later |
|
42 implicit_str_to_num_ok = 1; |
|
43 |
|
44 if(nargin != 2) |
|
45 usage("sysadd: [sys] = sysysadd(Gsys,Hsys)"); |
|
46 endif |
|
47 |
|
48 # check inputs |
|
49 if(!is_struct(Gsys) | !is_struct(Hsys)) |
|
50 error("Both Gsys and Hsys must be in system data structure form"); |
|
51 endif |
|
52 |
|
53 # check for compatibility |
|
54 [n,nz,mg,pg] = sysdimensions(Gsys); |
|
55 [n,nz,mh,ph] = sysdimensions(Hsys); |
|
56 if(mg != mh) |
|
57 error(sprintf("Gsys inputs(%d) != Hsys inputs (%d)",mg,mh)); |
|
58 elseif(pg != ph) |
|
59 error(sprintf("Gsys outputs(%d) != Hsys outputs (%d)",pg,ph)); |
|
60 endif |
|
61 |
|
62 [Gst, Gin, Gout, Gyd] = sysgetsignals(Gsys); |
|
63 [Hst, Hin, Hout, Hyd] = sysgetsignals(Hsys); |
|
64 |
|
65 # check for digital to continuous addition |
|
66 if (Gyd != Hyd) |
|
67 error("can not add a discrete output to a continuous output"); |
|
68 endif |
|
69 |
3228
|
70 if( strcmp(sysgettype(Gsys),"tf") | strcmp(sysgettype(Hsys),"tf") ) |
3213
|
71 # see if adding transfer functions with identical denominators |
3228
|
72 [Gnum,Gden,GT,Gin,Gout] = sys2tf(Gsys); |
|
73 [Hnum,Hden,HT,Hin,Hout] = sys2tf(Hsys); |
|
74 if( (Hden == Gden) & (HT == GT) ) |
|
75 sys = tf2sys(Gnum+Hnum,Gden,GT,Gin,Gout); |
3213
|
76 return |
|
77 endif |
3228
|
78 # if not, we go on and do the usual thing... |
3213
|
79 endif |
|
80 |
|
81 # make sure in ss form |
|
82 Gsys = sysupdate(Gsys,"ss"); |
|
83 Hsys = sysupdate(Hsys,"ss"); |
|
84 |
|
85 sys = sysgroup(Gsys,Hsys); |
|
86 |
|
87 eyin = eye(mg); |
|
88 eyout = eye(pg); |
|
89 |
|
90 |
|
91 inname = Gin; |
|
92 outname = Gout; |
|
93 |
|
94 sys = sysscale(sys,[eyout eyout],[eyin;eyin],outname,inname); |
|
95 |
|
96 endfunction |