-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPROJECT_H2.m
744 lines (664 loc) · 21.8 KB
/
PROJECT_H2.m
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
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
%% PROJECT, Three tanks system
clear
close all
clc
%% MODELLING
% system state space matrix description:
Atot=[-1 0 0
1 -1 0
0 1 -1];
Ctot=eye(3);
Btot=[1 0
0 1
0 0];
%discrete time realization
h = 0.2; % sampling time, to chose wisely according to system dynamic
[Ftot,Gtot,Htot,Ltot,h]=ssdata(c2d(ss(Atot,Btot,Ctot,[]),h));
% System decomposition:
N = 2; %number of subsystems, (1)first tank, (2)second+third tank
for i=1:N
% continuous time decomposition
B{i} = Btot(:,i);
C{i} = Ctot(i:2*i-1,:);
% discrete time decomposition
G{i} = Gtot(:,i);
H{i} = Htot(i:2*i-1,:);
end
%% ANALYSIS
% Open Loop analysis:
% CONTROL STRUCTURES
ContStructure_centralized = ones(N,N); % centralized
ContStructure_decentralized = diag(ones(N,1)); % decentralized
% smart choice is to use info from first sub system to affect second
% controller (due to the inherent influence of the first to the second)
ContStructure_distributedString = [1 0;
1 1]; % BETTER ONE PHISICALLY
ContStructure_distributedString2 = [1 1;
0 1];
% OPEN LOOP EIGEN VALUES and SPECTRAL ABSCISSA:
% CONTINUOUS
eigenvalues=eig(Atot); % eigen values
rho=max(real(eig(Atot))); % spectral abscissa
% DISCRETE
eigenvalues_DT=eig(Ftot); % eigen values
rho_DT=max(abs(eig(Ftot))); % spectral radius
% State-feedback FIXED MODES:
% Centralized
[cfm]=di_fixed_modes(Atot,B,C,N,ContStructure_centralized,3);
[cfm_DT]=di_fixed_modes(Ftot,G,H,N,ContStructure_centralized,3);
% Decentralized
[Dfm]=di_fixed_modes(Atot,B,C,N,ContStructure_decentralized,3);
[Dfm_DT]=di_fixed_modes(Ftot,G,H,N,ContStructure_decentralized,3);
% Distributed1, BETTER
[Distfm]=di_fixed_modes(Atot,B,C,N,ContStructure_distributedString,3);
[Distfm_DT]=di_fixed_modes(Ftot,G,H,N,ContStructure_distributedString,3);
% Distributed2
[Distfm2]=di_fixed_modes(Atot,B,C,N,ContStructure_distributedString2,3);
[Distfm2_DT]=di_fixed_modes(Ftot,G,H,N,ContStructure_distributedString2,3);
%-----------------------------------------------------------------------
% SPEED UP, REDUCE OVERSHOOT AND LIMIT CONTROL ACTION CONTROL LAW:
%% CONTINUOUS TIME:
rho_desired = 1.7; % speed up to get a setting time of 2.5 sec
alfa_desired = (10/180)*pi; % lower bound on dumping factor, +/- 40 deg region
% CENTRALIZED
[K_c_opt1,rho_c_opt1,feas_c_opt1]=LMI_CT_opt1(Atot,B,C,N,ContStructure_centralized,rho_desired,alfa_desired);
% DECENTRALIZED
[K_De_opt1,rho_De_opt1,feas_De_opt1]=LMI_CT_opt1(Atot,B,C,N,ContStructure_decentralized,rho_desired,alfa_desired);
% DISTRIBUTED
[K_string_opt1,rho_string_opt1,feas_string_opt1]=LMI_CT_opt1(Atot,B,C,N,ContStructure_distributedString,rho_desired,alfa_desired);
% DISTRIBUTED2
[K_string2_opt1,rho_string2_opt1,feas_string2_opt1]=LMI_CT_opt1(Atot,B,C,N,ContStructure_distributedString2,rho_desired,alfa_desired);
%% DISCRETE TIME:
% first compare with same performance request, than try to optimally design
% the controller for each control structure, according to its limitations
% PERFORMANCE
rho_desired_DT = 0.05; % limit the circle region radius of DT eigenvalues
alfa_desired_DT = -0.75; % place the circle center where eigs are constrained
% CENTRALIZED
[K_c_opt1_DT,rho_c_opt1_DT,feas_c_opt1_DT]=LMI_DT_opt1(Ftot,G,H,N,ContStructure_centralized,rho_desired_DT,alfa_desired_DT);
% DECENTRALIZED
[K_De_opt1_DT,rho_De_opt1_DT,feas_De_opt1_DT]=LMI_DT_opt1(Ftot,G,H,N,ContStructure_decentralized,rho_desired_DT,alfa_desired_DT);
% DISTRIBUTED
[K_string_opt1_DT,rho_string_opt1_DT,feas_string_opt1_DT]=LMI_DT_opt1(Ftot,G,H,N,ContStructure_distributedString,rho_desired_DT,alfa_desired_DT);
% DISTRIBUTED2
[K_string2_opt1_DT,rho_string2_opt1_DT,feas_string2_opt1_DT]=LMI_DT_opt1(Ftot,G,H,N,ContStructure_distributedString2,rho_desired_DT,alfa_desired_DT);
%% LQ CONTROL (BY H2 PROPER MATRIX CHOICE)
n = length(Atot); % number of states
m = size(Btot,2);
% CONTINUOUS TIME
Bw = eye(n);
%Bw=zeros(n,n);
Q = 100; % State weight
R = 1; % Control action weight
Cz = [eye(n)*sqrt(Q);zeros(m,n)];
Dz = [zeros(n,m);eye(m)*sqrt(R)];
% CENTRALIZED
[K_c_H2,rho_c_H2,feas_c_H2]=LMI_CT_H2(Atot,B,C,Bw,Cz,Dz,N,ContStructure_centralized);
% DECENTRALIZED
[K_De_H2,rho_De_H2,feas_De_H2]=LMI_CT_H2(Atot,B,C,Bw,Cz,Dz,N,ContStructure_decentralized);
% DISTRIBUTED
[K_string_H2,rho_string_H2,feas_string_H2]=LMI_CT_H2(Atot,B,C,Bw,Cz,Dz,N,ContStructure_distributedString);
% DISTRIBUTED2
[K_string2_H2,rho_string2_H2,feas_string2_H2]=LMI_CT_H2(Atot,B,C,Bw,Cz,Dz,N,ContStructure_distributedString2);
% DISCRETE TIME
Gw = eye(n);
Q = 100; % State weight
R = 100; % Control action weight
Hz = [eye(n)*sqrt(Q);zeros(m,n)];
Dz = [zeros(n,m);eye(m)*sqrt(R)];
% CENTRALIZED
[K_c_H2_DT,rho_c_H2_DT,feas_c_H2_DT]=LMI_DT_H2(Ftot,G,H,Hz,Dz,Gw,N,ContStructure_centralized);
% DECENTRALIZED
[K_De_H2_DT,rho_De_H2_DT,feas_De_H2_DT]=LMI_DT_H2(Ftot,G,H,Hz,Dz,Gw,N,ContStructure_decentralized);
% DISTRIBUTED
[K_string_H2_DT,rho_string_H2_DT,feas_string_H2_DT]=LMI_DT_H2(Ftot,G,H,Hz,Dz,Gw,N,ContStructure_distributedString);
% DISTRIBUTED2
[K_string2_H2_DT,rho_string2_H2_DT,feas_string2_H2_DT]=LMI_DT_H2(Ftot,G,H,Hz,Dz,Gw,N,ContStructure_distributedString2);
%% SIMULATIONS
% optimal design
% H2 control
%-------------------------------------------------------------------------
Tf = 10;
T = [0:0.01:Tf];
x0 = 0.1*randn(n,1); %random initial states
%x0 = [-0.1444, -0.0991, -0.0732]';
%---------------------------------------------------------------------
%% REDUCING OVERSHOOT AND SPEED UP CONTROL, WITH LIMITED CONTROL ACTION (OPT1)
i = 0;
% CONTINUOUS
for t=T
i=i+1;
x_c_opt1(:,i)=expm((Atot+Btot*K_c_opt1)*t)*x0;
x_De_opt1(:,i)=expm((Atot+Btot*K_De_opt1)*t)*x0;
x_string_opt1(:,i)=expm((Atot+Btot*K_string_opt1)*t)*x0;
x_string2_opt1(:,i)=expm((Atot+Btot*K_string2_opt1)*t)*x0;
x_c_H2(:,i)=expm((Atot+Btot*K_c_H2)*t)*x0;
x_De_H2(:,i)=expm((Atot+Btot*K_De_H2)*t)*x0;
x_string_H2(:,i)=expm((Atot+Btot*K_string_H2)*t)*x0;
x_string2_H2(:,i)=expm((Atot+Btot*K_string2_H2)*t)*x0;
end
u_c_opt1 = K_c_opt1*x_c_opt1;
u_De_opt1 = K_De_opt1*x_De_opt1;
u_string_opt1 = K_string_opt1*x_string_opt1;
u_string2_opt1 = K_string2_opt1*x_string2_opt1;
u_c_H2 = K_c_H2*x_c_H2;
u_De_H2 = K_De_H2*x_De_H2;
u_string_H2 = K_string_H2*x_string_H2;
u_string2_H2 = K_string2_H2*x_string2_H2;
% CENTRALIZED:
figure('Name',' CENTRALIZED SPEED+OVERSHOOT ')
subplot(1,2,1)
plot(T,x_c_opt1(1,:), 'r');
hold on
plot(T,x_c_opt1(2,:), 'b');
plot(T,x_c_opt1(3,:), 'g');
grid on
xlabel('t [s]')
ylabel('Dh [m]')
title('CONTINUOUS: Centralized States')
legend('Dh_{1}', 'Dh_{2}', 'Dh_{3}')
subplot(1,2,2)
plot(T,u_c_opt1(1,:), 'm');
hold on
plot(T,u_c_opt1(2,:), 'b');
grid on
xlabel('t [s]')
ylabel('u [m^{3}/s]')
title('CONTINUOUS: Centralized Control')
legend('u_{1}', 'u_{2}')
sgtitle(" CENTRALIZED CONTROL ")
% DECENTRALIZED
figure('Name',' DECENTRALIZED SPEED+OVERSHOOT ')
subplot(1,2,1)
plot(T,x_De_opt1(1,:), 'r');
hold on
plot(T,x_De_opt1(2,:), 'b');
plot(T,x_De_opt1(3,:), 'g');
grid on
xlabel('t [s]')
ylabel('Dh [m]')
title('CONTINUOUS: Decentralized States')
legend('Dh_{1}', 'Dh_{2}', 'Dh_{3}')
subplot(1,2,2)
plot(T,u_De_opt1(1,:), 'm');
hold on
plot(T,u_De_opt1(2,:), 'b');
grid on
xlabel('t [s]')
ylabel('u [m^{3}/s]')
title('CONTINUOUS: Decentralized Control')
legend('u_{1}', 'u_{2}')
sgtitle(" DECENTRALIZED CONTROL ")
% DISTRIBUTED
figure('Name',' DISTRIBUTED SPEED+OVERSHOOT ')
subplot(1,2,1)
plot(T,x_string_opt1(1,:), 'r');
hold on
plot(T,x_string_opt1(2,:), 'b');
plot(T,x_string_opt1(3,:), 'g');
grid on
xlabel('t [s]')
ylabel('Dh [m]')
title('CONTINUOUS: Distributed States')
legend('Dh_{1}', 'Dh_{2}', 'Dh_{3}')
subplot(1,2,2)
plot(T,u_string_opt1(1,:), 'm');
hold on
plot(T,u_string_opt1(2,:), 'b');
grid on
xlabel('t [s]')
ylabel('u [m^{3}/s]')
title('CONTINUOUS: Distributed Control')
legend('u_{1}', 'u_{2}')
sgtitle(" DISTRIBUTED CONTROL ")
% DISTRIBUTED 2
figure('Name',' DISTRIBUTED SPEED+OVERSHOOT ')
subplot(1,2,1)
plot(T,x_string2_opt1(1,:), 'r');
hold on
plot(T,x_string2_opt1(2,:), 'b');
plot(T,x_string2_opt1(3,:), 'g');
grid on
xlabel('t [s]')
ylabel('Dh [m]')
title('CONTINUOUS: Distributed 2 States')
legend('Dh_{1}', 'Dh_{2}', 'Dh_{3}')
subplot(1,2,2)
plot(T,u_string2_opt1(1,:), 'm');
hold on
plot(T,u_string2_opt1(2,:), 'b');
grid on
xlabel('t [s]')
ylabel('u [m^{3}/s]')
title('CONTINUOUS: Distributed 2 Control')
legend('u_{1}', 'u_{2}')
sgtitle(" DISTRIBUTED 2 CONTROL ")
%% H2 CONTINUOUS
% CENTRALIZED:
figure('Name',' CENTRALIZED H2 ')
subplot(1,2,1)
plot(T,x_c_H2(1,:), 'r');
hold on
plot(T,x_c_H2(2,:), 'b');
plot(T,x_c_H2(3,:), 'g');
grid on
xlabel('t [s]')
ylabel('Dh [m]')
title('CONTINUOUS: Centralized States H2')
legend('Dh_{1}', 'Dh_{2}', 'Dh_{3}')
subplot(1,2,2)
plot(T,u_c_H2(1,:), 'm');
hold on
plot(T,u_c_H2(2,:), 'b');
grid on
xlabel('t [s]')
ylabel('u [m^{3}/s]')
title('CONTINUOUS: Centralized Control H2')
legend('u_{1}', 'u_{2}')
sgtitle(" CENTRALIZED CONTROL H2")
% DECENTRALIZED
figure('Name',' DECENTRALIZED H2 ')
subplot(1,2,1)
plot(T,x_De_H2(1,:), 'r');
hold on
plot(T,x_De_H2(2,:), 'b');
plot(T,x_De_H2(3,:), 'g');
grid on
xlabel('t [s]')
ylabel('Dh [m]')
title('CONTINUOUS: Decentralized States H2')
legend('Dh_{1}', 'Dh_{2}', 'Dh_{3}')
subplot(1,2,2)
plot(T,u_De_H2(1,:), 'm');
hold on
plot(T,u_De_H2(2,:), 'b');
grid on
xlabel('t [s]')
ylabel('u [m^{3}/s]')
title('CONTINUOUS: Decentralized Control H2')
legend('u_{1}', 'u_{2}')
sgtitle(" DECENTRALIZED CONTROL H2")
% DISTRIBUTED
figure('Name',' DISTRIBUTED H2 ')
subplot(1,2,1)
plot(T,x_string_H2(1,:), 'r');
hold on
plot(T,x_string_H2(2,:), 'b');
plot(T,x_string_H2(3,:), 'g');
grid on
xlabel('t [s]')
ylabel('Dh [m]')
title('CONTINUOUS: Distributed States H2')
legend('Dh_{1}', 'Dh_{2}', 'Dh_{3}')
subplot(1,2,2)
plot(T,u_string_H2(1,:), 'm');
hold on
plot(T,u_string_H2(2,:), 'b');
grid on
xlabel('t [s]')
ylabel('u [m^{3}/s]')
title('CONTINUOUS: Distributed Control H2')
legend('u_{1}', 'u_{2}')
sgtitle(" DISTRIBUTED CONTROL H2")
% DISTRIBUTED 2
figure('Name',' DISTRIBUTED H2')
subplot(1,2,1)
plot(T,x_string2_H2(1,:), 'r');
hold on
plot(T,x_string2_H2(2,:), 'b');
plot(T,x_string2_H2(3,:), 'g');
grid on
xlabel('t [s]')
ylabel('Dh [m]')
title('CONTINUOUS: Distributed 2 States H2')
legend('Dh_{1}', 'Dh_{2}', 'Dh_{3}')
subplot(1,2,2)
plot(T,u_string2_H2(1,:), 'm');
hold on
plot(T,u_string2_H2(2,:), 'b');
grid on
xlabel('t [s]')
ylabel('u [m^{3}/s]')
title('CONTINUOUS: Distributed 2 Control H2')
legend('u_{1}', 'u_{2}')
sgtitle(" DISTRIBUTED 2 CONTROL H2")
figure('Name','PZPLOT CONTINUOUS')
subplot(2,3,1)
pzmap(ss(Atot,Btot,Ctot,0))
title("Open Loop")
subplot(2,3,2)
pzmap(ss(Atot+Btot*K_c_opt1,zeros(3,2),Ctot,0))
title("Centralized")
subplot(2,3,3)
pzmap(ss(Atot+Btot*K_De_opt1,zeros(3,2),Ctot,0))
title("Decentralized")
subplot(2,3,4)
pzmap(ss(Atot+Btot*K_string_opt1,zeros(3,2),Ctot,0))
title("Distributed")
subplot(2,3,5)
pzmap(ss(Atot+Btot*K_string2_opt1,zeros(3,2),Ctot,0))
title("Distributed 2")
figure('Name','PZPLOT CONTINUOUS H2')
subplot(2,3,1)
pzmap(ss(Atot,Btot,Ctot,0))
title("Open Loop")
subplot(2,3,2)
pzmap(ss(Atot+Btot*K_c_H2,zeros(3,2),Ctot,0))
title("Centralized H2")
subplot(2,3,3)
pzmap(ss(Atot+Btot*K_De_H2,zeros(3,2),Ctot,0))
title("Decentralized H2")
subplot(2,3,4)
pzmap(ss(Atot+Btot*K_string_H2,zeros(3,2),Ctot,0))
title("Distributed H2")
subplot(2,3,5)
pzmap(ss(Atot+Btot*K_string2_H2,zeros(3,2),Ctot,0))
title("Distributed 2")
%% PLACE EIGENVALUES IN A CIRCLE REGION WITH LIMITED RADIUS AND CHOSEN CENTER
%DICRETE
% i = 0;
% steps = [0:Tf/h];
% for k=steps
% i = i+1;
% x_c_opt1_DT(:,i)=((Ftot+Gtot*K_c_opt1_DT)^k)*x0;
% x_De_opt1_DT(:,i)=((Ftot+Gtot*K_De_opt1_DT)^k)*x0;
% x_string_opt1_DT(:,i)=((Ftot+Gtot*K_string_opt1_DT)^k)*x0;
% x_string2_opt1_DT(:,i)=((Ftot+Gtot*K_string2_opt1_DT)^k)*x0;
%
% x_c_H2_DT(:,i)=((Ftot+Gtot*K_c_H2_DT)^k)*x0;
% x_De_H2_DT(:,i)=((Ftot+Gtot*K_De_H2_DT)^k)*x0;
% x_string_H2_DT(:,i)=((Ftot+Gtot*K_string_H2_DT)^k)*x0;
% x_string2_H2_DT(:,i)=((Ftot+Gtot*K_string2_H2_DT)^k)*x0;
%
% end
% u_c_opt1_DT = K_c_opt1_DT*x_c_opt1_DT;
% u_De_opt1_DT = K_De_opt1_DT*x_De_opt1_DT;
% u_string_opt1_DT = K_string_opt1_DT*x_string_opt1_DT;
% u_string2_opt1_DT = K_string2_opt1_DT*x_string2_opt1_DT;
%
% u_c_H2_DT = K_c_H2_DT*x_c_H2_DT;
% u_De_H2_DT = K_De_H2_DT*x_De_H2_DT;
% u_string_H2_DT = K_string_H2_DT*x_string_H2_DT;
% u_string2_H2_DT = K_string2_H2_DT*x_string2_H2_DT;
%
% % CENTRALIZED:
% figure('Name',' CENTRALIZED DISCRETE OPT1 ')
% subplot(1,2,1)
% plot(steps*h,x_c_opt1_DT(1,:), 'r');
% hold on
% plot(steps*h,x_c_opt1_DT(2,:), 'b');
% plot(steps*h,x_c_opt1_DT(3,:), 'g');
% grid on
% xlabel('t [s]')
% ylabel('Dh [m]')
% title('DISCRETE: Centralized States')
% legend('Dh_{1}', 'Dh_{2}', 'Dh_{3}')
%
% subplot(1,2,2)
% plot(steps*h,u_c_opt1_DT(1,:), 'm');
% hold on
% plot(steps*h,u_c_opt1_DT(2,:), 'b');
% grid on
% xlabel('t [s]')
% ylabel('u [m^{3}/s]')
% title('DISCRETE: Centralized Control')
% legend('u_{1}', 'u_{2}')
%
% sgtitle(" CENTRALIZED CONTROL ")
%
% % DECENTRALIZED
% figure('Name',' DECENTRALIZED DISCRETE OPT1 ')
% subplot(1,2,1)
% plot(steps*h,x_De_opt1_DT(1,:), 'r');
% hold on
% plot(steps*h,x_De_opt1_DT(2,:), 'b');
% plot(steps*h,x_De_opt1_DT(3,:), 'g');
% grid on
% xlabel('t [s]')
% ylabel('Dh [m]')
% title('DISCRETE: Decentralized States')
% legend('Dh_{1}', 'Dh_{2}', 'Dh_{3}')
%
% subplot(1,2,2)
% plot(steps*h,u_De_opt1_DT(1,:), 'm');
% hold on
% plot(steps*h,u_De_opt1_DT(2,:), 'b');
% grid on
% xlabel('t [s]')
% ylabel('u [m^{3}/s]')
% title('DISCRETE: Decentralized Control')
% legend('u_{1}', 'u_{2}')
%
% sgtitle(" DECENTRALIZED CONTROL ")
%
% % DISTRIBUTED
%
% figure('Name',' DISTRIBUTED DISCRETE OPT1 ')
% subplot(1,2,1)
% plot(steps*h,x_string_opt1_DT(1,:), 'r');
% hold on
% plot(steps*h,x_string_opt1_DT(2,:), 'b');
% plot(steps*h,x_string_opt1_DT(3,:), 'g');
% grid on
% xlabel('t [s]')
% ylabel('Dh [m]')
% title('DISCRETE: Distributed States')
% legend('Dh_{1}', 'Dh_{2}', 'Dh_{3}')
%
% subplot(1,2,2)
% plot(steps*h,u_string_opt1_DT(1,:), 'm');
% hold on
% plot(steps*h,u_string_opt1_DT(2,:), 'b');
% grid on
% xlabel('t [s]')
% ylabel('u [m^{3}/s]')
% title('DISCRETE: Distributed Control')
% legend('u_{1}', 'u_{2}')
%
% sgtitle(" DISTRIBUTED CONTROL DISCRETE ")
%
% % DISTRIBUTED 2
%
% figure('Name',' DISTRIBUTED 2 DISCRETE OPT1 ')
% subplot(1,2,1)
% plot(steps*h,x_string2_opt1_DT(1,:), 'r');
% hold on
% plot(steps*h,x_string2_opt1_DT(2,:), 'b');
% plot(steps*h,x_string2_opt1_DT(3,:), 'g');
% grid on
% xlabel('t [s]')
% ylabel('Dh [m]')
% title('DISCRETE: Distributed 2 States')
% legend('Dh_{1}', 'Dh_{2}', 'Dh_{3}')
%
% subplot(1,2,2)
% plot(steps*h,u_string2_opt1_DT(1,:), 'm');
% hold on
% plot(steps*h,u_string2_opt1_DT(2,:), 'b');
% grid on
% xlabel('t [s]')
% ylabel('u [m^{3}/s]')
% title('DISCRETE: Distributed 2 Control')
% legend('u_{1}', 'u_{2}')
%
% sgtitle(" DISTRIBUTED 2 CONTROL DISCRETE ")
%
% %% H2 DISCRETE
%
% % CENTRALIZED:
% figure('Name',' CENTRALIZED DISCRETE H2 ')
% subplot(1,2,1)
% plot(steps*h,x_c_H2_DT(1,:), 'r');
% hold on
% plot(steps*h,x_c_H2_DT(2,:), 'b');
% plot(steps*h,x_c_H2_DT(3,:), 'g');
% grid on
% xlabel('t [s]')
% ylabel('Dh [m]')
% title('DISCRETE: Centralized States H2')
% legend('Dh_{1}', 'Dh_{2}', 'Dh_{3}')
%
% subplot(1,2,2)
% plot(steps*h,u_c_H2_DT(1,:), 'm');
% hold on
% plot(steps*h,u_c_H2_DT(2,:), 'b');
% grid on
% xlabel('t [s]')
% ylabel('u [m^{3}/s]')
% title('DISCRETE: Centralized Control H2')
% legend('u_{1}', 'u_{2}')
%
% sgtitle(" CENTRALIZED CONTROL H2")
%
% % DECENTRALIZED
% figure('Name',' DECENTRALIZED DISCRETE H2 ')
% subplot(1,2,1)
% plot(steps*h,x_De_H2_DT(1,:), 'r');
% hold on
% plot(steps*h,x_De_H2_DT(2,:), 'b');
% plot(steps*h,x_De_H2_DT(3,:), 'g');
% grid on
% xlabel('t [s]')
% ylabel('Dh [m]')
% title('DISCRETE: Decentralized States H2')
% legend('Dh_{1}', 'Dh_{2}', 'Dh_{3}')
%
% subplot(1,2,2)
% plot(steps*h,u_De_H2_DT(1,:), 'm');
% hold on
% plot(steps*h,u_De_H2_DT(2,:), 'b');
% grid on
% xlabel('t [s]')
% ylabel('u [m^{3}/s]')
% title('DISCRETE: Decentralized Control H2')
% legend('u_{1}', 'u_{2}')
%
% sgtitle(" DECENTRALIZED CONTROL H2")
%
% % DISTRIBUTED
%
% figure('Name',' DISTRIBUTED DISCRETE H2 ')
% subplot(1,2,1)
% plot(steps*h,x_string_H2_DT(1,:), 'r');
% hold on
% plot(steps*h,x_string_H2_DT(2,:), 'b');
% plot(steps*h,x_string_H2_DT(3,:), 'g');
% grid on
% xlabel('t [s]')
% ylabel('Dh [m]')
% title('DISCRETE: Distributed States H2')
% legend('Dh_{1}', 'Dh_{2}', 'Dh_{3}')
%
% subplot(1,2,2)
% plot(steps*h,u_string_H2_DT(1,:), 'm');
% hold on
% plot(steps*h,u_string_H2_DT(2,:), 'b');
% grid on
% xlabel('t [s]')
% ylabel('u [m^{3}/s]')
% title('DISCRETE: Distributed Control H2')
% legend('u_{1}', 'u_{2}')
%
% sgtitle(" DISTRIBUTED CONTROL DISCRETE H2")
%
% % DISTRIBUTED 2
%
% figure('Name',' DISTRIBUTED 2 DISCRETE H" ')
% subplot(1,2,1)
% plot(steps*h,x_string2_H2_DT(1,:), 'r');
% hold on
% plot(steps*h,x_string2_H2_DT(2,:), 'b');
% plot(steps*h,x_string2_H2_DT(3,:), 'g');
% grid on
% xlabel('t [s]')
% ylabel('Dh [m]')
% title('DISCRETE: Distributed 2 States H2')
% legend('Dh_{1}', 'Dh_{2}', 'Dh_{3}')
%
% subplot(1,2,2)
% plot(steps*h,u_string2_H2_DT(1,:), 'm');
% hold on
% plot(steps*h,u_string2_H2_DT(2,:), 'b');
% grid on
% xlabel('t [s]')
% ylabel('u [m^{3}/s]')
% title('DISCRETE: Distributed 2 Control H2')
% legend('u_{1}', 'u_{2}')
%
% sgtitle(" DISTRIBUTED 2 CONTROL DISCRETE H2")
%
%
%
% figure('Name','PZPLOT DISCRETE')
% subplot(2,3,1)
% pzmap(ss(Ftot,Gtot,Htot,0))
% title("Open Loop")
% subplot(2,3,2)
% pzmap(ss(Ftot+Gtot*K_c_opt1_DT,zeros(3,2),Ctot,0))
% title("Centralized")
% subplot(2,3,3)
% pzmap(ss(Ftot+Gtot*K_De_opt1_DT,zeros(3,2),Ctot,0))
% title("Decentralized")
% subplot(2,3,4)
% pzmap(ss(Ftot+Gtot*K_string_opt1_DT,zeros(3,2),Ctot,0))
% title("Distributed")
% subplot(2,3,5)
% pzmap(ss(Ftot+Gtot*K_string2_opt1_DT,zeros(3,2),Ctot,0))
% title("Distributed 2")
%
%
% figure('Name','PZPLOT DISCRETE H2')
% subplot(2,3,1)
% pzmap(ss(Ftot,Gtot,Htot,0))
% title("Open Loop")
% subplot(2,3,2)
% pzmap(ss(Ftot+Gtot*K_c_H2_DT,zeros(3,2),Ctot,0))
% title("Centralized H2")
% subplot(2,3,3)
% pzmap(ss(Ftot+Gtot*K_De_H2_DT,zeros(3,2),Ctot,0))
% title("Decentralized H2")
% subplot(2,3,4)
% pzmap(ss(Ftot+Gtot*K_string_H2_DT,zeros(3,2),Ctot,0))
% title("Distributed H2")
% subplot(2,3,5)
% pzmap(ss(Ftot+Gtot*K_string2_H2_DT,zeros(3,2),Ctot,0))
% title("Distributed 2 H2")
%% DISPLAY RESULT:
disp("---------THREE-TANK SYSTEM-----------");
disp([' Number of sub-systems N = ', num2str(N)]);
disp([' Sampling time h = ', num2str(h)]);
disp('Results (Continuous-time):')
if rho < 0
disp(['- Open-loop: Asyptotically stable, Spectral abscissa = ',num2str(rho)]);
elseif rho == 0
disp(['- Open-loop: Simply stable, Spectral abscissa = ',num2str(rho)]);
else
disp(['- Open-loop: Unstable, Spectral abscissa = ',num2str(rho)]);
end
disp(['- Centralized OPT1: Feasibility=',num2str(feas_c_opt1),', rho=',num2str(rho_c_opt1),', FM=',num2str(cfm),'.'])
disp(['- Decentralized OPT1: Feasibility=',num2str(feas_De_opt1),', rho=',num2str(rho_De_opt1),', FM=',num2str(Dfm),'.'])
disp(['- Distributed (string) OPT1: Feasibility=',num2str(feas_string_opt1),', rho=',num2str(rho_string_opt1),', FM=',num2str(Distfm),'.'])
disp(['- Distributed (string 2) OPT1: Feasibility=',num2str(feas_string2_opt1),', rho=',num2str(rho_string2_opt1),', FM=',num2str(Distfm2),'.'])
disp(['- Centralized H2: Feasibility=',num2str(feas_c_H2),', rho=',num2str(rho_c_H2),', FM=',num2str(cfm),'.'])
disp(['- Decentralized H2: Feasibility=',num2str(feas_De_H2),', rho=',num2str(rho_De_H2),', FM=',num2str(Dfm),'.'])
disp(['- Distributed (string) H2: Feasibility=',num2str(feas_string_H2),', rho=',num2str(rho_string_H2),', FM=',num2str(Distfm),'.'])
disp(['- Distributed (string 2) H2: Feasibility=',num2str(feas_string2_H2),', rho=',num2str(rho_string2_H2),', FM=',num2str(Distfm2),'.'])
% disp('Results (Discrete-time):')
%
% if rho_DT < 1
% disp(['- Open-loop: Asyptotically stable, Spectral radius = ',num2str(rho_DT)]);
% elseif rho_DT == 1
% disp(['- Open-loop: Simply stable, Spectral radius = ',num2str(rho_DT)]);
% else
% disp(['- Open-loop: Unstable, Spectral radius = ',num2str(rho_DT)]);
% end
%
% disp(['- Centralized OPT1: Feasibility=',num2str(feas_c_opt1_DT),', rho=',num2str(rho_c_opt1_DT),', FM=',num2str(cfm_DT),'.'])
% disp(['- Decentralized OPT1: Feasibility=',num2str(feas_De_opt1_DT),', rho=',num2str(rho_De_opt1_DT),', FM=',num2str(Dfm_DT),'.'])
% disp(['- Distributed (string) OPT1: Feasibility=',num2str(feas_string_opt1_DT),', rho=',num2str(rho_string_opt1_DT),', FM=',num2str(Distfm_DT),'.'])
% disp(['- Distributed (string 2) OPT1: Feasibility=',num2str(feas_string2_opt1_DT),', rho=',num2str(rho_string2_opt1_DT),', FM=',num2str(Distfm2_DT),'.'])
%
% disp(['- Centralized H2: Feasibility=',num2str(feas_c_H2_DT),', rho=',num2str(rho_c_H2_DT),', FM=',num2str(cfm_DT),'.'])
% disp(['- Decentralized H2: Feasibility=',num2str(feas_De_H2_DT),', rho=',num2str(rho_De_H2_DT),', FM=',num2str(Dfm_DT),'.'])
% disp(['- Distributed (string) H2: Feasibility=',num2str(feas_string_H2_DT),', rho=',num2str(rho_string_H2_DT),', FM=',num2str(Distfm_DT),'.'])
% disp(['- Distributed (string 2) H2: Feasibility=',num2str(feas_string2_H2_DT),', rho=',num2str(rho_string2_H2_DT),', FM=',num2str(Distfm2_DT),'.'])