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. |
3213
|
18 |
3279
|
19 function sys = sysadd(...) |
3213
|
20 # |
3279
|
21 # sys = sysadd(Gsys{,Hsys,...}) |
3213
|
22 # |
3279
|
23 # returns transfer function sys = Gsys + Hsys + ... |
3213
|
24 # |
3279
|
25 # Method: sysgroup used to connect systems in parallel |
|
26 # The input vector is connected to all systems; the outputs are summed. |
|
27 # Returned system input/output signal names are those of Gsys. For |
|
28 # example, sysadd(Gsys,Hsys) results in |
3213
|
29 # |
|
30 # ________ |
|
31 # ----| Gsys |--- |
|
32 # u | ---------- +| |
|
33 # ----- (_)----> y |
|
34 # | ________ +| |
|
35 # ----| Hsys |--- |
|
36 # -------- |
|
37 |
|
38 # Written by John Ingram July 1996 |
3279
|
39 # Updated for variable number of arguments July 1999 A. S. Hodel |
3213
|
40 |
|
41 save_val = implicit_str_to_num_ok; # save for later |
|
42 implicit_str_to_num_ok = 1; |
|
43 |
3279
|
44 if(nargin < 1) |
|
45 usage("sysadd: sys = sysysadd(Gsys{,Hsys, ...})"); |
3213
|
46 endif |
|
47 |
3279
|
48 # collect all arguments |
|
49 arglist = list(); |
|
50 va_start(); |
|
51 for kk=1:nargin |
|
52 arglist(kk) = va_arg(); |
|
53 if(!is_struct(nth(arglist,kk))) |
|
54 error("sysadd: argument %d is not a data structure",kk); |
3213
|
55 endif |
3279
|
56 endfor |
3213
|
57 |
3279
|
58 # check system dimensions |
|
59 [n,nz,mg,pg,Gyd] = sysdimensions(nth(arglist,1)); |
|
60 for kk=2:nargin |
|
61 [n,nz,mh,ph,Hyd] = sysdimensions(nth(arglist,kk)); |
|
62 if(mg != mh) |
|
63 error("arg 1 has %d inputs; arg %d has vs %d inputs",mg,kk,mh); |
|
64 elseif(pg != ph) |
|
65 error("arg 1 has %d outputs; arg %d has vs %d outputs",pg,kk,ph); |
|
66 elseif(norm(Gyd - Hyd)) |
|
67 warning("cannot add a discrete output to a continuous output"); |
|
68 error("Output type mismatch: arguments 1 and %d\n",kk); |
|
69 endif |
|
70 endfor |
3213
|
71 |
3279
|
72 # perform the add |
|
73 if(nargin == 2) |
|
74 Gsys = nth(arglist,1); Hsys = nth(arglist,2); |
|
75 if( strcmp(sysgettype(Gsys),"tf") | strcmp(sysgettype(Hsys),"tf") ) |
|
76 # see if adding transfer functions with identical denominators |
|
77 [Gnum,Gden,GT,Gin,Gout] = sys2tf(Gsys); |
|
78 [Hnum,Hden,HT,Hin,Hout] = sys2tf(Hsys); |
|
79 if(length(Hden) == length(Gden) ) |
|
80 if( (Hden == Gden) & (HT == GT) ) |
|
81 sys = tf2sys(Gnum+Hnum,Gden,GT,Gin,Gout); |
|
82 return |
|
83 endif |
|
84 # if not, we go on and do the usual thing... |
|
85 endif |
|
86 endif |
|
87 |
|
88 # make sure in ss form |
|
89 Gsys = sysupdate(Gsys,"ss"); |
|
90 Hsys = sysupdate(Hsys,"ss"); |
3236
|
91 |
3279
|
92 # change signal names to avoid warning messages from sysgroup |
|
93 Gsys = syssetsignals(Gsys,"in",sysdefioname(length(Gin),"Gin_u")); |
|
94 Gsys = syssetsignals(Gsys,"out",sysdefioname(length(Gout),"Gout_u")); |
|
95 Hsys = syssetsignals(Hsys,"in",sysdefioname(length(Hin),"Hin_u")); |
|
96 Hsys = syssetsignals(Hsys,"out",sysdefioname(length(Hout),"Hout_u")); |
|
97 |
|
98 sys = sysgroup(Gsys,Hsys); |
|
99 |
|
100 eyin = eye(mg); |
|
101 eyout = eye(pg); |
|
102 |
|
103 sys = sysscale(sys,[eyout, eyout],[eyin;eyin],Gout,Gin); |
|
104 |
|
105 else |
|
106 # multiple systems (or a single system); combine together one by one |
|
107 sys = nth(arglist,1); |
|
108 for kk=2:length(arglist) |
|
109 sys = sysadd(sys,nth(arglist,kk)); |
|
110 endfor |
|
111 endif |
|
112 endfunction |
3213
|
113 |