File: h_inf.sci

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (492 lines) | stat: -rw-r--r-- 12,505 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
function [Sk,rk,mu]=h_inf(P,r,mumin,mumax,nmax)
// H-infinity optimal control for the continuous-time plant P
// P is the plant (linear system)given in state-space form or in transfer form,
// e.g. P=syslin('c',A,B,C,D) with A,B,C,D = scalar matrices
// or P=syslin('c',H) with H a transfer matrix.
// r = size of the P22 plant i.e. 2-vector [#outputs,#inputs];
// mumin,mumax = bounds on mu with mu=1/gama^2; (mumin=0  usually)
// nmax = maximum number of iterations in the gama-iteration.
// Two possible calling sequences:
// [Sk,mu]=h_inf(P,r,mumin,mumax,nmax) returns mu and the central controller 
// Sk in the same representation as P. (All calculations being done in state
// space).
// [Sk,rk,mu]=h_inf(P,r,mumin,mumax,nmax) returns mu 
//            and the parametrization of all stabilizing controllers:
//  a stabilizing controller K is obtained by K=Fl(Sk,r,PHI) where
//  PHI is a linear system with dimensions r' and satisfy h_norm(PHI) < gama. 
//  rk (=r) is the size of the Sk22 block and mu = 1/gama^2 after nmax 
//  iterations.
// Author: F.D. Inria (1990) adapted from Safonov-Limebeer.
//!
//
// Initialization : Uci and Yci normalize P
// mu_inf upper bound on mu = gama^-2
//P2 = normalized P.
//
// Copyright INRIA
P1=P(1);
[P2,mu_inf,Uci,Yci,D22]=h_init(P,r)
if mu_inf < mumax then 
    write(%io(2),mu_inf,'(3x,''romax too big: max romax= '',f10.5)');end
