comparison scripts/control/ss2sys.m @ 3425:8625164a0a39

[project @ 2000-01-13 08:31:37 by jwe]
author jwe
date Thu, 13 Jan 2000 08:32:16 +0000
parents 9610d364e444
children e098ebb77023
comparison
equal deleted inserted replaced
3424:61e40232a4e8 3425:8625164a0a39
1 ## Copyright (C) 1996, 1998 Auburn University. All rights reserved. 1 ## Copyright (C) 1996, 1998 Auburn University. All rights reserved.
2 ## 2 ##
3 ## This file is part of Octave. 3 ## This file is part of Octave.
4 ## 4 ##
5 ## Octave is free software; you can redistribute it and/or modify it 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 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 7 ## Free Software Foundation; either version 2, or (at your option) any
8 ## later version. 8 ## later version.
9 ## 9 ##
10 ## Octave is distributed in the hope that it will be useful, but WITHOUT 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 11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 ## for more details. 13 ## for more details.
14 ## 14 ##
15 ## You should have received a copy of the GNU General Public License 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 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. 17 ## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {Function File } { @var{sys} =} ss2sys (@var{a},@var{b},@var{c}@{,@var{d}, @var{tsam}, @var{n}, @var{nz}, @var{stname}, @var{inname}, @var{outname}, @var{outlist}@}) 20 ## @deftypefn {Function File} {@var{sys} =} ss2sys (@var{a}, @var{b}, @var{c}@{,@var{d}, @var{tsam}, @var{n}, @var{nz}, @var{stname}, @var{inname}, @var{outname}, @var{outlist}@})
21 ## Create system structure from state-space data. May be continous, 21 ## Create system structure from state-space data. May be continous,
22 ## discrete, or mixed (sampeled-data) 22 ## discrete, or mixed (sampeled-data)
23 ## 23 ##
24 ## @strong{Inputs} 24 ## @strong{Inputs}
25 ## @table @var 25 ## @table @var
26 ## @item a 26 ## @item a
27 ## @itemx b 27 ## @itemx b
28 ## @itemx c 28 ## @itemx c
29 ## @itemx d 29 ## @itemx d
30 ## usual state space matrices. 30 ## usual state space matrices.
31 ## 31 ##
32 ## default: @var{d} = zero matrix 32 ## default: @var{d} = zero matrix
33 ## 33 ##
34 ## @item tsam 34 ## @item tsam
35 ## sampling rate. Default: @math{tsam = 0} (continuous system) 35 ## sampling rate. Default: @math{tsam = 0} (continuous system)
36 ## 36 ##
37 ## @item n 37 ## @item n
38 ## @itemx nz 38 ## @itemx nz
39 ## number of continuous, discrete states in the system 39 ## number of continuous, discrete states in the system
40 ## 40 ##
41 ## If @var{tsam} is 0, @math{n = @code{rows}(@var{a})}, @math{nz = 0}. 41 ## If @var{tsam} is 0, @math{n = @code{rows}(@var{a})}, @math{nz = 0}.
42 ## 42 ##
43 ## If @var{tsam} is greater than zero, @math{n = 0}, 43 ## If @var{tsam} is greater than zero, @math{n = 0},
44 ## @math{nz = @code{rows}(@var{a})} 44 ## @math{nz = @code{rows}(@var{a})}
45 ## 45 ##
46 ## see below for system partitioning 46 ## see below for system partitioning
47 ## 47 ##
48 ## @item stname 48 ## @item stname
49 ## list of strings of state signal names 49 ## list of strings of state signal names
50 ## 50 ##
51 ## default (@var{stname}=[] on input): @code{x_n} for continuous states, 51 ## default (@var{stname}=[] on input): @code{x_n} for continuous states,
52 ## @code{xd_n} for discrete states 52 ## @code{xd_n} for discrete states
53 ## 53 ##
54 ## @item inname 54 ## @item inname
55 ## list of strings of input signal names 55 ## list of strings of input signal names
56 ## 56 ##
57 ## default (@var{inname} = [] on input): @code{u_n} 57 ## default (@var{inname} = [] on input): @code{u_n}
58 ## 58 ##
59 ## @item outname 59 ## @item outname
60 ## list of strings of input signal names 60 ## list of strings of input signal names
61 ## 61 ##
62 ## default (@var{outname} = [] on input): @code{y_n} 62 ## default (@var{outname} = [] on input): @code{y_n}
63 ## 63 ##
64 ## @item outlist 64 ## @item outlist
65 ## 65 ##
66 ## list of indices of outputs y that are sampled 66 ## list of indices of outputs y that are sampled
67 ## 67 ##
68 ## If @var{tsam} is 0, @math{outlist = []}. 68 ## If @var{tsam} is 0, @math{outlist = []}.
69 ## 69 ##
70 ## If @var{tsam} is greater than 0, @math{outlist = 1:@code{rows}(@var{c})}. 70 ## If @var{tsam} is greater than 0, @math{outlist = 1:@code{rows}(@var{c})}.
71 ## @end table 71 ## @end table
72 ## 72 ##
73 ## Unlike states, discrete/continous outputs may appear in any order. 73 ## Unlike states, discrete/continous outputs may appear in any order.
74 ## 74 ##
75 ## @strong{Note} @code{sys2ss} returns a vector @var{yd} where 75 ## @strong{Note} @code{sys2ss} returns a vector @var{yd} where
76 ## @var{yd}(@var{outlist}) = 1; all other entries of @var{yd} are 0. 76 ## @var{yd}(@var{outlist}) = 1; all other entries of @var{yd} are 0.
77 ## 77 ##
78 ## @strong{Outputs} 78 ## @strong{Outputs}
79 ## @var{outsys} = system data structure 79 ## @var{outsys} = system data structure
80 ## 80 ##
81 ## @strong{System partitioning} 81 ## @strong{System partitioning}
82 ## 82 ##
83 ## Suppose for simplicity that outlist specified 83 ## Suppose for simplicity that outlist specified
84 ## that the first several outputs were continuous and the remaining outputs 84 ## that the first several outputs were continuous and the remaining outputs
85 ## were discrete. Then the system is partitioned as 85 ## were discrete. Then the system is partitioned as
86 ## @example 86 ## @example
87 ## @group 87 ## @group
88 ## x = [ xc ] (n x 1) 88 ## x = [ xc ] (n x 1)
89 ## [ xd ] (nz x 1 discrete states) 89 ## [ xd ] (nz x 1 discrete states)
90 ## a = [ acc acd ] b = [ bc ] 90 ## a = [ acc acd ] b = [ bc ]
91 ## [ adc add ] [ bd ] 91 ## [ adc add ] [ bd ]
92 ## c = [ ccc ccd ] d = [ dc ] 92 ## c = [ ccc ccd ] d = [ dc ]
93 ## [ cdc cdd ] [ dd ] 93 ## [ cdc cdd ] [ dd ]
94 ## 94 ##
95 ## (cdc = c(outlist,1:n), etc.) 95 ## (cdc = c(outlist,1:n), etc.)
96 ## @end group 96 ## @end group
97 ## @end example 97 ## @end example
98 ## with dynamic equations: 98 ## with dynamic equations:
99 ## @ifinfo 99 ## @ifinfo
100 ## @math{ d/dt xc(t) = acc*xc(t) + acd*xd(k*tsam) + bc*u(t)} 100 ## @math{ d/dt xc(t) = acc*xc(t) + acd*xd(k*tsam) + bc*u(t)}
101 ## 101 ##
102 ## @math{ xd((k+1)*tsam) = adc*xc(k*tsam) + add*xd(k*tsam) + bd*u(k*tsam)} 102 ## @math{ xd((k+1)*tsam) = adc*xc(k*tsam) + add*xd(k*tsam) + bd*u(k*tsam)}
103 ## 103 ##
104 ## @math{ yc(t) = ccc*xc(t) + ccd*xd(k*tsam) + dc*u(t)} 104 ## @math{ yc(t) = ccc*xc(t) + ccd*xd(k*tsam) + dc*u(t)}
105 ## 105 ##
106 ## @math{ yd(k*tsam) = cdc*xc(k*tsam) + cdd*xd(k*tsam) + dd*u(k*tsam)} 106 ## @math{ yd(k*tsam) = cdc*xc(k*tsam) + cdd*xd(k*tsam) + dd*u(k*tsam)}
107 ## @end ifinfo 107 ## @end ifinfo
108 ## @iftex 108 ## @iftex
109 ## @tex 109 ## @tex
110 ## $$\eqalign{ 110 ## $$\eqalign{
111 ## {d \over dt} x_c(t) 111 ## {d \over dt} x_c(t)
112 ## & = a_{cc} x_c(t) + a_{cd} x_d(k*t_{sam}) + bc*u(t) \cr 112 ## & = a_{cc} x_c(t) + a_{cd} x_d(k*t_{sam}) + bc*u(t) \cr
113 ## x_d((k+1)*t_{sam}) 113 ## x_d((k+1)*t_{sam})
114 ## & = a_{dc} x_c(k t_{sam}) + a_{dd} x_d(k t_{sam}) + b_d u(k t_{sam}) \cr 114 ## & = a_{dc} x_c(k t_{sam}) + a_{dd} x_d(k t_{sam}) + b_d u(k t_{sam}) \cr
115 ## y_c(t) 115 ## y_c(t)
116 ## & = c_{cc} x_c(t) + c_{cd} x_d(k t_{sam}) + d_c u(t) \cr 116 ## & = c_{cc} x_c(t) + c_{cd} x_d(k t_{sam}) + d_c u(t) \cr
117 ## y_d(k t_{sam}) 117 ## y_d(k t_{sam})
118 ## & = c_{dc} x_c(k t_{sam}) + c_{dd} x_d(k t_{sam}) + d_d u(k t_{sam}) 118 ## & = c_{dc} x_c(k t_{sam}) + c_{dd} x_d(k t_{sam}) + d_d u(k t_{sam})
119 ## }$$ 119 ## }$$
120 ## @end tex 120 ## @end tex
121 ## @end iftex 121 ## @end iftex
122 ## 122 ##
123 ## @strong{Signal partitions} 123 ## @strong{Signal partitions}
124 ## @example 124 ## @example
125 ## @group 125 ## @group
126 ## | continuous | discrete | 126 ## | continuous | discrete |
127 ## ---------------------------------------------------- 127 ## ----------------------------------------------------
129 ## ---------------------------------------------------- 129 ## ----------------------------------------------------
130 ## outputs | outname(cout,:) | outname(outlist,:) | 130 ## outputs | outname(cout,:) | outname(outlist,:) |
131 ## ---------------------------------------------------- 131 ## ----------------------------------------------------
132 ## @end group 132 ## @end group
133 ## @end example 133 ## @end example
134 ## where @math{cout} is the list of in 1:@code{rows}(@var{p}) 134 ## where @math{cout} is the list of in 1:@code{rows}(@var{p})
135 ## that are not contained in outlist. (Discrete/continuous outputs 135 ## that are not contained in outlist. (Discrete/continuous outputs
136 ## may be entered in any order desired by the user.) 136 ## may be entered in any order desired by the user.)
137 ## 137 ##
138 ## @strong{Example} 138 ## @strong{Example}
139 ## @example 139 ## @example
140 ## octave:1> a = [1 2 3; 4 5 6; 7 8 10]; 140 ## octave:1> a = [1 2 3; 4 5 6; 7 8 10];
141 ## octave:2> b = [0 0 ; 0 1 ; 1 0]; 141 ## octave:2> b = [0 0 ; 0 1 ; 1 0];
142 ## octave:3> c = eye(3); 142 ## octave:3> c = eye(3);
143 ## octave:4> sys = ss2sys(a,b,c,[],0,3,0,list("volts","amps","joules")); 143 ## octave:4> sys = ss2sys(a,b,c,[],0,3,0,list("volts","amps","joules"));
144 ## octave:5> sysout(sys); 144 ## octave:5> sysout(sys);
145 ## Input(s) 145 ## Input(s)
146 ## 1: u_1 146 ## 1: u_1
147 ## 2: u_2 147 ## 2: u_2
148 ## 148 ##
149 ## Output(s): 149 ## Output(s):
150 ## 1: y_1 150 ## 1: y_1
151 ## 2: y_2 151 ## 2: y_2
152 ## 3: y_3 152 ## 3: y_3
153 ## 153 ##
154 ## state-space form: 154 ## state-space form:
155 ## 3 continuous states, 0 discrete states 155 ## 3 continuous states, 0 discrete states
156 ## State(s): 156 ## State(s):
157 ## 1: volts 157 ## 1: volts
158 ## 2: amps 158 ## 2: amps
159 ## 3: joules 159 ## 3: joules
160 ## 160 ##
161 ## A matrix: 3 x 3 161 ## A matrix: 3 x 3
162 ## 1 2 3 162 ## 1 2 3
163 ## 4 5 6 163 ## 4 5 6
164 ## 7 8 10 164 ## 7 8 10
165 ## B matrix: 3 x 2 165 ## B matrix: 3 x 2
173 ## D matrix: 3 x 3 173 ## D matrix: 3 x 3
174 ## 0 0 174 ## 0 0
175 ## 0 0 175 ## 0 0
176 ## 0 0 176 ## 0 0
177 ## @end example 177 ## @end example
178 ## Notice that the @var{D} matrix is constructed by default to the 178 ## Notice that the @var{D} matrix is constructed by default to the
179 ## correct dimensions. Default input and output signals names were assigned 179 ## correct dimensions. Default input and output signals names were assigned
180 ## since none were given. 180 ## since none were given.
181 ##
182 ## @end deftypefn 181 ## @end deftypefn
183 182
184 ## Author: John Ingram <ingraje@eng.auburn.edu> 183 ## Author: John Ingram <ingraje@eng.auburn.edu>
185 ## Created: July 20, 1996 184 ## Created: July 20, 1996
186 185
218 elseif((!is_matrix(n)) | isstr(n)) 217 elseif((!is_matrix(n)) | isstr(n))
219 error("Parameter n is not a numerical value."); 218 error("Parameter n is not a numerical value.");
220 elseif( (!is_scalar(n)) | (n < 0 ) | (n != round(n)) ) 219 elseif( (!is_scalar(n)) | (n < 0 ) | (n != round(n)) )
221 if(is_scalar(n)) error("illegal value of n=%d,%e",n,n); 220 if(is_scalar(n)) error("illegal value of n=%d,%e",n,n);
222 else error("illegal value of n=(%dx%d)", ... 221 else error("illegal value of n=(%dx%d)", ...
223 rows(n), columns(n)); endif 222 rows(n), columns(n)); endif
224 endif 223 endif
225 224
226 ## check for num discrete states 225 ## check for num discrete states
227 if( (nargin < 7) & (tsam == 0)) nz = 0; 226 if( (nargin < 7) & (tsam == 0)) nz = 0;
228 elseif(nargin < 7) nz = na - n; 227 elseif(nargin < 7) nz = na - n;
229 elseif((!is_matrix(nz)) | isstr(nz)) 228 elseif((!is_matrix(nz)) | isstr(nz))
230 error("Parameter nz is not a numerical value."); 229 error("Parameter nz is not a numerical value.");
231 elseif( (!is_scalar(nz)) | (nz < 0 ) | (nz != round(nz)) ) 230 elseif( (!is_scalar(nz)) | (nz < 0 ) | (nz != round(nz)) )
232 if(is_scalar(nz)) 231 if(is_scalar(nz))
233 error(["illegal value of nz=",num2str(nz)]); 232 error(["illegal value of nz=",num2str(nz)]);
234 else 233 else
235 error(["illegal value of nz=(",num2str(rows(nz)),"x", ... 234 error(["illegal value of nz=(",num2str(rows(nz)),"x", ...
236 num2str(columns(nz)),")"]); 235 num2str(columns(nz)),")"]);
237 endif 236 endif
238 endif 237 endif
239 238
240 ## check for total number of states 239 ## check for total number of states
241 if( (n + nz) != na ) 240 if( (n + nz) != na )
242 error(["Illegal: a is ",num2str(na),"x",num2str(na),", n=", ... 241 error(["Illegal: a is ",num2str(na),"x",num2str(na),", n=", ...
243 num2str(n),", nz=",num2str(nz)]); 242 num2str(n),", nz=",num2str(nz)]);
244 endif 243 endif
245 244
246 ## construct system with default names 245 ## construct system with default names
247 retsys.a = a; 246 retsys.a = a;
248 retsys.b = b; 247 retsys.b = b;
249 retsys.c = c; 248 retsys.c = c;
250 retsys.d = d; 249 retsys.d = d;
251 250
252 retsys.n = n; 251 retsys.n = n;
253 retsys.nz = nz; 252 retsys.nz = nz;
254 retsys.tsam = tsam; 253 retsys.tsam = tsam;
255 retsys.yd = zeros(1,p); # default value entered below 254 retsys.yd = zeros(1,p); # default value entered below
256 255
257 ## Set the system vector: active = 2(ss), updated = [0 0 1]; 256 ## Set the system vector: active = 2(ss), updated = [0 0 1];
258 retsys.sys = [2, 0, 0, 1]; 257 retsys.sys = [2, 0, 0, 1];
259 258
260 retsys.stname = sysdefstname(n,nz); 259 retsys.stname = sysdefstname(n,nz);
261 retsys.inname = sysdefioname(m,"u"); 260 retsys.inname = sysdefioname(m,"u");
262 retsys.outname = sysdefioname(p,"y"); 261 retsys.outname = sysdefioname(p,"y");
263 262
278 277
279 ## set up yd 278 ## set up yd
280 if(nargin < 11) 279 if(nargin < 11)
281 retsys = syssetsignals(retsys,"yd",ones(1,p)*(tsam > 0)); 280 retsys = syssetsignals(retsys,"yd",ones(1,p)*(tsam > 0));
282 else 281 else
283 if(!isempty(outlist)) 282 if(!isempty(outlist))
284 retsys = syssetsignals(retsys,"yd",ones(size(outlist)),outlist); 283 retsys = syssetsignals(retsys,"yd",ones(size(outlist)),outlist);
285 endif 284 endif
286 endif 285 endif
287 286
288 endfunction 287 endfunction