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 |
|
53 arglist = list(); |
|
54 for kk=1:nargin |
3979
|
55 arglist(kk) = varargin{kk}; |
4030
|
56 if(!isstruct(nth(arglist,kk))) |
3430
|
57 error("sysadd: argument %d is not a data structure",kk); |
|
58 endif |
|
59 endfor |
|
60 |
|
61 ## check system dimensions |
|
62 [n,nz,mg,pg,Gyd] = sysdimensions(nth(arglist,1)); |
|
63 for kk=2:nargin |
|
64 [n,nz,mh,ph,Hyd] = sysdimensions(nth(arglist,kk)); |
|
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) |
|
77 Gsys = nth(arglist,1); |
|
78 Hsys = nth(arglist,2); |
|
79 |
|
80 if (! strcmp (sysgettype (Gsys), "tf")) |
3430
|
81 [Gnum,Gden,GT,Gin,Gout] = sys2tf(Gsys); |
4404
|
82 endif |
|
83 |
|
84 if (! strcmp (sysgettype (Hsys),"tf")) |
3430
|
85 [Hnum,Hden,HT,Hin,Hout] = sys2tf(Hsys); |
4404
|
86 endif |
|
87 |
|
88 ## see if adding transfer functions with identical denominators |
|
89 if (length(Hden) == length(Gden) ) |
|
90 if( (Hden == Gden) & (HT == GT) ) |
|
91 sys = tf2sys(Gnum+Hnum,Gden,GT,Gin,Gout); |
|
92 return |
3430
|
93 endif |
4404
|
94 ## if not, we go on and do the usual thing... |
3430
|
95 endif |
|
96 |
|
97 ## make sure in ss form |
|
98 Gsys = sysupdate(Gsys,"ss"); |
|
99 Hsys = sysupdate(Hsys,"ss"); |
|
100 |
|
101 ## change signal names to avoid warning messages from sysgroup |
3438
|
102 Gsys = syssetsignals(Gsys,"in",__sysdefioname__(length(Gin),"Gin_u")); |
|
103 Gsys = syssetsignals(Gsys,"out",__sysdefioname__(length(Gout),"Gout_u")); |
|
104 Hsys = syssetsignals(Hsys,"in",__sysdefioname__(length(Hin),"Hin_u")); |
|
105 Hsys = syssetsignals(Hsys,"out",__sysdefioname__(length(Hout),"Hout_u")); |
3430
|
106 |
|
107 sys = sysgroup(Gsys,Hsys); |
|
108 |
|
109 eyin = eye(mg); |
|
110 eyout = eye(pg); |
|
111 |
|
112 sys = sysscale(sys,[eyout, eyout],[eyin;eyin],Gout,Gin); |
|
113 |
|
114 else |
|
115 ## multiple systems (or a single system); combine together one by one |
|
116 sys = nth(arglist,1); |
|
117 for kk=2:length(arglist) |
|
118 sys = sysadd(sys,nth(arglist,kk)); |
|
119 endfor |
|
120 endif |
|
121 |
|
122 endfunction |
|
123 |