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} {} syssub (@var{gsys}, @var{hsys}) |
|
21 ## Return @math{sys = Gsys - Hsys}. |
3430
|
22 ## |
3502
|
23 ## Method: @var{gsys} and @var{hsys} are connected in parallel |
3430
|
24 ## The input vector is connected to both systems; the outputs are |
3502
|
25 ## subtracted. Returned system names are those of @var{gsys}. |
3430
|
26 ## @example |
|
27 ## @group |
|
28 ## +--------+ |
3502
|
29 ## +--->| gsys |---+ |
3430
|
30 ## | +--------+ | |
|
31 ## | +| |
|
32 ## u --+ (_)--> y |
|
33 ## | -| |
|
34 ## | +--------+ | |
3502
|
35 ## +--->| hsys |---+ |
3430
|
36 ## +--------+ |
|
37 ## @end group |
|
38 ## @end example |
|
39 ## @end deftypefn |
|
40 |
|
41 ## Author: John Ingram <ingraje@eng.auburn.edu> |
|
42 ## Created: July 1996 |
|
43 ## updated for variable numbers of input arguments by July 1999 A. S. Hodel |
|
44 |
3979
|
45 function sys = syssub (varargin) |
3430
|
46 |
|
47 if(nargin < 1) |
|
48 usage("syssub: sys = syssub(Gsys{,Hsys,...})"); |
|
49 endif |
|
50 |
|
51 ## collect all arguments |
4771
|
52 arglist = {}; |
3430
|
53 for kk=1:nargin |
4771
|
54 arglist{kk} = varargin{kk}; |
|
55 if(!isstruct(arglist{kk})) |
3430
|
56 error("syssub: argument %d is not a data structure",kk); |
|
57 endif |
|
58 endfor |
|
59 |
|
60 ## check system dimensions |
4771
|
61 [n,nz,mg,pg,Gyd] = sysdimensions(arglist{1}); |
3430
|
62 for kk=2:nargin |
4771
|
63 [n,nz,mh,ph,Hyd] = sysdimensions(arglist{kk}); |
3430
|
64 if(mg != mh) |
|
65 error("arg 1 has %d inputs; arg %d has vs %d inputs",mg,kk,mh); |
|
66 elseif(pg != ph) |
|
67 error("arg 1 has %d outputs; arg %d has vs %d outputs",pg,kk,ph); |
|
68 elseif(norm(Gyd - Hyd)) |
|
69 warning("cannot add a discrete output to a continuous output"); |
|
70 error("Output type mismatch: arguments 1 and %d\n",kk); |
|
71 endif |
|
72 endfor |
|
73 |
|
74 ## perform the subtract |
|
75 if(nargin == 2) |
4771
|
76 Gsys = arglist{1}; |
|
77 Hsys = arglist{2}; |
3430
|
78 if( strcmp(sysgettype(Gsys),"tf") | strcmp(sysgettype(Hsys),"tf") ) |
|
79 ## see if subtracting transfer functions with identical denominators |
|
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) ) |
4771
|
84 sys = tf(Gnum-Hnum,Gden,GT,Gin,Gout); |
3430
|
85 return |
|
86 endif |
|
87 ## if not, we go on and do the usual thing... |
|
88 endif |
|
89 endif |
|
90 |
|
91 ## make sure in ss form |
|
92 Gsys = sysupdate(Gsys,"ss"); |
|
93 Hsys = sysupdate(Hsys,"ss"); |
|
94 |
|
95 ## change signal names to avoid warning messages from sysgroup |
3438
|
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")); |
3430
|
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 |
|
109 ## multiple systems (or a single system); combine together one by one |
4771
|
110 sys = arglist{1}; |
3430
|
111 for kk=2:length(arglist) |
4771
|
112 sys = syssub(sys,arglist{kk}); |
3430
|
113 endfor |
|
114 endif |
|
115 |
|
116 endfunction |