7017
|
1 ## Copyright (C) 1996, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007 |
|
2 ## Auburn University. All rights reserved. |
3430
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
7016
|
7 ## under the terms of the GNU General Public License as published by |
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
3430
|
10 ## |
7016
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
3430
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
3430
|
19 |
|
20 ## -*- texinfo -*- |
3502
|
21 ## @deftypefn {Function File} {} sysadd (@var{gsys}, @var{hsys}) |
|
22 ## returns @var{sys} = @var{gsys} + @var{hsys}. |
3430
|
23 ## @itemize @bullet |
|
24 ## @item Exits with |
3502
|
25 ## an error if @var{gsys} and @var{hsys} are not compatibly dimensioned. |
3430
|
26 ## @item Prints a warning message is system states have identical names; |
|
27 ## duplicate names are given a suffix to make them unique. |
3502
|
28 ## @item @var{sys} input/output names are taken from @var{gsys}. |
3430
|
29 ## @end itemize |
|
30 ## @example |
|
31 ## @group |
|
32 ## ________ |
3502
|
33 ## ----| gsys |--- |
3430
|
34 ## u | ---------- +| |
|
35 ## ----- (_)----> y |
|
36 ## | ________ +| |
3502
|
37 ## ----| hsys |--- |
3430
|
38 ## -------- |
|
39 ## @end group |
|
40 ## @end example |
|
41 ## @end deftypefn |
|
42 |
|
43 ## Author: John Ingram <ingraje@eng.auburn.edu> |
|
44 ## Created: July 1996 |
|
45 ## Updated for variable number of arguments July 1999 A. S. Hodel |
|
46 |
3979
|
47 function sys = sysadd (varargin) |
3430
|
48 |
7135
|
49 if (nargin < 1) |
6046
|
50 print_usage (); |
3430
|
51 endif |
|
52 |
|
53 ## collect all arguments |
4771
|
54 arglist = {}; |
7135
|
55 for kk = 1:nargin |
4771
|
56 arglist{kk} = varargin{kk}; |
7135
|
57 if (! isstruct (arglist{kk})) |
|
58 error ("sysadd: argument %d is not a data structure", kk); |
3430
|
59 endif |
|
60 endfor |
|
61 |
|
62 ## check system dimensions |
7135
|
63 [n, nz, mg, pg, Gyd] = sysdimensions (arglist{1}); |
|
64 for kk = 2:nargin |
|
65 [n, nz, mh, ph, Hyd] = sysdimensions (arglist{kk}); |
|
66 if (mg != mh) |
|
67 error ("arg 1 has %d inputs; arg %d has vs %d inputs", mg, kk, mh); |
|
68 elseif (pg != ph) |
|
69 error ("arg 1 has %d outputs; arg %d has vs %d outputs", pg, kk, ph); |
|
70 elseif (norm (Gyd - Hyd)) |
|
71 warning ("cannot add a discrete output to a continuous output"); |
|
72 error ("Output type mismatch: arguments 1 and %d\n", kk); |
3430
|
73 endif |
|
74 endfor |
|
75 |
|
76 ## perform the add |
4404
|
77 if (nargin == 2) |
4771
|
78 Gsys = arglist{1}; |
|
79 Hsys = arglist{2}; |
4404
|
80 |
4771
|
81 # check if adding scalar transfer functions with identical denoms |
7135
|
82 [Gn, Gnz, Gm, Gp] = sysdimensions (Gsys); |
|
83 [Hn, Hnz, Hm, Hp] = sysdimensions (Hsys); |
|
84 if (Gm == 1 & Gp == 1 & Hm == 1 & Hp == 1 & Gn == Hn & Gnz == Hnz) |
|
85 ## dimensions are compatible, check if can add |
|
86 [Gnum, Gden, GT, Gin, Gout] = sys2tf (Gsys); |
|
87 [Hnum, Hden, HT, Hin, Hout] = sys2tf (Hsys); |
|
88 if (length (Hden) == length (Gden) ) |
|
89 if ((Hden == Gden) & (HT == GT)) |
|
90 sys = tf (Gnum+Hnum, Gden, GT, Gin, Gout); |
|
91 return; |
4771
|
92 endif |
3430
|
93 endif |
|
94 endif |
|
95 |
|
96 ## make sure in ss form |
7135
|
97 Gsys = sysupdate (Gsys, "ss"); |
|
98 Hsys = sysupdate (Hsys, "ss"); |
|
99 Gin = sysgetsignals (Gsys, "in"); |
|
100 Gout = sysgetsignals (Gsys, "out"); |
|
101 Hin = sysgetsignals (Hsys, "in"); |
|
102 Hout = sysgetsignals (Hsys, "out"); |
3430
|
103 |
|
104 ## change signal names to avoid warning messages from sysgroup |
7135
|
105 Gsys = syssetsignals (Gsys, "in", |
|
106 __sysdefioname__ (length (Gin), "Gin_u")); |
|
107 |
|
108 Gsys = syssetsignals (Gsys, "out", |
|
109 __sysdefioname__ (length (Gout), "Gout_u")); |
|
110 |
|
111 Hsys = syssetsignals (Hsys, "in", |
|
112 __sysdefioname__ (length (Hin), "Hin_u")); |
3430
|
113 |
7135
|
114 Hsys = syssetsignals (Hsys, "out", |
|
115 __sysdefioname__ (length (Hout), "Hout_u")); |
|
116 |
|
117 sys = sysgroup (Gsys, Hsys); |
3430
|
118 |
7135
|
119 eyin = eye (mg); |
|
120 eyout = eye (pg); |
3430
|
121 |
7135
|
122 sys = sysscale (sys, [eyout, eyout], [eyin; eyin], Gout, Gin); |
3430
|
123 |
|
124 else |
|
125 ## multiple systems (or a single system); combine together one by one |
4771
|
126 sys = arglist{1}; |
7135
|
127 for kk = 2:length(arglist) |
|
128 sys = sysadd (sys, arglist{kk}); |
3430
|
129 endfor |
|
130 endif |
|
131 |
|
132 endfunction |
|
133 |