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 |
|
49 if(nargin < 1) |
6046
|
50 print_usage (); |
3430
|
51 endif |
|
52 |
|
53 ## collect all arguments |
4771
|
54 arglist = {}; |
3430
|
55 for kk=1:nargin |
4771
|
56 arglist{kk} = varargin{kk}; |
|
57 if(!isstruct(arglist{kk})) |
3430
|
58 error("sysadd: argument %d is not a data structure",kk); |
|
59 endif |
|
60 endfor |
|
61 |
|
62 ## check system dimensions |
4771
|
63 [n,nz,mg,pg,Gyd] = sysdimensions(arglist{1}); |
3430
|
64 for kk=2:nargin |
4771
|
65 [n,nz,mh,ph,Hyd] = sysdimensions(arglist{kk}); |
3430
|
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); |
|
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 |
|
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 |
3430
|
86 [Gnum,Gden,GT,Gin,Gout] = sys2tf(Gsys); |
|
87 [Hnum,Hden,HT,Hin,Hout] = sys2tf(Hsys); |
4771
|
88 if (length(Hden) == length(Gden) ) |
|
89 if( (Hden == Gden) & (HT == GT) ) |
|
90 sys = tf(Gnum+Hnum,Gden,GT,Gin,Gout); |
4404
|
91 |
4771
|
92 return; # return prematurely since the add is done. |
|
93 endif |
3430
|
94 endif |
|
95 endif |
|
96 |
|
97 ## make sure in ss form |
|
98 Gsys = sysupdate(Gsys,"ss"); |
|
99 Hsys = sysupdate(Hsys,"ss"); |
4771
|
100 Gin = sysgetsignals(Gsys,"in"); |
|
101 Gout = sysgetsignals(Gsys,"out"); |
|
102 Hin = sysgetsignals(Hsys,"in"); |
|
103 Hout = sysgetsignals(Hsys,"out"); |
3430
|
104 |
|
105 ## change signal names to avoid warning messages from sysgroup |
3438
|
106 Gsys = syssetsignals(Gsys,"in",__sysdefioname__(length(Gin),"Gin_u")); |
|
107 Gsys = syssetsignals(Gsys,"out",__sysdefioname__(length(Gout),"Gout_u")); |
|
108 Hsys = syssetsignals(Hsys,"in",__sysdefioname__(length(Hin),"Hin_u")); |
|
109 Hsys = syssetsignals(Hsys,"out",__sysdefioname__(length(Hout),"Hout_u")); |
3430
|
110 |
|
111 sys = sysgroup(Gsys,Hsys); |
|
112 |
|
113 eyin = eye(mg); |
|
114 eyout = eye(pg); |
|
115 |
|
116 sys = sysscale(sys,[eyout, eyout],[eyin;eyin],Gout,Gin); |
|
117 |
|
118 else |
|
119 ## multiple systems (or a single system); combine together one by one |
4771
|
120 sys = arglist{1}; |
3430
|
121 for kk=2:length(arglist) |
4771
|
122 sys = sysadd(sys,arglist{kk}); |
3430
|
123 endfor |
|
124 endif |
|
125 |
|
126 endfunction |
|
127 |