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