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