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