3381
|
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. |
3346
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File } { @var{sys} =} sysadd ( @var{Gsys},@var{Hsys}) |
|
21 ## returns @var{sys} = @var{Gsys} + @var{Hsys}. |
|
22 ## @itemize @bullet |
|
23 ## @item Exits with |
|
24 ## an error if @var{Gsys} and @var{Hsys} are not compatibly dimensioned. |
|
25 ## @item Prints a warning message is system states have identical names; |
|
26 ## duplicate names are given a suffix to make them unique. |
|
27 ## @item @var{sys} input/output names are taken from @var{Gsys}. |
|
28 ## @end itemize |
|
29 ## @example |
|
30 ## @group |
|
31 ## ________ |
|
32 ## ----| Gsys |--- |
|
33 ## u | ---------- +| |
|
34 ## ----- (_)----> y |
|
35 ## | ________ +| |
|
36 ## ----| Hsys |--- |
|
37 ## -------- |
|
38 ## @end group |
|
39 ## @end example |
|
40 ## @end deftypefn |
3213
|
41 |
3279
|
42 function sys = sysadd(...) |
3381
|
43 |
|
44 ## Written by John Ingram July 1996 |
|
45 ## Updated for variable number of arguments July 1999 A. S. Hodel |
3213
|
46 |
3279
|
47 if(nargin < 1) |
|
48 usage("sysadd: sys = sysysadd(Gsys{,Hsys, ...})"); |
3213
|
49 endif |
|
50 |
3381
|
51 ## collect all arguments |
3279
|
52 arglist = list(); |
|
53 va_start(); |
|
54 for kk=1:nargin |
|
55 arglist(kk) = va_arg(); |
|
56 if(!is_struct(nth(arglist,kk))) |
|
57 error("sysadd: argument %d is not a data structure",kk); |
3213
|
58 endif |
3279
|
59 endfor |
3213
|
60 |
3381
|
61 ## check system dimensions |
3279
|
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 |
3213
|
74 |
3381
|
75 ## perform the add |
3279
|
76 if(nargin == 2) |
|
77 Gsys = nth(arglist,1); Hsys = nth(arglist,2); |
|
78 if( strcmp(sysgettype(Gsys),"tf") | strcmp(sysgettype(Hsys),"tf") ) |
3381
|
79 ## see if adding transfer functions with identical denominators |
3279
|
80 [Gnum,Gden,GT,Gin,Gout] = sys2tf(Gsys); |
|
81 [Hnum,Hden,HT,Hin,Hout] = sys2tf(Hsys); |
|
82 if(length(Hden) == length(Gden) ) |
|
83 if( (Hden == Gden) & (HT == GT) ) |
|
84 sys = tf2sys(Gnum+Hnum,Gden,GT,Gin,Gout); |
|
85 return |
|
86 endif |
3381
|
87 ## if not, we go on and do the usual thing... |
3279
|
88 endif |
|
89 endif |
|
90 |
3381
|
91 ## make sure in ss form |
3279
|
92 Gsys = sysupdate(Gsys,"ss"); |
|
93 Hsys = sysupdate(Hsys,"ss"); |
3236
|
94 |
3381
|
95 ## change signal names to avoid warning messages from sysgroup |
3279
|
96 Gsys = syssetsignals(Gsys,"in",sysdefioname(length(Gin),"Gin_u")); |
|
97 Gsys = syssetsignals(Gsys,"out",sysdefioname(length(Gout),"Gout_u")); |
|
98 Hsys = syssetsignals(Hsys,"in",sysdefioname(length(Hin),"Hin_u")); |
|
99 Hsys = syssetsignals(Hsys,"out",sysdefioname(length(Hout),"Hout_u")); |
|
100 |
|
101 sys = sysgroup(Gsys,Hsys); |
|
102 |
|
103 eyin = eye(mg); |
|
104 eyout = eye(pg); |
|
105 |
|
106 sys = sysscale(sys,[eyout, eyout],[eyin;eyin],Gout,Gin); |
|
107 |
|
108 else |
3381
|
109 ## multiple systems (or a single system); combine together one by one |
3279
|
110 sys = nth(arglist,1); |
|
111 for kk=2:length(arglist) |
|
112 sys = sysadd(sys,nth(arglist,kk)); |
|
113 endfor |
|
114 endif |
3383
|
115 |
3279
|
116 endfunction |
3213
|
117 |