annotate scripts/control/hinf_ctr.m @ 3385:10f21f7ccc7f

[project @ 1999-12-15 22:28:26 by jwe]
author jwe
date Wed, 15 Dec 1999 22:28:52 +0000
parents 69b167451491
children 1a8e2c0d627a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
1 ## Copyright (C) 1996 Auburn University. All Rights Reserved
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
2 ##
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
3 ## This file is part of Octave.
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
4 ##
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
6 ## under the terms of the GNU General Public License as published by the
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
7 ## Free Software Foundation; either version 2, or (at your option) any
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
8 ## later version.
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
9 ##
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but WITHOUT
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
13 ## for more details.
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
14 ##
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
15 ## You should have received a copy of the GNU General Public License
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
16 ## along with Octave; see the file COPYING. If not, write to the Free
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
17 ## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
3346
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
18
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
19 ## -*- texinfo -*-
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
20 ## @deftypefn {Function File } {@var{K} =} hinf_ctr(@var{dgs}, @var{F}, @var{H}, @var{Z}, @var{g})
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
21 ## Called by @code{hinfsyn} to compute the H_inf optimal controller.
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
22 ##
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
23 ## @strong{Inputs}
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
24 ## @table @var
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
25 ## @item dgs
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
26 ## data structure returned by @code{is_dgkf}
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
27 ## @item F, H
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
28 ## feedback and filter gain (not partitioned)
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
29 ## @item g
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
30 ## final gamma value
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
31 ## @end table
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
32 ## @strong{Outputs}
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
33 ## controller K (system data structure)
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
34 ##
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
35 ## Do not attempt to use this at home; no argument checking performed.
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
36 ## @end deftypefn
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
37
3385
10f21f7ccc7f [project @ 1999-12-15 22:28:26 by jwe]
jwe
parents: 3381
diff changeset
38 function K = hinf_ctr (dgs, F, H, Z, g)
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
39
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
40 ## A. S. Hodel August 1995
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
41 ## Revised by Kai P Mueller April 1998 to solve the general H_infinity
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
42 ## problem using unitary transformations Q (on w and z)
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
43 ## and non-singular transformations R (on u and y).
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
44
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
45 nw = dgs.nw;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
46 nu = dgs.nu;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
47 nz = dgs.nz;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
48 ny = dgs.ny;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
49 d22nz = dgs.Dyu_nz;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
50
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
51 B1 = dgs.Bw;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
52 B2 = dgs.Bu;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
53 C1 = dgs.Cz;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
54 C2 = dgs.Cy;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
55 C = [C1; C2];
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
56 D11 = dgs.Dzw;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
57 D12 = dgs.Dzu;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
58 D21 = dgs.Dyw;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
59 D22 = dgs.Dyu;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
60 A = dgs.A;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
61 Ru = dgs.Ru;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
62 Ry = dgs.Ry;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
63
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
64 nout = nz + ny;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
65 nin = nw + nu;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
66 nstates = size(A, 1);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
67
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
68 F11 = F(1:(nw-ny),:);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
69 F12 = F((nw-ny+1):nw,:);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
70 F2 = F((nw+1):nin,:);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
71 H11 = H(:,1:(nz-nu));
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
72 H12 = H(:,(nz-nu+1):nz);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
73 H2 = H(:,(nz+1):nout);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
74
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
75 ## D11 partitions
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
76 D1111 = D11(1:(nz-nu),1:(nw-ny));
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
77 D1112 = D11(1:(nz-nu),(nw-ny+1):nw);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
78 D1121 = D11((nz-nu+1):nz,1:(nw-ny));
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
79 D1122 = D11((nz-nu+1):nz,(nw-ny+1):nw);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
80
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
81 ## D11ik may be the empty matrix, don't calculate with empty matrices
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
82 [nd1111,md1111] = size(D1111);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
83 md1112 = length(D1112);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
84 md1121 = length(D1121);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
85
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
86 if ((nd1111 == 0) || (md1112 == 0))
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
87 d11hat = -D1122;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
88 else
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
89 xx = inv(g*g*eye(nz-nu) - D1111*D1111');
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
90 d11hat = -D1121*D1111'*xx*D1112 - D1122;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
91 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
92 if (md1112 == 0)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
93 d21hat = eye(ny);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
94 elseif (nd1111 == 0)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
95 d21hat = chol(eye(ny) - D1112'*D1112/g/g);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
96 else
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
97 xx = inv(g*g*eye(nz-nu) - D1111*D1111');
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
98 xx = eye(ny) - D1112'*xx*D1112;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
99 d21hat = chol(xx);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
100 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
101 if (md1121 == 0)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
102 d12hat = eye(nu);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
103 elseif (md1111 == 0)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
104 d12hat = chol(eye(nu) - D1121*D1121'/g/g)';
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
105 else
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
106 xx = inv(g*g*eye(nw-ny) - D1111'*D1111);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
107 xx = eye(nu)-D1121*xx*D1121';
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
108 d12hat = chol(xx)';
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
109 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
110
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
111 b2hat = (B2+H12)*d12hat;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
112 c2hat = -d21hat*(C2+F12)*Z;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
113 b1hat = -H2 + (b2hat/d12hat)*d11hat;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
114 c1hat = F2*Z + (d11hat/d21hat)*c2hat;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
115 ahat = A + H*C + (b2hat/d12hat)*c1hat;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
116
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
117 ## rescale controller by Ru and Ry
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
118 b1hat = b1hat/Ry;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
119 c1hat = Ru\c1hat;
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3236
diff changeset
120 bhat = [b1hat, b2hat];
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
121 chat = [c1hat; c2hat];
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3236
diff changeset
122 dhat = [Ru\d11hat/Ry, Ru\d12hat; d21hat/Ry, 0*d11hat'];
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
123
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
124 ## non-zero D22 is a special case
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
125 if (d22nz)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
126 if (rank(eye(nu) + d11hat*D22) < nu)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
127 error(" *** cannot compute controller for D22 non-zero.");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
128 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
129
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3236
diff changeset
130 d22new = [D22, zeros(ny,ny); zeros(nu,nu), 0*D22'];
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
131 xx = inv(eye(nu+ny) + d22new*dhat);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
132 mhat = inv(eye(nu+ny) + dhat*d22new);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
133 ahat = ahat - bhat*((eye(nu+ny)-xx)/dhat)*chat;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
134 bhat = bhat*xx;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
135 chat = mhat*chat;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
136 dhat = dhat*xx;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
137
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
138 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
139
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
140 K = ss2sys(ahat,bhat(:,1:ny),chat(1:nu,:),dhat(1:nu,1:ny));
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
141
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
142 endfunction