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