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{retsys} =} sysdup (@var{asys}, @var{out_idx}, @var{in_idx}) |
3430
|
21 ## Duplicate specified input/output connections of a system |
|
22 ## |
|
23 ## @strong{Inputs} |
|
24 ## @table @var |
3502
|
25 ## @item asys |
3439
|
26 ## system data structure |
3430
|
27 ## @item out_idx |
|
28 ## @itemx in_idx |
3462
|
29 ## indices or names of desired signals (see @code{sigidx}). |
3430
|
30 ## duplicates are made of @code{y(out_idx(ii))} and @code{u(in_idx(ii))}. |
|
31 ## @end table |
|
32 ## |
5016
|
33 ## @strong{Output} |
|
34 ## @table @var |
|
35 ## @item retsys |
|
36 ## Resulting closed loop system: |
3430
|
37 ## duplicated i/o names are appended with a @code{"+"} suffix. |
5016
|
38 ## @end table |
3430
|
39 ## |
|
40 ## @strong{Method} |
5016
|
41 ## |
3430
|
42 ## @code{sysdup} creates copies of selected inputs and outputs as |
5016
|
43 ## shown below. @var{u1}, @var{y1} is the set of original inputs/outputs, and |
|
44 ## @var{u2}, @var{y2} is the set of duplicated inputs/outputs in the order |
|
45 ## specified in @var{in_idx}, @var{out_idx}, respectively |
3430
|
46 ## @example |
|
47 ## @group |
|
48 ## ____________________ |
|
49 ## u1 ----->| |----> y1 |
3502
|
50 ## | asys | |
3430
|
51 ## u2 ------>| |----->y2 |
5016
|
52 ## (in_idx) -------------------- (out_idx) |
3430
|
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 ## modified by John Ingram July 1996 |
|
60 |
|
61 function retsys = sysdup (Asys, output_list, input_list) |
|
62 |
|
63 if( nargin != 3) |
|
64 usage("retsys = sysdup(Asys,output_list,input_list)"); |
|
65 endif |
|
66 |
4030
|
67 if( !isstruct(Asys)) |
4771
|
68 error("Asys must be a system data structure (see ss, tf, or zp)") |
3430
|
69 endif |
|
70 |
|
71 Asys = sysupdate(Asys,"ss"); |
|
72 [nn,nz,mm,pp] = sysdimensions(Asys); |
|
73 [aa,bb,cc,dd] = sys2ss(Asys); |
|
74 |
3462
|
75 ## check for signal names |
|
76 if(is_signal_list(input_list) | isstr(input_list)) |
|
77 input_list = sysidx(Asys,"in",input_list); |
|
78 endif |
|
79 if(is_signal_list(output_list) | isstr(output_list)) |
|
80 output_list = sysidx(Asys,"out",output_list); |
|
81 endif |
|
82 |
3430
|
83 ## first duplicate inputs |
4030
|
84 if(isvector(input_list)) |
3430
|
85 for ii=1:length(input_list); |
|
86 bb(:,mm+ii) = bb(:,input_list(ii)); |
|
87 dd(:,mm+ii) = dd(:,input_list(ii)); |
|
88 end |
|
89 elseif(!isempty(input_list)) |
|
90 error("input_list must be a vector or empty"); |
|
91 endif |
|
92 |
|
93 |
|
94 ## now duplicate outputs |
|
95 osize = min(size(output_list)); |
|
96 if(osize == 1) |
|
97 for ii=1:length(output_list); |
|
98 cc(pp+ii,:) = cc(output_list(ii),:); |
|
99 dd(pp+ii,:) = dd(output_list(ii),:); |
|
100 end |
|
101 elseif(osize != 0) |
|
102 error("output_list must be a vector or empty"); |
|
103 endif |
|
104 |
|
105 [stnam,innam,outnam,yd] = sysgetsignals(Asys); |
|
106 tsam = sysgettsam(Asys); |
|
107 |
|
108 ## pack system and then rename signals |
4771
|
109 retsys = ss(aa,bb,cc,dd,tsam,nn,nz); |
3430
|
110 retsys = syssetsignals(retsys,"in",innam,1:mm); |
|
111 retsys = syssetsignals(retsys,"out",outnam,1:pp); |
|
112 retsys = syssetsignals(retsys,"yd",yd,1:pp); |
|
113 |
|
114 ## update added input names |
|
115 for ii=(mm+1):(mm+length(input_list)) |
|
116 onum = input_list(ii-mm); |
|
117 strval = sprintf("%s(dup)",sysgetsignals(retsys,"in",onum,1) ); |
|
118 retsys = syssetsignals(retsys,"in",strval,ii); |
|
119 endfor |
|
120 |
|
121 ## update added output names/discrete flags |
|
122 ## give default names to the added outputs |
|
123 for jj=(pp+1):(pp+length(output_list)) |
|
124 onum = output_list(jj-pp); |
|
125 strval = sprintf("%s(dup)",sysgetsignals(retsys,"out",onum,1) ); |
|
126 retsys = syssetsignals(retsys,"out",strval,jj); |
|
127 dflg = sysgetsignals(retsys,"yd",onum); |
|
128 retsys = syssetsignals(retsys,"yd",dflg,jj); |
|
129 endfor |
|
130 |
|
131 endfunction |