Mercurial > hg > octave-lyh
comparison scripts/control/system/sysscale.m @ 3430:65b3519ac3a1
[project @ 2000-01-14 03:44:03 by jwe]
author | jwe |
---|---|
date | Fri, 14 Jan 2000 03:50:02 +0000 |
parents | |
children | 2e06c3941943 |
comparison
equal
deleted
inserted
replaced
3429:b9f5829ec843 | 3430:65b3519ac3a1 |
---|---|
1 ## Copyright (C) 1996, 1998 Auburn University. All rights reserved. | |
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, 59 Temple Place, Suite 330, Boston, MA 02111 USA. | |
18 | |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {@var{sys} =} sysscale (@var{sys}, @var{outscale}, @var{inscale}@{, @var{outname}, @var{inname}@}) | |
21 ## scale inputs/outputs of a system. | |
22 ## | |
23 ## @strong{Inputs} | |
24 ## sys: structured system | |
25 ## outscale, inscale: constant matrices of appropriate dimension | |
26 ## | |
27 ## @strong{Outputs} | |
28 ## @var{sys}: resulting open loop system: | |
29 ## @example | |
30 ## ----------- ------- ----------- | |
31 ## u --->| inscale |--->| sys |--->| outscale |---> y | |
32 ## ----------- ------- ----------- | |
33 ## @end example | |
34 ## If the input names and output names (each a list of strings) | |
35 ## are not given and the scaling matrices | |
36 ## are not square, then default names will be given to the inputs and/or | |
37 ## outputs. | |
38 ## | |
39 ## A warning message is printed if outscale attempts to add continuous | |
40 ## system outputs to discrete system outputs; otherwise @var{yd} is | |
41 ## set appropriately in the returned value of @var{sys}. | |
42 ## @end deftypefn | |
43 | |
44 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> | |
45 ## Created: August 1995 | |
46 ## modified by John Ingram 7-15-96 | |
47 | |
48 function sys = sysscale (sys, outscale, inscale, outname, inname) | |
49 | |
50 if( (nargin < 3) || (nargin > 5) ) | |
51 usage("retsys = sysscale(Asys,output_list,input_list{,inname,outname})"); | |
52 elseif (!is_struct(sys)) | |
53 error("sys must be a structured system"); | |
54 endif | |
55 | |
56 [nn,nz,mm,pp] = sysdimensions(sys); | |
57 | |
58 ## check for omitted scales | |
59 if(isempty(outscale)) outscale = eye(pp); endif | |
60 if(isempty(inscale)) inscale = eye(mm); endif | |
61 | |
62 ## check dimensions of scaling matrices | |
63 if(mm!=rows(inscale)) | |
64 error("inscale(%dx%d) should have %d rows(# system inputs)", ... | |
65 rows(inscale),columns(inscale),mm); | |
66 elseif( pp != columns(outscale) ) | |
67 error("outscale(%dx%d) should have %d columns(# system outputs)", ... | |
68 rows(outscale), columns(outscale),pp); | |
69 endif | |
70 | |
71 sysyd = sysgetsignals(sys,"yd"); | |
72 outc = find(sysyd==0); | |
73 outd = find(sysyd==1); | |
74 | |
75 if(length(outc) & length(outd)) | |
76 for ii = 1:rows(outscale) | |
77 nci = norm(outscale(ii,outc)); | |
78 ndi = norm(outscale(ii,outd)); | |
79 | |
80 if( nci & ndi) | |
81 warning("sysscale: outscale(%d,:) sums continuous and discrete outputs; setting output to cont",ii) | |
82 sysyd(ii) = 0; | |
83 else | |
84 sysyd(ii) = (ndi != 0); | |
85 endif | |
86 endfor | |
87 else | |
88 sysyd = ones(1,rows(outscale))*( length(outd) > 0); | |
89 endif | |
90 | |
91 ## check for SISO system type | |
92 if strcmp(sysgettype(sys),"tf") | |
93 [num,den,tsam,innam,outnam] = sys2tf(sys); | |
94 num = num*inscale*outscale; | |
95 sys = tf2sys(num,den,tsam,innam,outnam,find(sysyd)); | |
96 return | |
97 elseif strcmp(sysgettype(sys),"zp") | |
98 [zer,pol,kk,tsam,innam,outnam] = sys2zp(sys); | |
99 kk = kk*inscale*outscale; | |
100 sys = zp2sys(zer,pol,k,tsam,innam,outnam,find(sysyd)); | |
101 return | |
102 endif | |
103 | |
104 ## it's a state space system... | |
105 | |
106 [sysa,sysb,sysc,sysd,systsam, ... | |
107 sysn,sysnz,sysstname,sysinname,sysoutname,oldyd] = sys2ss(sys); | |
108 | |
109 sysb = sysb*inscale; | |
110 sysc = outscale*sysc; | |
111 sysd = outscale*sysd*inscale; | |
112 | |
113 if( !is_square(outscale) ) | |
114 ## strip extra output names (if any) | |
115 sysoutname = sysoutname(1:min(rows(outscale),columns(outscale))); | |
116 if( nargin < 4) | |
117 warning("sysscale: outscale not square, outname not specified"); | |
118 warning("sysscale: using default output names"); | |
119 outname = sysdefioname(rows(sysc),"y"); | |
120 endif | |
121 else | |
122 outname = sysoutname; | |
123 endif | |
124 if( !is_square(inscale) ) | |
125 ## strip extra output names (if any) | |
126 sysinname = sysinname(1:min(rows(inscale),columns(inscale))); | |
127 if(nargin < 5) | |
128 warning("sysscale: inscale not square, inname not specified"); | |
129 warning("sysscale: using default input names"); | |
130 inname = sysdefioname(columns(sysb),"u"); | |
131 endif | |
132 else | |
133 inname = sysgetsignals(sys,"in"); | |
134 endif | |
135 | |
136 sys = ss2sys(sysa,sysb,sysc,sysd,systsam,nn,nz,sysstname, ... | |
137 inname,outname,find(sysyd==1)); | |
138 | |
139 endfunction |