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 -*- |
3500
|
20 ## @deftypefn {Function File} {} syssub (@var{Gsys}, @var{Hsys}) |
3430
|
21 ## returns @math{sys = Gsys - Hsys} |
|
22 ## |
|
23 ## Method: @var{Gsys} and @var{Hsys} are connected in parallel |
|
24 ## The input vector is connected to both systems; the outputs are |
|
25 ## subtracted. Returned system names are those of @var{Gsys}. |
|
26 ## @example |
|
27 ## @group |
|
28 ## +--------+ |
|
29 ## +--->| Gsys |---+ |
|
30 ## | +--------+ | |
|
31 ## | +| |
|
32 ## u --+ (_)--> y |
|
33 ## | -| |
|
34 ## | +--------+ | |
|
35 ## +--->| Hsys |---+ |
|
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 |
|
45 function sys = syssub (...) |
|
46 |
|
47 if(nargin < 1) |
|
48 usage("syssub: sys = syssub(Gsys{,Hsys,...})"); |
|
49 endif |
|
50 |
|
51 ## collect all arguments |
|
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("syssub: 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 subtract |
|
76 if(nargin == 2) |
|
77 Gsys = nth(arglist,1); Hsys = nth(arglist,2); |
|
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) ) |
|
84 sys = tf2sys(Gnum+Hnum,Gden,GT,Gin,Gout); |
|
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 |
|
110 sys = nth(arglist,1); |
|
111 for kk=2:length(arglist) |
|
112 sys = syssub(sys,nth(arglist,kk)); |
|
113 endfor |
|
114 endif |
|
115 |
|
116 endfunction |