annotate scripts/control/system/sysgroup.m @ 3979:e0b7a493e5a8

[project @ 2002-07-10 17:45:34 by jwe]
author jwe
date Wed, 10 Jul 2002 17:45:34 +0000
parents b5238ac1dca9
children 22bd65326ec1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 1996, 1998, 1999 Auburn University. All rights reserved.
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
2 ##
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
4 ##
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by the
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
7 ## Free Software Foundation; either version 2, or (at your option) any
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
8 ## later version.
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
9 ##
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but WITHOUT
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
13 ## for more details.
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
14 ##
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, write to the Free
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
17 ## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
18
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
20 ## @deftypefn {Function File} {} sysgroup (@var{asys}, @var{bsys})
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
21 ## Combines two systems into a single system
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
22 ##
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
23 ## @strong{Inputs}
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
24 ## @var{asys}, @var{bsys}: system data structures
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
25 ##
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
26 ## @strong{Outputs}
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
27 ## @math{sys = @r{block diag}(asys,bsys)}
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
28 ## @example
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
29 ## @group
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
30 ## __________________
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
31 ## | ________ |
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
32 ## u1 ----->|--> | asys |--->|----> y1
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
33 ## | -------- |
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
34 ## | ________ |
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
35 ## u2 ----->|--> | bsys |--->|----> y2
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
36 ## | -------- |
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
37 ## ------------------
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
38 ## Ksys
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
39 ## @end group
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
40 ## @end example
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
41 ## The function also rearranges the internal state-space realization of @var{sys}
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
42 ## so that the
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
43 ## continuous states come first and the discrete states come last.
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
44 ## If there are duplicate names, the second name has a unique suffix appended
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
45 ## on to the end of the name.
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
46 ## @end deftypefn
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
47
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
48 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu>
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
49 ## Created: August 1995
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
50 ## modified by John Ingram July 1996
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
51 ## A. S. Hodel: modified for variable number of arguments 1999
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
52
3979
e0b7a493e5a8 [project @ 2002-07-10 17:45:34 by jwe]
jwe
parents: 3502
diff changeset
53 function sys = sysgroup (varargin)
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
54
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
55 save_emp = empty_list_elements_ok;
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
56 empty_list_elements_ok = 1;
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
57
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
58 if(nargin < 1)
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
59 usage("sys = sysgroup(Asys{,Bsys,...})");
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
60 endif
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
61
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
62 ## collect all arguments
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
63 arglist = list();
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
64 for kk=1:nargin
3979
e0b7a493e5a8 [project @ 2002-07-10 17:45:34 by jwe]
jwe
parents: 3502
diff changeset
65 arglist(kk) = varargin{kk};
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
66 if(!is_struct(nth(arglist,kk)))
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
67 error("sysgroup: argument %d is not a data structure",kk);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
68 endif
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
69 endfor
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
70
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
71 if(nargin == 2)
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
72 ## the usual case; group the two systems together
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
73 Asys = nth(arglist,1);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
74 Bsys = nth(arglist,2);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
75
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
76 ## extract information from Asys, Bsys to consruct sys
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
77 Asys = sysupdate(Asys,"ss");
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
78 Bsys = sysupdate(Bsys,"ss");
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
79 [n1,nz1,m1,p1] = sysdimensions(Asys);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
80 [n2,nz2,m2,p2] = sysdimensions(Bsys);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
81 [Aa,Ab,Ac,Ad,Atsam,An,Anz,Ast,Ain,Aout,Ayd] = sys2ss(Asys);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
82 [Ba,Bb,Bc,Bd,Btsam,Bn,Bnz,Bst,Bin,Bout,Byd] = sys2ss(Bsys);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
83 nA = An + Anz;
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
84 nB = Bn + Bnz;
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
85
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
86 if(p1*m1*p2*m2 == 0)
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
87 error("sysgroup: argument lacks inputs and/or outputs");
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
88
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
89 elseif((Atsam + Btsam > 0) & (Atsam * Btsam == 0) )
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
90 warning("sysgroup: creating combination of continuous and discrete systems")
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
91
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
92 elseif(Atsam != Btsam)
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
93 error("sysgroup: Asys.tsam=%e, Bsys.tsam =%e", Atsam, Btsam);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
94 endif
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
95
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
96 A = [Aa,zeros(nA,nB); zeros(nB,nA),Ba];
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
97 B = [Ab,zeros(nA,m2); zeros(nB,m1),Bb];
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
98 C = [Ac,zeros(p1,nB); zeros(p2,nA),Bc];
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
99 D = [Ad,zeros(p1,m2); zeros(p2,m1),Bd];
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
100 tsam = max(Atsam,Btsam);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
101
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
102 ## construct combined signal names; stnames must check for pure gain blocks
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
103 if(isempty(Ast))
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
104 stname = Bst;
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
105 elseif(isempty(Bst))
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
106 stname = Ast;
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
107 else
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
108 stname = append(Ast, Bst);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
109 endif
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
110 inname = append(Ain, Bin);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
111 outname = append(Aout,Bout);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
112
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
113 ## Sort states into continous first, then discrete
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
114 dstates = ones(1,(nA+nB));
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
115 if(An)
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
116 dstates(1:(An)) = zeros(1,An);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
117 endif
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
118 if(Bn)
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
119 dstates((nA+1):(nA+Bn)) = zeros(1,Bn);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
120 endif
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
121 [tmp,pv] = sort(dstates);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
122 A = A(pv,pv);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
123 B = B(pv,:);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
124 C = C(:,pv);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
125 stname = stname(pv);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
126
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
127 ## check for duplicate signal names
3438
2e06c3941943 [project @ 2000-01-14 06:33:18 by jwe]
jwe
parents: 3430
diff changeset
128 inname = __sysgroupn__ (inname, "input");
2e06c3941943 [project @ 2000-01-14 06:33:18 by jwe]
jwe
parents: 3430
diff changeset
129 stname = __sysgroupn__ (stname, "state");
2e06c3941943 [project @ 2000-01-14 06:33:18 by jwe]
jwe
parents: 3430
diff changeset
130 outname = __sysgroupn__ (outname, "output");
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
131
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
132 ## mark discrete outputs
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
133 outlist = find([Ayd, Byd]);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
134
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
135 ## build new system
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
136 sys = ss2sys(A,B,C,D,tsam,An+Bn,Anz+Bnz,stname,inname,outname);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
137
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
138 else
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
139 ## multiple systems (or a single system); combine together one by one
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
140 sys = nth(arglist,1);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
141 for kk=2:length(arglist)
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
142 printf("sysgroup: kk=%d\n",kk);
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
143 sys = sysgroup(sys,nth(arglist,kk));
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
144 endfor
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
145 endif
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
146
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
147 empty_list_elements_ok = save_emp;
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
148
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
149 endfunction