mumax=mini(mu_inf,mumax)
//
//    Gama-iteration P6 = transformed P2 with D11 removed
[P6,Finf,mu,Uc#i,Yc#i]=h_iter(P2,r,mumin,mumax,nmax)
if mu==0 then 
write(%io(2),[mumin,mumax],'(1x,''no feasible ro in bounds: '',2(e10.3,2x))');
rk=[];Sk=[];
return,end
//
//    Optimal controller for P6
[Sk,polesH,polesJ]=h_contr(P6,r,1/mu,Uc#i,Yc#i);
[E,Ak,Bk1,Bk2,Ck1,Ck2,Dk11,Dk12,Dk21,Dk22]=Sk(:);
//    Add the optimal controller at infinity
 if norm(Finf,1) <> 0 then Dk11=Dk11+Finf;end
//    Back-normalization of the controller
Bk1=Bk1*Yci;
Ck1=Uci*Ck1;
Dk11=Uci*Dk11*Yci;
Dk12=Uci*Dk12;
Dk21=Dk21*Yci;
//Convert to descriptor form:
  Sk=des2ss(Ak,[Bk1,Bk2],[Ck1;Ck2],[Dk11,Dk12;Dk21,Dk22],E);
//    Sk in transfer representation if P is.
[LHS,RHS]=argn(0);
if LHS<3 then Sk=Sk(1:r(2),1:r(1));rk=mu;
//    Case D22 different from zero
 if norm(coeff(D22),1) <> 0 then Sk=Sk/.D22;end
   if P1(1)=='r' then Sk=ss2tf(Sk);end;
   return;
end
if LHS==3 then rk=r;
   if P1(1)=='r' then Sk=ss2tf(Sk);end;
end


function [P2,mu_inf,Uci,Yci,D22]=h_init(P,r)
//******************************
// Initialization of the standard plant
// P = standard plant; r=size of P22 (1X2 vector)
// P2 = normalized plant
// gama_inf :lower bound on gama
//
//   [C1 D12]'*[C1 D12] = Q = [Q1 S;S' Q2]
//   [B1;D21] *[B1;D21]'= R = [R1 L';L R2]
//!
P1=P(1);
if P1(1)=='r' then P=tf2ss(P);end
     [A,B1,B2,C1,C2,D11,D12,D21,D22]=smga(P,r);
     [na,na]=size(A);
     [p1,m2]=size(D12),
     [p2,m1]=size(D21),
//Useful indexes
     l1=1:p1-m2;k1=1:m1-p2;
     l2=1+p1-m2:p1;k2=1+m1-p2:m1;

//**************Check assumptions******************

//Stabilizability/detectability of P22 ?

P22=syslin('c',A,B2,C2);
 
[ns,Us,St]=st_ility(P22,1.d-10)
 
if ns<>na then write(%io(2),'Warning: P22 not stabilizable');end
if ns==na then write(%io(2),'P22 is stabilizable');end

[nd,Ud,Sd]=dt_ility(P22,1.d-10)

if nd <> 0 then write(%io(2),'Warning: P22 not detectable');end
if nd==0 then write(%io(2),'P22 is detectable');end

// rank P21=[A,B2,C1,D12] = m2 ?
     P12=syslin('c',A,B2,C1,D12);
     [nt,dt]=trzeros(P12),rzt=real(nt./dt),
     if size(nt,'*') > 0 then
       if mini(abs(rzt)) < sqrt(%eps) then 
     write(%io(2),'Warning P12 has a zero on/close the imaginary axis'),
       end,
     end,

// rank P21=[A,B1,C2,D21] = p2 ?
     P21=syslin('c',A,B1,C2,D21);
     [nt,dt]=trzeros(P21),rzt=real(nt./dt),
     if size(nt,'*')>0 then
        if mini(abs(rzt)) < sqrt(%eps) then 
    write(%io(2),'Warning: P21 has a zero on/close the imaginary axis'),
        end,
     end,

//***********************end***************************

//Row compression of D12 (bottom)
     [T1,r1]=rowcomp(D12),
 if r1<>m2 then error('D12 not full column rank'),end,
     T1=[T1(r1+1:p1,:);T1(1:r1,:)],
     D12=T1*D12,
//Column compression of D21 (right)
     [S1,r2]=colcomp(D21),
 if r2<>p2 then error('D21 not full row rank'),end,
     D21=D21*S1,
//Updating 
     B1=B1*S1,C1=T1*C1,
     D11=T1*D11*S1,

// Scaling on U and Y
     Uc=D12(l2,:);
     Uci=inv(Uc);
     B2=B2*Uci;
     D12=D12*Uci;

     Yc=D21(:,k2)
     Yci=inv(Yc);
     C2=Yci*C2;
     D21=Yci*D21;

//P2=[A,B1,B2,C1,C2,D11,D12,D21,D22] with D12 and D21 scaled;

//Initialization  

//Solve H-infinity problem at infinity

     D1111=D11(l1,k1),
     D1112=D11(l1,k2),
     D1121=D11(l2,k1),
     D1122=D11(l2,k2),

M11=[D1111,D1112];M22=[D1111',D1121'];
g1=-1;g2=-1;
if M11<>[] then g1=norm(M11);end
if M22<>[] then g2=norm(M22);end

gama_inf=maxi(g1,g2);
if gama_inf==0 then mu_inf=1/%eps/%eps, else mu_inf=1/(gama_inf*gama_inf);end

P2=syslin('c',A,[B1,B2],[C1;C2],[D11,D12;D21,0*D22]);

//P2 = standard plant with D22=0 and D12,D21 normalized;


function [P6ad,Finfad,muad,Uc#iad,Yc#iad]=h_iter(P2,r,mumin,mumax,nmax)
niter=0;muad=0;P6ad=[]; Finfad=[];Uc#iad=[];Yc#iad=[];
while niter < nmax
  niter=niter+1;
  mu=(mumin+mumax)/2;
  [P6,Finf,tv,Uc#i,Yc#i]=h_test(P2,r,mu)
  
  test=maxi(tv)

    if test > 0 then
     mumax=mu
     else
     mumin=mu,muad=mu;P6ad=P6;Finfad=Finf;Uc#iad=Uc#i;Yc#iad=Yc#i;
    end

end  //while


function [P6,Kinf,tv,Uc#i,Yc#i]=h_test(P2,r,mu)
//****************************
//To test if mu is feasable for the plant P2 :
//mu is feasible for P2 iff the three components of
//tv are negative
//!
//
//   [C1 D12]*[C1 D12]'=Q=[Q1 S;S' Q2]
//   [B1;D21]*[B1;D21]'=R=[R1 L';L R2]
tv=[1,1,1];
     [A,B1,B2,C1,C2,D11,D12,D21,D22]=smga(P2,r);
     [p1,m2]=size(D12),
     [p2,m1]=size(D21),
//Useful indexes
     l1=1:p1-m2;k1=1:m1-p2;
     l2=1+p1-m2:p1;k2=1+m1-p2:m1;
//

     D1111=D11(l1,k1),
     D1112=D11(l1,k2),
     D1121=D11(l2,k1),
     D1122=D11(l2,k2),

if mu==0 then mu=%eps*%eps;end
mu1=1/mu;
gama=1/sqrt(mu);
gam2=1/(gama*gama);

err=(m1-p2)*(p1-m2);

if err==0 then
   Kinf=-D1122
else
   Kinf=-(D1122+D1121*inv(mu1*eye-D1111'*D1111)*D1111'*D1112);
end

//Kinf=admissible controller for mu

A=A+B2*Kinf*C2;
B1=B1+B2*Kinf*D21;
C1=C1+D12*Kinf*C2;
D11=D11+D12*Kinf*D21;

if norm(D11) >= gama then write(%io(2),'error : gamma too small');
    P6=[]; Kinf=[];Uc#i=[];Yc#i=[];return;end

//P3=list(A,B1,B2,C1,C2,D11,D12,D21,D22) with norm(D11) < gama.

Teta11=gam2*D11;
Teta22=gam2*D11';
W12=eye-gam2*D11*D11';
W21=eye-gam2*D11'*D11;
Teta12=(1/gama)*sqrtm(0.5*(W12+W12'));
Teta21=-(1/gama)*sqrtm(0.5*(W21+W21'));

//Teta*Teta'=(1/gama*gama)*eye

M=inv(eye-D11*Teta22);
N=inv(eye-Teta22*D11);

A=A+B1*Teta22*M*C1;

B2=B2+B1*Teta22*M*D12;
B1=B1*N*Teta21;

C2=C2+D21*Teta22*M*C1;
C1=Teta12*M*C1;

D11=0*D11;     //By construction...

D22#=D22+D21*Teta22*M*D12;

D12=Teta12*M*D12;
D21=D21*N*Teta21;

//P4 =syslin('c',A,[B1,B2],[C1;C2],[D11,D12;D21,D22] 
//          with D11=0; P4=Fl(Teta,size(D11'),P3,r);

D22=0*D22#;

//P5 = [A,[B1,B2],[C1;C2],[D11,D12;D21,D22] with D11=0 and D22=0;

//Row compression of D12
     [T1,r1]=rowcomp(D12);
 if r1<>m2 then error('D12 not full rank! '),end
     T1=[T1(r1+1:p1,:);T1(1:r1,:)],
     D12=T1*D12,
//Column compression of D21
     [S1,r2]=colcomp(D21),
 if r2<>p2 then error('D21 not full rank! '),end,
     D21=D21*S1,
//Updating
     B1=B1*S1,C1=T1*C1,
     D11=T1*D11*S1,
// Scaling on U and Y
     Uc#=D12(l2,:);
     Uc#i=inv(Uc#);
     B2=B2*Uc#i;
     D12=D12*Uc#i;

     Yc#=D21(:,k2)
     Yc#i=inv(Yc#);
     C2=Yc#i*C2;
     D21=Yc#i*D21;

//P6=[A,B1,B2,C1,C2,D11,D12,D21,D22] with D11=0,D22=0;D12 and D21 scaled.
//Standard assumptions now satisfied

//P6=[A,B1,B2,C1,C2,D11,D12,D21,D22];

//     Test of mu for P6  <=> Test of mu^-1 for P2
//Optimal controller :
indic=0;     

mu_test=1/mu;

     R1=B1*B1';
     S=D12'*C1;
     C1#=(eye-D12*D12')*C1;
     Ax=A-B2*S;
     Qx=-C1#'*C1#;

     Rx=mu_test*R1-B2*B2';
H=[Ax Rx;
   Qx -Ax'];

dx=mini(abs(real(spec(H))));
//write(%io(2),dx);
       if dx < 1.d-9 then
 write(%io(2),'An eigenvalue of H (controller) is close to Imaginary axis !');
     write(%io(2),dx);
       indic=1;test=1;
       end
 if indic ==0 then
   [X1,X2,errx]=ric_desc(H);
     if errx > 1.d-4 then
       write(%io(2),'Riccati solution inaccurate ');
       write(%io(2),errx);
     end
//Optimal observer :

     Q1=C1'*C1;
     L=B1*D21';
     B1#=B1*(eye-D21'*D21);
     Ay=A-L*C2;
     Qy=-B1#*B1#';
 
     Ry=mu_test*Q1-C2'*C2;

    J=[Ay' Ry;
       Qy -Ay];
    dy=mini(abs(real(spec(J))));
//write(%io(2),dy);
      if dy < 1.d-9 then
   write(%io(2),'An eigenvalue of J (observer) is close to Imaginary axis !');
      write(%io(2),dy);
      indic=1 ;test=1;
       end
     if indic==0 then
       [Y1,Y2,erry]=ric_desc(J);
        if erry > 1.d-4 then 
          write(%io(2),'Riccati solution inaccurate ');
          write(%io(2),erry);
        end
//Tests
//
//     E=(Y2'*X2-mu*Y1'*X1);
//     write(%io(2),mini(svd(E)),'(5x,''mini(svd(E)) = '',f10.2)')
     [al1,be1]=gspec(A*X2 -B2*(S*X2 +B2'*X1 ),X2);
     [al2,be2]=gspec(Y2'*A-(Y2'*L+Y1'*C2')*C2,Y2');
     [al3,be3]=gspec(mu_test*Y1'*X1,Y2'*X2);

//Here division by zero may appear...
//If such division appear try to uncomment the 3 following lines:
w1=find(be1==0);be1(w1)=%eps*ones(be1(w1));
w2=find(be2==0);be2(w2)=%eps*ones(be2(w2));
w3=find(be3==0);be3(w3)=%eps*ones(be3(w3));

     test1=maxi(real(al1./be1));
     test2=maxi(real(al2./be2));
     test3=maxi(real(al3./be3))-1;
     tv   =[test1,test2,test3]
  end
end

//write(%io(2),1/sqrt(mu),'(10x,'' Try gama = '',f18.10)');
[answer,no]=maxi(tv);
//if exists('tv')==1 then write(%io(2),[tv,maxi(tv)],'(4f15.10)');end
if exists('tv')==1 then 
   if answer>0 then 
               if no==1 then
 write(%io(2),[1/sqrt(mu),answer],'('' gama = '',f18.10,'' Unfeasible (Hx hamiltonian)  test = '',e15.5)');
                       end
               if no==2 then
 write(%io(2),[1/sqrt(mu),answer],'('' gama = '',f18.10,'' Unfeasible (Hy hamiltonian)  test = '',e15.5)');
                       end
               if no==3 then
 write(%io(2),[1/sqrt(mu),answer],'('' gama = '',f18.10,'' Unfeasible (spectral radius) test = '',e15.5)');
                       end
		     else 
 write(%io(2),[1/sqrt(mu),answer],'('' gama = '',f18.10,''              OK              test = '',e15.5)');
    end;
end;
     P6=syslin('c',A,[B1,B2],[C1;C2],[D11,D12;D21,D22])


function [Sk,polesH,polesJ]=h_contr(P,r,mu,U2i,Y2i)
// ****************************
// Computation of the optimal controller Sk for a standard
// plant which satisfies the assumption D11=0
// 
// F.D.
//!
//   [C1 D12]*[C1 D12]'=Q=[Q1 S;S' Q2]
//   [B1;D21]*[B1;D21]'=R=[R1 L';L R2]
// 

     [A,B1,B2,C1,C2,D11,D12,D21,D22]=smga(P,r);
     if norm(D11,1) > %eps then error('D11 <> 0'),return end

     [p2,m1]=size(D21),
     [p1,m2]=size(D12),
     l1=1:p1-m2;k1=1:m1-p2;
     l2=1+p1-m2:p1;k2=1+m1-p2:m1;

//Initialization  : constants 

     R1=B1*B1';
     S=D12'*C1;
     C1#=(eye-D12*D12')*C1;
     Ax=A-B2*S;
     Qx=-C1#'*C1#;

     Q1=C1'*C1;
     L=B1*D21';
     B1#=B1*(eye-D21'*D21);
     Ay=A-L*C2;
     Qy=-B1#*B1#';

//               mu-dependent part

//Optimal controller

  Rx=mu*R1-B2*B2';

  H=[Ax Rx;
     Qx -Ax'];
  polesH=spec(H);
  dx=mini(abs(real(polesH)));
//write(%io(2),dx);
if dx < 1.d-6 then
 write(%io(2),'An eigenvalue of H (controller) is close to Imaginary axis !');
end
   [X1,X2,errx]=ric_desc(H);
if errx > 1.d-4 then 
   write(%io(2),'Riccati solution inaccurate ');
   write(%io(2),errx);
end

//Optimal observer :

  Ry=mu*Q1-C2'*C2;

  J=[Ay' Ry;
     Qy -Ay];
  polesJ=spec(J);
  dy=mini(abs(real(polesJ)));
//write(%io(2),dy);
if dy < 1.d-6 then
   write(%io(2),'An eigenvalue of J (observer) is close to Imaginary axis !');
end
  [Y1,Y2,erry]=ric_desc(J);
if erry > 1.d-4 then 
   write(%io(2),'Riccati solution inaccurate ');
   write(%io(2),erry);
end

//Controller in descriptor form

  E=(Y2'*X2-mu*Y1'*X1);
  A#=A-B2*S-L*C2;
  Ak=Y2'*A#*X2+mu*Y1'*A#'*X1-Y2'*(mu*Qy+B2*B2')*X1-Y1'*(mu*Qx+C2'*C2)*X2;
  Bk1=(Y2'*L+Y1'*C2');
  Ck1=-(S*X2+B2'*X1);

  Bk2=Y2'*B2+Y1'*S'
  Ck2=-(C2*X2+L'*X1)

  Dk11=0*Ck1*Bk1;
  Dk22=0*Ck2*Bk2;
  Dk12=eye(Ck1*Bk2);
  Dk21=eye(Ck2*Bk1);

//Scaling back

    Bk1=Bk1*Y2i;
    Ck1=U2i*Ck1;
    Dk21=Dk21*Y2i;
    Dk12=U2i*Dk12;
//  Dk11=U2i*Dk11*Y2i

    Sk=list(E,Ak,Bk1,Bk2,Ck1,Ck2,Dk11,Dk12,Dk21,Dk22);