3430
|
1 ## Copyright (C) 1996, 1998 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} =} 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 |
4460
|
85 save_warn_empty_list_elements = warn_empty_list_elements; |
|
86 unwind_protect |
|
87 warn_empty_list_elements = 0; |
3430
|
88 |
4460
|
89 ## check input arguments |
|
90 if ( (nargin < 2) | (nargin > 7) | (!isstruct(sys))) |
|
91 usage("retsys = sysappend(sys,b,c[,d,outname,inname,yd]) "); |
|
92 elseif(!isstruct(sys)) |
|
93 error("sys must be a system data structure"); |
|
94 endif |
3430
|
95 |
4460
|
96 ## default system type must be state space form |
|
97 [Aa,Ab,Ac,Ad,Ats,Ann,Anz,Ast,Ain,Aout,Ayd] = sys2ss(sys); |
|
98 [Ann,Anz,Am,Ap] = sysdimensions(sys); |
3430
|
99 |
4460
|
100 ## default c |
|
101 if(nargin < 3) c = []; endif |
3430
|
102 |
4460
|
103 ## default d |
|
104 if(nargin < 4) make_d = 1; |
|
105 elseif(isempty(d)) make_d = 1; |
|
106 else make_d = 0; endif |
|
107 if(make_d) d = zeros(rows(c)+Ap,columns(b) + Am); endif |
3430
|
108 |
4460
|
109 ## Append new input(s) if any |
|
110 Bm = max(columns(d),columns(b)+Am); |
|
111 if(Bm != Am) |
|
112 ## construct new signal names |
|
113 if(nargin >= 6) # new names were passed |
5443
|
114 if(!ischar(inname)) |
4460
|
115 error("inname must be a string"); |
|
116 elseif(rows(inname) != (Bm - Am)) |
|
117 error(sprintf("%d new inputs requested; inname(%dx%d)", ... |
|
118 (Bm-Am),rows(inname),columns(inname))); |
|
119 endif |
|
120 else |
|
121 inname = __sysdefioname__(Bm,"u",(Am+1)); |
|
122 endif |
4771
|
123 |
|
124 if(Am) |
|
125 Ain = __sysconcat__(Ain,inname); |
|
126 else |
|
127 Ain = inname; |
|
128 endif |
3430
|
129 |
4460
|
130 ## default b matrix |
|
131 if(isempty(b)) b = zeros(Ann+Anz,(Bm-Am)); |
|
132 elseif(rows(b) != Ann+Anz | columns(b) != (Bm-Am)) |
|
133 error(sprintf("b(%dx%d); should be (%dx%d)", rows(b), columns(b), ... |
|
134 (Ann+Anz), (Bm-Am))); |
3430
|
135 endif |
|
136 |
4460
|
137 ## append new b matrix |
|
138 Ab = [Ab,b]; |
3430
|
139 endif |
|
140 |
4460
|
141 ## Append new output(s) if any |
|
142 Bp = max(rows(d),rows(c)+Ap); |
|
143 if(Bp != Ap) |
3430
|
144 |
4460
|
145 ## construct new signal names, output classification |
|
146 if(nargin >= 5) # new names were passed |
5443
|
147 if(!ischar(outname)) |
4460
|
148 error("outname must be a string"); |
|
149 elseif(rows(outname) != (Bp - Ap)) |
|
150 error(sprintf("%d new outputs requested; outname(%dx%d)", ... |
|
151 (Bp-Ap),rows(outname),columns(outname))); |
|
152 endif |
|
153 else |
|
154 outname = __sysdefioname__(Bp,"y",(Ap+1)); |
3430
|
155 endif |
4771
|
156 if(Ap) Aout = __sysconcat__(Aout,outname); |
4460
|
157 else Aout = outname; endif |
3430
|
158 |
4460
|
159 ## construct new yd entries |
|
160 if(nargin == 7) |
|
161 if(!isvector(yd)) |
|
162 error(sprintf("yd(%dx%d) must be a vector",rows(yd),columns(yd))) |
|
163 elseif(rows(c) != length(yd) & rows(d) != length(yd)) |
|
164 error(sprintf("length(yd) = %d; c(%dx%d), d(%dx%d); mismatch", ... |
|
165 length(yd), rows(c), columns(c),rows(d),columns(d))); |
|
166 endif |
|
167 else |
|
168 ## default yd values |
|
169 yd = ones(1,Bp)*( (Ats > 0) & (Ann == 0) & isempty(find(Ayd == 0)) ) ; |
3430
|
170 endif |
4460
|
171 Ayd = [vec(Ayd);vec(yd)]; |
3430
|
172 |
4460
|
173 ## default c matrix |
|
174 if(isempty(c)) c = zeros((Bp-Ap),Ann+Anz); |
|
175 elseif(columns(c) != Ann+Anz | rows(c) != (Bp-Ap)) |
|
176 error(sprintf("c(%dx%d); should be (%dx%d)", rows(c), columns(c), ... |
|
177 (Bp-Ap), (Ann+Anz) )); |
|
178 endif |
|
179 |
|
180 ## append new c matrix |
|
181 Ac = [Ac;c]; |
3430
|
182 endif |
|
183 |
4460
|
184 ## check d matrix |
|
185 if(isempty(d)) d = zeros(Bp,Bm); |
|
186 elseif(rows(d) != Bp | columns(d) != Bm) |
|
187 error(sprintf("d(%dx%d) should be (%dx%d)",rows(d), columns(d), Bp, Bp)); |
|
188 endif |
3430
|
189 |
4460
|
190 ## Splice in original D matrix |
|
191 if(Am & Ap) d(1:Ap, 1:Am) = Ad; endif |
|
192 Ad = d; |
3430
|
193 |
4460
|
194 ## construct return system |
4771
|
195 retsys = ss(Aa,Ab,Ac,Ad,Ats,Ann,Anz,Ast,Ain,Aout,find(Ayd == 1)); |
3430
|
196 |
4460
|
197 unwind_protect_cleanup |
|
198 warn_empty_list_elements = save_warn_empty_list_elements; |
|
199 end_unwind_protect |
3430
|
200 |
|
201 endfunction |