7017
|
1 ## Copyright (C) 1996, 1999, 2000, 2002, 2004, 2005, 2006, 2007 |
|
2 ## Auburn University. All rights reserved. |
3430
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
7016
|
7 ## under the terms of the GNU General Public License as published by |
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
3430
|
10 ## |
7016
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
3430
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
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 |
7136
|
50 if (nargin < 1) |
6046
|
51 print_usage (); |
3430
|
52 endif |
|
53 |
|
54 ## collect all arguments |
4771
|
55 arglist = {}; |
7136
|
56 for kk = 1:nargin |
4771
|
57 arglist{kk} = varargin{kk}; |
7136
|
58 if (! isstruct (arglist{kk})) |
|
59 error ("syssub: argument %d is not a data structure", kk); |
3430
|
60 endif |
|
61 endfor |
|
62 |
|
63 ## check system dimensions |
7136
|
64 [n, nz, mg, pg, Gyd] = sysdimensions (arglist{1}); |
|
65 for kk = 2:nargin |
|
66 [n, nz, mh, ph, Hyd] = sysdimensions (arglist{kk}); |
|
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", kk); |
3430
|
74 endif |
|
75 endfor |
|
76 |
|
77 ## perform the subtract |
7136
|
78 if (nargin == 2) |
4771
|
79 Gsys = arglist{1}; |
|
80 Hsys = arglist{2}; |
7136
|
81 if (strcmp (sysgettype (Gsys), "tf") || strcmp (sysgettype (Hsys), "tf")) |
3430
|
82 ## see if subtracting transfer functions with identical denominators |
7136
|
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)) |
|
87 sys = tf (Gnum-Hnum, Gden, GT, Gin, Gout); |
|
88 return; |
3430
|
89 endif |
|
90 ## if not, we go on and do the usual thing... |
|
91 endif |
|
92 endif |
|
93 |
|
94 ## make sure in ss form |
7136
|
95 Gsys = sysupdate (Gsys, "ss"); |
|
96 Hsys = sysupdate (Hsys, "ss"); |
3430
|
97 |
|
98 ## change signal names to avoid warning messages from sysgroup |
7136
|
99 Gsys = syssetsignals (Gsys, "in", |
|
100 __sysdefioname__(length(Gin), "Gin_u")); |
|
101 |
|
102 Gsys = syssetsignals (Gsys, "out", |
|
103 __sysdefioname__(length(Gout), "Gout_u")); |
3430
|
104 |
7136
|
105 Hsys = syssetsignals (Hsys, "in", |
|
106 __sysdefioname__(length(Hin), "Hin_u")); |
3430
|
107 |
7136
|
108 Hsys = syssetsignals (Hsys, "out", |
|
109 __sysdefioname__(length(Hout), "Hout_u")); |
|
110 |
|
111 sys = sysgroup (Gsys, Hsys); |
|
112 |
|
113 eyin = eye (mg); |
|
114 eyout = eye (pg); |
3430
|
115 |
|
116 sys = sysscale (sys, [eyout, -eyout], [eyin; eyin], Gout, Gin); |
|
117 |
|
118 else |
|
119 ## multiple systems (or a single system); combine together one by one |
4771
|
120 sys = arglist{1}; |
7136
|
121 for kk = 2:length(arglist) |
|
122 sys = syssub (sys, arglist{kk}); |
3430
|
123 endfor |
|
124 endif |
|
125 |
|
126 endfunction |