3213
|
1 # Copyright (C) 1996 A. Scottedward Hodel |
|
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, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
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 # $Revision: 1.2 $ |
|
47 |
|
48 save_val = implicit_str_to_num_ok; # save for later |
|
49 implicit_str_to_num_ok = 1; |
|
50 |
|
51 if( nargin != 3) |
|
52 usage("retsys = sysdup(Asys,output_list,input_list)"); |
|
53 endif |
|
54 |
|
55 if( !is_struct(Asys)) |
|
56 error("Asys must be a system data structure (see ss2sys, tf2sys, or zp2sys)") |
|
57 endif |
|
58 |
|
59 if (Asys.sys(4) != 1) |
|
60 Asys = sysupdate(Asys,'ss'); |
|
61 endif |
|
62 |
|
63 mm = rows(Asys.inname); |
|
64 pp = rows(Asys.outname); |
|
65 |
|
66 # first duplicate inputs |
|
67 if(is_vector(input_list)) |
|
68 for ii=1:length(input_list); |
|
69 Asys.b(:,mm+ii) = Asys.b(:,input_list(ii)); |
|
70 Asys.d(:,mm+ii) = Asys.d(:,input_list(ii)); |
|
71 end |
|
72 elseif(!isempty(input_list)) |
|
73 error("input_list must be a vector or empty"); |
|
74 endif |
|
75 |
|
76 |
|
77 # now duplicate outputs |
|
78 osize = min(size(output_list)); |
|
79 if(osize == 1) |
|
80 for ii=1:length(output_list); |
|
81 Asys.c(pp+ii,:) = Asys.c(output_list(ii),:); |
|
82 Asys.d(pp+ii,:) = Asys.d(output_list(ii),:); |
|
83 end |
|
84 elseif(osize != 0) |
|
85 error("output_list must be a vector or empty"); |
|
86 endif |
|
87 |
|
88 yd = Asys.yd(output_list); |
|
89 Asys.yd = [Asys.yd yd]; |
|
90 |
|
91 # give default names to the added inputs |
|
92 for ii=(mm+1):(mm+length(input_list)) |
|
93 orig_name = Asys.inname(input_list(ii-mm),:); |
|
94 |
|
95 #disp("sysdup: orig_name=") |
|
96 #orig_name |
|
97 #disp("/sysdup") |
|
98 |
|
99 strval = [dezero(orig_name),"(dup)"]; |
|
100 |
|
101 #disp("sysdup: strval=") |
|
102 #strval |
|
103 #disp("/sysdup") |
|
104 |
|
105 Asys.inname(ii,1:length(strval)) = [strval]; |
|
106 |
|
107 #disp("sysdup: resulting Asys.inname:") |
|
108 #Asys.inname |
|
109 #disp("/sysdup"); |
|
110 |
|
111 endfor |
|
112 |
|
113 # give default names to the added outputs |
|
114 for jj=(pp+1):(pp+length(output_list)) |
|
115 if(isstr(Asys.outname)) |
|
116 orig_name =Asys.outname; |
|
117 else |
|
118 orig_name = Asys.outname(output_list(jj-pp),:); |
|
119 endif |
|
120 strval = [dezero(orig_name),"(dup)"]; |
|
121 Asys.outname(jj,1:length(strval)) = [strval]; |
|
122 |
|
123 endfor |
|
124 |
|
125 |
|
126 |
|
127 if(max(size(Asys.d)) > 1 ) |
|
128 Asys.sys = [2 0 0 1]; # change default form to state space |
|
129 # tf and zp are no longer relevant |
|
130 endif |
|
131 |
|
132 retsys = Asys; |
|
133 |
|
134 implicit_str_to_num_ok = save_val; # restore value |
|
135 |
|
136 endfunction |