7017
|
1 ## Copyright (C) 1996, 1998, 2000, 2002, 2003, 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} =} sysappend (@var{syst}, @var{b}, @var{c}, @var{d}, @var{outname}, @var{inname}, @var{yd}) |
3430
|
22 ## appends new inputs and/or outputs to a system |
|
23 ## |
|
24 ## @strong{Inputs} |
|
25 ## @table @var |
5016
|
26 ## @item syst |
3430
|
27 ## system data structure |
|
28 ## |
|
29 ## @item b |
|
30 ## matrix to be appended to sys "B" matrix (empty if none) |
|
31 ## |
|
32 ## @item c |
|
33 ## matrix to be appended to sys "C" matrix (empty if none) |
|
34 ## |
|
35 ## @item d |
|
36 ## revised sys d matrix (can be passed as [] if the revised d is all zeros) |
|
37 ## |
|
38 ## @item outname |
|
39 ## list of names for new outputs |
|
40 ## |
|
41 ## @item inname |
|
42 ## list of names for new inputs |
|
43 ## |
|
44 ## @item yd |
|
45 ## binary vector; @math{yd(ii)=0} indicates a continuous output; |
|
46 ## @math{yd(ii)=1} indicates a discrete output. |
|
47 ## @end table |
|
48 ## |
5016
|
49 ## @strong{Outputs} |
|
50 ## @table @var |
|
51 ## @item sys |
3430
|
52 ## @example |
|
53 ## @group |
5016
|
54 ## sys.b := [syst.b , b] |
|
55 ## sys.c := [syst.c ] |
3430
|
56 ## [ c ] |
5016
|
57 ## sys.d := [syst.d | D12 ] |
|
58 ## [ D21 | D22 ] |
3430
|
59 ## @end group |
|
60 ## @end example |
3502
|
61 ## where @math{D12}, @math{D21}, and @math{D22} are the appropriate dimensioned |
3430
|
62 ## blocks of the input parameter @var{d}. |
|
63 ## @itemize @bullet |
3502
|
64 ## @item The leading block @math{D11} of @var{d} is ignored. |
3430
|
65 ## @item If @var{inname} and @var{outname} are not given as arguments, |
|
66 ## the new inputs and outputs are be assigned default names. |
|
67 ## @item @var{yd} is a binary vector of length rows(c) that indicates |
|
68 ## continuous/sampled outputs. Default value for @var{yd} is: |
5016
|
69 ## @itemize @minus |
|
70 ## @item @var{sys} is continuous or mixed |
3430
|
71 ## @var{yd} = @code{zeros(1,rows(c))} |
|
72 ## |
5016
|
73 ## @item @var{sys} is discrete |
3430
|
74 ## @var{yd} = @code{ones(1,rows(c))} |
|
75 ## @end itemize |
5016
|
76 ## @end itemize |
|
77 ## @end table |
3430
|
78 ## @end deftypefn |
|
79 |
|
80 ## Author: John Ingram <ingraje@eng.auburn.edu> |
|
81 ## Created: August 1996 |
|
82 |
|
83 function retsys = sysappend (sys, b, c, d, outname, inname, yd) |
|
84 |
5568
|
85 ## check input arguments |
|
86 if ( (nargin < 2) | (nargin > 7) | (!isstruct(sys))) |
6046
|
87 print_usage (); |
5568
|
88 elseif(!isstruct(sys)) |
|
89 error("sys must be a system data structure"); |
|
90 endif |
3430
|
91 |
5568
|
92 ## default system type must be state space form |
|
93 [Aa,Ab,Ac,Ad,Ats,Ann,Anz,Ast,Ain,Aout,Ayd] = sys2ss(sys); |
|
94 [Ann,Anz,Am,Ap] = sysdimensions(sys); |
3430
|
95 |
5568
|
96 ## default c |
|
97 if(nargin < 3) c = []; endif |
3430
|
98 |
5568
|
99 ## default d |
|
100 if(nargin < 4) make_d = 1; |
|
101 elseif(isempty(d)) make_d = 1; |
|
102 else make_d = 0; endif |
|
103 if(make_d) d = zeros(rows(c)+Ap,columns(b) + Am); endif |
3430
|
104 |
5568
|
105 ## Append new input(s) if any |
|
106 Bm = max(columns(d),columns(b)+Am); |
|
107 if(Bm != Am) |
|
108 ## construct new signal names |
|
109 if(nargin >= 6) # new names were passed |
5443
|
110 if(!ischar(inname)) |
4460
|
111 error("inname must be a string"); |
|
112 elseif(rows(inname) != (Bm - Am)) |
|
113 error(sprintf("%d new inputs requested; inname(%dx%d)", ... |
|
114 (Bm-Am),rows(inname),columns(inname))); |
|
115 endif |
5568
|
116 else |
4460
|
117 inname = __sysdefioname__(Bm,"u",(Am+1)); |
5568
|
118 endif |
4771
|
119 |
5568
|
120 if(Am) |
|
121 Ain = __sysconcat__(Ain,inname); |
|
122 else |
|
123 Ain = inname; |
|
124 endif |
3430
|
125 |
5568
|
126 ## default b matrix |
|
127 if(isempty(b)) b = zeros(Ann+Anz,(Bm-Am)); |
|
128 elseif(rows(b) != Ann+Anz | columns(b) != (Bm-Am)) |
4460
|
129 error(sprintf("b(%dx%d); should be (%dx%d)", rows(b), columns(b), ... |
|
130 (Ann+Anz), (Bm-Am))); |
3430
|
131 endif |
|
132 |
5568
|
133 ## append new b matrix |
|
134 Ab = [Ab,b]; |
|
135 endif |
3430
|
136 |
5568
|
137 ## Append new output(s) if any |
|
138 Bp = max(rows(d),rows(c)+Ap); |
|
139 if(Bp != Ap) |
|
140 |
|
141 ## construct new signal names, output classification |
|
142 if(nargin >= 5) # new names were passed |
5443
|
143 if(!ischar(outname)) |
4460
|
144 error("outname must be a string"); |
|
145 elseif(rows(outname) != (Bp - Ap)) |
|
146 error(sprintf("%d new outputs requested; outname(%dx%d)", ... |
|
147 (Bp-Ap),rows(outname),columns(outname))); |
|
148 endif |
5568
|
149 else |
4460
|
150 outname = __sysdefioname__(Bp,"y",(Ap+1)); |
5568
|
151 endif |
|
152 if(Ap) Aout = __sysconcat__(Aout,outname); |
|
153 else Aout = outname; endif |
3430
|
154 |
5568
|
155 ## construct new yd entries |
|
156 if(nargin == 7) |
4460
|
157 if(!isvector(yd)) |
|
158 error(sprintf("yd(%dx%d) must be a vector",rows(yd),columns(yd))) |
|
159 elseif(rows(c) != length(yd) & rows(d) != length(yd)) |
|
160 error(sprintf("length(yd) = %d; c(%dx%d), d(%dx%d); mismatch", ... |
|
161 length(yd), rows(c), columns(c),rows(d),columns(d))); |
|
162 endif |
5568
|
163 else |
4460
|
164 ## default yd values |
|
165 yd = ones(1,Bp)*( (Ats > 0) & (Ann == 0) & isempty(find(Ayd == 0)) ) ; |
5568
|
166 endif |
|
167 Ayd = [vec(Ayd);vec(yd)]; |
3430
|
168 |
5568
|
169 ## default c matrix |
|
170 if(isempty(c)) c = zeros((Bp-Ap),Ann+Anz); |
|
171 elseif(columns(c) != Ann+Anz | rows(c) != (Bp-Ap)) |
4460
|
172 error(sprintf("c(%dx%d); should be (%dx%d)", rows(c), columns(c), ... |
|
173 (Bp-Ap), (Ann+Anz) )); |
3430
|
174 endif |
|
175 |
5568
|
176 ## append new c matrix |
|
177 Ac = [Ac;c]; |
|
178 endif |
3430
|
179 |
5568
|
180 ## check d matrix |
|
181 if(isempty(d)) d = zeros(Bp,Bm); |
|
182 elseif(rows(d) != Bp | columns(d) != Bm) |
|
183 error(sprintf("d(%dx%d) should be (%dx%d)",rows(d), columns(d), Bp, Bp)); |
|
184 endif |
3430
|
185 |
5568
|
186 ## Splice in original D matrix |
|
187 if(Am & Ap) d(1:Ap, 1:Am) = Ad; endif |
|
188 Ad = d; |
3430
|
189 |
5568
|
190 ## construct return system |
|
191 retsys = ss(Aa,Ab,Ac,Ad,Ats,Ann,Anz,Ast,Ain,Aout,find(Ayd == 1)); |
3430
|
192 |
|
193 endfunction |