3430
|
1 ## Copyright (C) 1996, 1999 Auburn University. All rights reserved. |
|
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, 59 Temple Place, Suite 330, Boston, MA 02111 USA. |
|
18 |
|
19 ## -*- texinfo -*- |
3502
|
20 ## @deftypefn {Function File} {} sysadd (@var{gsys}, @var{hsys}) |
|
21 ## returns @var{sys} = @var{gsys} + @var{hsys}. |
3430
|
22 ## @itemize @bullet |
|
23 ## @item Exits with |
3502
|
24 ## an error if @var{gsys} and @var{hsys} are not compatibly dimensioned. |
3430
|
25 ## @item Prints a warning message is system states have identical names; |
|
26 ## duplicate names are given a suffix to make them unique. |
3502
|
27 ## @item @var{sys} input/output names are taken from @var{gsys}. |
3430
|
28 ## @end itemize |
|
29 ## @example |
|
30 ## @group |
|
31 ## ________ |
3502
|
32 ## ----| gsys |--- |
3430
|
33 ## u | ---------- +| |
|
34 ## ----- (_)----> y |
|
35 ## | ________ +| |
3502
|
36 ## ----| hsys |--- |
3430
|
37 ## -------- |
|
38 ## @end group |
|
39 ## @end example |
|
40 ## @end deftypefn |
|
41 |
|
42 ## Author: John Ingram <ingraje@eng.auburn.edu> |
|
43 ## Created: July 1996 |
|
44 ## Updated for variable number of arguments July 1999 A. S. Hodel |
|
45 |
3979
|
46 function sys = sysadd (varargin) |
3430
|
47 |
|
48 if(nargin < 1) |
|
49 usage("sysadd: sys = sysysadd(Gsys{,Hsys, ...})"); |
|
50 endif |
|
51 |
|
52 ## collect all arguments |
4771
|
53 arglist = {}; |
3430
|
54 for kk=1:nargin |
4771
|
55 arglist{kk} = varargin{kk}; |
|
56 if(!isstruct(arglist{kk})) |
3430
|
57 error("sysadd: argument %d is not a data structure",kk); |
|
58 endif |
|
59 endfor |
|
60 |
|
61 ## check system dimensions |
4771
|
62 [n,nz,mg,pg,Gyd] = sysdimensions(arglist{1}); |
3430
|
63 for kk=2:nargin |
4771
|
64 [n,nz,mh,ph,Hyd] = sysdimensions(arglist{kk}); |
3430
|
65 if(mg != mh) |
|
66 error("arg 1 has %d inputs; arg %d has vs %d inputs",mg,kk,mh); |
|
67 elseif(pg != ph) |
|
68 error("arg 1 has %d outputs; arg %d has vs %d outputs",pg,kk,ph); |
|
69 elseif(norm(Gyd - Hyd)) |
|
70 warning("cannot add a discrete output to a continuous output"); |
|
71 error("Output type mismatch: arguments 1 and %d\n",kk); |
|
72 endif |
|
73 endfor |
|
74 |
|
75 ## perform the add |
4404
|
76 if (nargin == 2) |
4771
|
77 Gsys = arglist{1}; |
|
78 Hsys = arglist{2}; |
4404
|
79 |
4771
|
80 # check if adding scalar transfer functions with identical denoms |
|
81 [Gn, Gnz, Gm, Gp] = sysdimensions(Gsys); |
|
82 [Hn, Hnz, Hm, Hp] = sysdimensions(Hsys); |
|
83 if ( Gm ==1 & Gp == 1 & Hm == 1 & Hp == 1 & Gn == Hn & Gnz == Hnz ) |
|
84 # dimensions are compatible, check if can add |
3430
|
85 [Gnum,Gden,GT,Gin,Gout] = sys2tf(Gsys); |
|
86 [Hnum,Hden,HT,Hin,Hout] = sys2tf(Hsys); |
4771
|
87 if (length(Hden) == length(Gden) ) |
|
88 if( (Hden == Gden) & (HT == GT) ) |
|
89 sys = tf(Gnum+Hnum,Gden,GT,Gin,Gout); |
4404
|
90 |
4771
|
91 return; # return prematurely since the add is done. |
|
92 endif |
3430
|
93 endif |
|
94 endif |
|
95 |
|
96 ## make sure in ss form |
|
97 Gsys = sysupdate(Gsys,"ss"); |
|
98 Hsys = sysupdate(Hsys,"ss"); |
4771
|
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 |
3438
|
105 Gsys = syssetsignals(Gsys,"in",__sysdefioname__(length(Gin),"Gin_u")); |
|
106 Gsys = syssetsignals(Gsys,"out",__sysdefioname__(length(Gout),"Gout_u")); |
|
107 Hsys = syssetsignals(Hsys,"in",__sysdefioname__(length(Hin),"Hin_u")); |
|
108 Hsys = syssetsignals(Hsys,"out",__sysdefioname__(length(Hout),"Hout_u")); |
3430
|
109 |
|
110 sys = sysgroup(Gsys,Hsys); |
|
111 |
|
112 eyin = eye(mg); |
|
113 eyout = eye(pg); |
|
114 |
|
115 sys = sysscale(sys,[eyout, eyout],[eyin;eyin],Gout,Gin); |
|
116 |
|
117 else |
|
118 ## multiple systems (or a single system); combine together one by one |
4771
|
119 sys = arglist{1}; |
3430
|
120 for kk=2:length(arglist) |
4771
|
121 sys = sysadd(sys,arglist{kk}); |
3430
|
122 endfor |
|
123 endif |
|
124 |
|
125 endfunction |
|
126 |