7017
|
1 ## Copyright (C) 1996, 1998, 2000, 2002, 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{retsys} =} sysprune (@var{asys}, @var{out_idx}, @var{in_idx}) |
3430
|
22 ## Extract specified inputs/outputs from a system |
|
23 ## |
|
24 ## @strong{Inputs} |
|
25 ## @table @var |
3502
|
26 ## @item asys |
3430
|
27 ## system data structure |
|
28 ## @item out_idx |
|
29 ## @itemx in_idx |
3455
|
30 ## Indices or signal names of the outputs and inputs to be kept in the returned |
5016
|
31 ## system; remaining connections are ``pruned'' off. |
3430
|
32 ## May select as [] (empty matrix) to specify all outputs/inputs. |
3455
|
33 ## |
|
34 ## @example |
4855
|
35 ## retsys = sysprune (Asys, [1:3,4], "u_1"); |
|
36 ## retsys = sysprune (Asys, @{"tx", "ty", "tz"@}, 4); |
3455
|
37 ## @end example |
|
38 ## |
3430
|
39 ## @end table |
|
40 ## |
5016
|
41 ## @strong{Output} |
|
42 ## @table @var |
|
43 ## @item retsys |
|
44 ## Resulting system. |
|
45 ## @end table |
3430
|
46 ## @example |
|
47 ## @group |
|
48 ## ____________________ |
|
49 ## u1 ------->| |----> y1 |
|
50 ## (in_idx) | Asys | (out_idx) |
|
51 ## u2 ------->| |----| y2 |
|
52 ## (deleted)-------------------- (deleted) |
|
53 ## @end group |
|
54 ## @end example |
|
55 ## @end deftypefn |
|
56 |
|
57 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
58 ## Created: August 1995 |
|
59 ## Updated by John Ingram 7-15-96 |
|
60 |
|
61 function sys = sysprune (sys, output_idx, input_idx, state_idx) |
|
62 |
7135
|
63 if (nargin < 3 || nargin > 4) |
6046
|
64 print_usage (); |
7135
|
65 elseif (nargin < 4) |
3430
|
66 state_idx = []; |
|
67 endif |
|
68 |
|
69 ## default: no action |
7135
|
70 [nn, nz, mm, pp] = sysdimensions (sys); |
|
71 if (isempty (output_idx)) |
|
72 output_idx = 1:pp; |
|
73 endif |
|
74 if (isempty (input_idx)) |
|
75 input_idx = 1:mm; |
|
76 endif |
|
77 if (isempty (state_idx)) |
|
78 state_idx = 1:(nn+nz); |
|
79 endif |
3430
|
80 |
3455
|
81 ## check for signal names |
7135
|
82 if (is_signal_list (output_idx) || ischar (output_idx)) |
|
83 output_idx = sysidx (sys, "out", output_idx); |
3455
|
84 endif |
7135
|
85 if (is_signal_list (input_idx) || ischar (input_idx)) |
|
86 input_idx = sysidx (sys, "in", input_idx); |
3455
|
87 endif |
|
88 |
3430
|
89 ## check dimensions |
7135
|
90 if (! (isvector (output_idx) || isempty (output_idx))) |
|
91 if (! ismatrix (output_idx)) |
|
92 error ("sysprune: bad argument passed for output_idx"); |
3430
|
93 else |
7135
|
94 error ("sysprune: output_idx (%d x %d) must be a vector or empty", |
|
95 rows (output_idx), columns (output_idx)); |
3430
|
96 endif |
7135
|
97 elseif (is_duplicate_entry (output_idx)) |
|
98 error ("sysprune: duplicate entries found in output_idx"); |
3430
|
99 endif |
|
100 |
7135
|
101 if (! (isvector (input_idx) || isempty (input_idx))) |
|
102 if (! ismatrix (input_idx)) |
|
103 error ("sysprune: bad argument passed for input_idx"); |
3430
|
104 else |
7135
|
105 error ("sysprune: input_idx (%d x %d) must be a vector or empty", |
|
106 rows (input_idx), columns(input_idx)); |
3430
|
107 endif |
7135
|
108 elseif (is_duplicate_entry (input_idx)) |
|
109 error ("sysprune: duplicate entries found in input_idx"); |
3430
|
110 endif |
|
111 |
7135
|
112 if (! (isvector (state_idx) || isempty (state_idx))) |
|
113 if (! ismatrix (state_idx)) |
|
114 error ("sysprune: bad argument passed for state_idx"); |
3430
|
115 else |
7135
|
116 error ("sysprune: state_idx (%d x %d) must be a vector or empty", |
|
117 rows (state_idx), columns (state_idx)); |
3430
|
118 endif |
7135
|
119 elseif (nn+nz > 0) |
|
120 if (is_duplicate_entry (state_idx)) |
|
121 error ("sysprune: duplicate entries found in state_idx"); |
3430
|
122 endif |
|
123 endif |
|
124 |
7135
|
125 lo = length (output_idx); |
|
126 li = length (input_idx); |
|
127 lst = length (state_idx); |
3430
|
128 |
7135
|
129 if (! isstruct (sys)) |
|
130 error ("Asys must be a system data structure (see ss, tf, or zp)"); |
|
131 elseif (pp < lo) |
|
132 error("%d output_idx entries, system has only %d outputs", lo, pp]); |
|
133 elseif (mm < li) |
|
134 error("%d input_idx entries, system has only %d inputs", li, mm); |
|
135 elseif (nn+nz < lst) |
|
136 error("%d state_idx entries, system has only %d states", lst, nn+nz); |
3430
|
137 endif |
|
138 |
7135
|
139 [aa, bb, cc, dd, tsam, nn, nz, stnam, innam, outnam, yd] = sys2ss (sys); |
3430
|
140 |
|
141 ## check for valid state permutation |
7135
|
142 if (nn & nz) |
|
143 c_idx = find (state_idx <= nn); |
|
144 if (! isempty (c_idx)) |
|
145 max_c = max (c_idx); |
|
146 else |
|
147 max_c = 0; |
|
148 endif |
|
149 d_idx = find (state_idx > nn); |
|
150 if (! isempty (d_idx)) |
|
151 min_d = min (d_idx); |
|
152 else |
|
153 min_d = nn+nz; |
|
154 endif |
|
155 if (max_c > min_d) |
|
156 warning ("sysprune: state_idx(%d)=%d (discrete) preceeds", |
|
157 min_d, state_idx(min_d)); |
|
158 warning(" state_idx(%d)=%d (continuous)", |
|
159 max_c, state_idx(max_c)); |
|
160 warning ("sysprune: sys has %d continuous states, %d discrete states", |
|
161 nn, nz); |
|
162 error("continuous/discrete state partition not preserved; see ss"); |
3430
|
163 endif |
|
164 endif |
|
165 |
|
166 idx = input_idx; |
|
167 odx = output_idx; |
7135
|
168 if (isempty (state_idx)) |
3430
|
169 idx = []; |
|
170 odx = []; |
|
171 endif |
|
172 aa = aa(state_idx,state_idx); |
|
173 bb = bb(state_idx,idx); |
|
174 cc = cc(odx,state_idx); |
|
175 dd = dd(output_idx,input_idx); |
|
176 yd = yd(output_idx); |
|
177 |
|
178 innam = innam(input_idx); |
|
179 outnam = outnam(output_idx); |
|
180 stnam = stnam(state_idx); |
7135
|
181 nn1 = length (find (state_idx <= nn)); |
|
182 nz1 = length (find (state_idx > nn)); |
|
183 |
|
184 sys = ss (aa, bb, cc, dd, tsam, nn1, nz1, stnam, innam, outnam, find (yd)); |
|
185 |
3430
|
186 endfunction |