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