comparison scripts/control/system/sysappend.m @ 4460:cef48c4b902d

[project @ 2003-07-11 18:37:48 by jwe]
author jwe
date Fri, 11 Jul 2003 18:37:48 +0000
parents 22bd65326ec1
children b8105302cfe8
comparison
equal deleted inserted replaced
4459:75ee1995d2b4 4460:cef48c4b902d
75 ## Author: John Ingram <ingraje@eng.auburn.edu> 75 ## Author: John Ingram <ingraje@eng.auburn.edu>
76 ## Created: August 1996 76 ## Created: August 1996
77 77
78 function retsys = sysappend (sys, b, c, d, outname, inname, yd) 78 function retsys = sysappend (sys, b, c, d, outname, inname, yd)
79 79
80 sav_empty_list_elements_ok = empty_list_elements_ok; 80 save_warn_empty_list_elements = warn_empty_list_elements;
81 unwind_protect
82 warn_empty_list_elements = 0;
81 83
82 empty_list_elements_ok = 1; 84 ## check input arguments
83 85 if ( (nargin < 2) | (nargin > 7) | (!isstruct(sys)))
84 ## check input arguments 86 usage("retsys = sysappend(sys,b,c[,d,outname,inname,yd]) ");
85 if ( (nargin < 2) | (nargin > 7) | (!isstruct(sys))) 87 elseif(!isstruct(sys))
86 usage("retsys = sysappend(sys,b,c[,d,outname,inname,yd]) "); 88 error("sys must be a system data structure");
87 elseif(!isstruct(sys))
88 error("sys must be a system data structure");
89 endif
90
91 ## default system type must be state space form
92 [Aa,Ab,Ac,Ad,Ats,Ann,Anz,Ast,Ain,Aout,Ayd] = sys2ss(sys);
93 [Ann,Anz,Am,Ap] = sysdimensions(sys);
94
95 ## default c
96 if(nargin < 3) c = []; endif
97
98 ## default d
99 if(nargin < 4) make_d = 1;
100 elseif(isempty(d)) make_d = 1;
101 else make_d = 0; endif
102 if(make_d) d = zeros(rows(c)+Ap,columns(b) + Am); endif
103
104 ## Append new input(s) if any
105 Bm = max(columns(d),columns(b)+Am);
106 if(Bm != Am)
107 ## construct new signal names
108 if(nargin >= 6) # new names were passed
109 if(!isstr(inname))
110 error("inname must be a string");
111 elseif(rows(inname) != (Bm - Am))
112 error(sprintf("%d new inputs requested; inname(%dx%d)", ...
113 (Bm-Am),rows(inname),columns(inname)));
114 endif
115 else
116 inname = __sysdefioname__(Bm,"u",(Am+1));
117 endif
118 if(Am) Ain = append(Ain,inname);
119 else Ain = inname; endif
120
121 ## default b matrix
122 if(isempty(b)) b = zeros(Ann+Anz,(Bm-Am));
123 elseif(rows(b) != Ann+Anz | columns(b) != (Bm-Am))
124 error(sprintf("b(%dx%d); should be (%dx%d)", rows(b), columns(b), ...
125 (Ann+Anz), (Bm-Am)));
126 endif 89 endif
127 90
128 ## append new b matrix 91 ## default system type must be state space form
129 Ab = [Ab,b]; # empty_list_elements_ok=1 makes this ok 92 [Aa,Ab,Ac,Ad,Ats,Ann,Anz,Ast,Ain,Aout,Ayd] = sys2ss(sys);
130 endif 93 [Ann,Anz,Am,Ap] = sysdimensions(sys);
131 94
132 ## Append new output(s) if any 95 ## default c
133 Bp = max(rows(d),rows(c)+Ap); 96 if(nargin < 3) c = []; endif
134 if(Bp != Ap)
135 97
136 ## construct new signal names, output classification 98 ## default d
137 if(nargin >= 5) # new names were passed 99 if(nargin < 4) make_d = 1;
138 if(!isstr(outname)) 100 elseif(isempty(d)) make_d = 1;
139 error("outname must be a string"); 101 else make_d = 0; endif
140 elseif(rows(outname) != (Bp - Ap)) 102 if(make_d) d = zeros(rows(c)+Ap,columns(b) + Am); endif
141 error(sprintf("%d new outputs requested; outname(%dx%d)", ... 103
142 (Bp-Ap),rows(outname),columns(outname))); 104 ## Append new input(s) if any
105 Bm = max(columns(d),columns(b)+Am);
106 if(Bm != Am)
107 ## construct new signal names
108 if(nargin >= 6) # new names were passed
109 if(!isstr(inname))
110 error("inname must be a string");
111 elseif(rows(inname) != (Bm - Am))
112 error(sprintf("%d new inputs requested; inname(%dx%d)", ...
113 (Bm-Am),rows(inname),columns(inname)));
114 endif
115 else
116 inname = __sysdefioname__(Bm,"u",(Am+1));
143 endif 117 endif
144 else 118 if(Am) Ain = append(Ain,inname);
145 outname = __sysdefioname__(Bp,"y",(Ap+1)); 119 else Ain = inname; endif
146 endif
147 if(Ap) Aout = append(Aout,outname);
148 else Aout = outname; endif
149 120
150 ## construct new yd entries 121 ## default b matrix
151 if(nargin == 7) 122 if(isempty(b)) b = zeros(Ann+Anz,(Bm-Am));
152 if(!isvector(yd)) 123 elseif(rows(b) != Ann+Anz | columns(b) != (Bm-Am))
153 error(sprintf("yd(%dx%d) must be a vector",rows(yd),columns(yd))) 124 error(sprintf("b(%dx%d); should be (%dx%d)", rows(b), columns(b), ...
154 elseif(rows(c) != length(yd) & rows(d) != length(yd)) 125 (Ann+Anz), (Bm-Am)));
155 error(sprintf("length(yd) = %d; c(%dx%d), d(%dx%d); mismatch", ...
156 length(yd), rows(c), columns(c),rows(d),columns(d)));
157 endif 126 endif
158 else
159 ## default yd values
160 yd = ones(1,Bp)*( (Ats > 0) & (Ann == 0) & isempty(find(Ayd == 0)) ) ;
161 endif
162 Ayd = [vec(Ayd);vec(yd)];
163 127
164 ## default c matrix 128 ## append new b matrix
165 if(isempty(c)) c = zeros((Bp-Ap),Ann+Anz); 129 Ab = [Ab,b];
166 elseif(columns(c) != Ann+Anz | rows(c) != (Bp-Ap))
167 error(sprintf("c(%dx%d); should be (%dx%d)", rows(c), columns(c), ...
168 (Bp-Ap), (Ann+Anz) ));
169 endif 130 endif
170 131
171 ## append new c matrix 132 ## Append new output(s) if any
172 Ac = [Ac;c]; # empty_list_elements_ok=1 makes this ok 133 Bp = max(rows(d),rows(c)+Ap);
173 endif 134 if(Bp != Ap)
174 135
175 ## check d matrix 136 ## construct new signal names, output classification
176 if(isempty(d)) d = zeros(Bp,Bm); 137 if(nargin >= 5) # new names were passed
177 elseif(rows(d) != Bp | columns(d) != Bm) 138 if(!isstr(outname))
178 error(sprintf("d(%dx%d) should be (%dx%d)",rows(d), columns(d), Bp, Bp)); 139 error("outname must be a string");
179 endif 140 elseif(rows(outname) != (Bp - Ap))
141 error(sprintf("%d new outputs requested; outname(%dx%d)", ...
142 (Bp-Ap),rows(outname),columns(outname)));
143 endif
144 else
145 outname = __sysdefioname__(Bp,"y",(Ap+1));
146 endif
147 if(Ap) Aout = append(Aout,outname);
148 else Aout = outname; endif
180 149
181 ## Splice in original D matrix 150 ## construct new yd entries
182 if(Am & Ap) d(1:Ap, 1:Am) = Ad; endif 151 if(nargin == 7)
183 Ad = d; 152 if(!isvector(yd))
153 error(sprintf("yd(%dx%d) must be a vector",rows(yd),columns(yd)))
154 elseif(rows(c) != length(yd) & rows(d) != length(yd))
155 error(sprintf("length(yd) = %d; c(%dx%d), d(%dx%d); mismatch", ...
156 length(yd), rows(c), columns(c),rows(d),columns(d)));
157 endif
158 else
159 ## default yd values
160 yd = ones(1,Bp)*( (Ats > 0) & (Ann == 0) & isempty(find(Ayd == 0)) ) ;
161 endif
162 Ayd = [vec(Ayd);vec(yd)];
184 163
185 ## construct return system 164 ## default c matrix
186 retsys = ss2sys(Aa,Ab,Ac,Ad,Ats,Ann,Anz,Ast,Ain,Aout,find(Ayd == 1)); 165 if(isempty(c)) c = zeros((Bp-Ap),Ann+Anz);
166 elseif(columns(c) != Ann+Anz | rows(c) != (Bp-Ap))
167 error(sprintf("c(%dx%d); should be (%dx%d)", rows(c), columns(c), ...
168 (Bp-Ap), (Ann+Anz) ));
169 endif
187 170
188 empty_list_elements_ok = sav_empty_list_elements_ok; 171 ## append new c matrix
172 Ac = [Ac;c];
173 endif
174
175 ## check d matrix
176 if(isempty(d)) d = zeros(Bp,Bm);
177 elseif(rows(d) != Bp | columns(d) != Bm)
178 error(sprintf("d(%dx%d) should be (%dx%d)",rows(d), columns(d), Bp, Bp));
179 endif
180
181 ## Splice in original D matrix
182 if(Am & Ap) d(1:Ap, 1:Am) = Ad; endif
183 Ad = d;
184
185 ## construct return system
186 retsys = ss2sys(Aa,Ab,Ac,Ad,Ats,Ann,Anz,Ast,Ain,Aout,find(Ayd == 1));
187
188 unwind_protect_cleanup
189 warn_empty_list_elements = save_warn_empty_list_elements;
190 end_unwind_protect
189 191
190 endfunction 192 endfunction