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