3279
|
1 # Copyright (C) 1996,1998 Auburn University. All Rights Reserved. |
3213
|
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 |
3284
|
17 # Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. |
3213
|
18 |
|
19 function retsys = sysdup(Asys,output_list,input_list) |
|
20 # function retsys = sysdup(Asys,output_list,input_list) |
|
21 # Duplicate specified input/output connections of a system |
|
22 # |
|
23 # |
|
24 # inputs: |
|
25 # Asys: system data structure (see ss2sys) |
|
26 # output_list,input_list: list of connections indices; |
|
27 # duplicates are made of y(output_list(ii)) and u(input_list(ii)). |
|
28 # output: retsys: resulting closed loop system: |
|
29 # duplicated i/o names are appended with a "+" suffix. |
|
30 # |
|
31 # Operation: sysdup creates copies of selected inputs and outputs as |
|
32 # shown below. u1/y1 is the set of original inputs/outputs, and |
|
33 # u2,y2 is the set of duplicated inputs/outputs in the order specified |
|
34 # in input_list,output_list, respectively |
|
35 # ____________________ |
|
36 # | | |
|
37 # u1 ----->| |----> y1 |
|
38 # | Asys | |
|
39 # | | |
|
40 # u2 ------------->| |----->y2 |
|
41 # (input_list) | | (output_list) |
|
42 # -------------------- |
|
43 |
|
44 # A. S. Hodel August 1995 |
|
45 # modified by John Ingram July 1996 |
|
46 |
|
47 save_val = implicit_str_to_num_ok; # save for later |
|
48 implicit_str_to_num_ok = 1; |
|
49 |
|
50 if( nargin != 3) |
|
51 usage("retsys = sysdup(Asys,output_list,input_list)"); |
|
52 endif |
|
53 |
|
54 if( !is_struct(Asys)) |
|
55 error("Asys must be a system data structure (see ss2sys, tf2sys, or zp2sys)") |
|
56 endif |
|
57 |
3228
|
58 Asys = sysupdate(Asys,"ss"); |
|
59 [nn,nz,mm,pp] = sysdimensions(Asys); |
|
60 [aa,bb,cc,dd] = sys2ss(Asys); |
3213
|
61 |
|
62 # first duplicate inputs |
|
63 if(is_vector(input_list)) |
|
64 for ii=1:length(input_list); |
3228
|
65 bb(:,mm+ii) = bb(:,input_list(ii)); |
|
66 dd(:,mm+ii) = dd(:,input_list(ii)); |
3213
|
67 end |
|
68 elseif(!isempty(input_list)) |
|
69 error("input_list must be a vector or empty"); |
|
70 endif |
|
71 |
|
72 |
|
73 # now duplicate outputs |
|
74 osize = min(size(output_list)); |
|
75 if(osize == 1) |
|
76 for ii=1:length(output_list); |
3228
|
77 cc(pp+ii,:) = cc(output_list(ii),:); |
|
78 dd(pp+ii,:) = dd(output_list(ii),:); |
3213
|
79 end |
|
80 elseif(osize != 0) |
|
81 error("output_list must be a vector or empty"); |
|
82 endif |
|
83 |
3228
|
84 [stnam,innam,outnam,yd] = sysgetsignals(Asys); |
|
85 tsam = sysgettsam(Asys); |
3213
|
86 |
3228
|
87 # pack system and then rename signals |
|
88 retsys = ss2sys(aa,bb,cc,dd,tsam,nn,nz); |
|
89 retsys = syssetsignals(retsys,"in",innam,1:mm); |
|
90 retsys = syssetsignals(retsys,"out",outnam,1:pp); |
|
91 retsys = syssetsignals(retsys,"yd",yd,1:pp); |
3213
|
92 |
3228
|
93 # update added input names |
|
94 for ii=(mm+1):(mm+length(input_list)) |
|
95 onum = input_list(ii-mm); |
|
96 strval = sprintf("%s(dup)",sysgetsignals(retsys,"in",onum,1) ); |
|
97 retsys = syssetsignals(retsys,"in",strval,ii); |
3213
|
98 endfor |
|
99 |
3228
|
100 # update added output names/discrete flags |
3213
|
101 # give default names to the added outputs |
|
102 for jj=(pp+1):(pp+length(output_list)) |
3228
|
103 onum = output_list(jj-pp); |
|
104 strval = sprintf("%s(dup)",sysgetsignals(retsys,"out",onum,1) ); |
|
105 retsys = syssetsignals(retsys,"out",strval,jj); |
|
106 dflg = sysgetsignals(retsys,"yd",onum); |
|
107 retsys = syssetsignals(retsys,"yd",dflg,jj); |
3213
|
108 endfor |
|
109 |
|
110 implicit_str_to_num_ok = save_val; # restore value |
|
111 |
|
112 endfunction |