summaryrefslogtreecommitdiffstats
path: root/templates/compute_minRPI.m
blob: 2ae7946ac6a0aff000a6e50cb328a1f71eb93d21 (plain)
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright (c) 2023, Amon Lahr, Simon Muntwiler, Antoine Leeman & Fabian Flürenbrock Institute for Dynamic Systems and Control, ETH Zurich.
%
% All rights reserved.
%
% Please see the LICENSE file that has been included as part of this package.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [H_tube,h_tube,n_iter] = compute_minRPI(K_tube,params)
    % YOUR CODE HERE
    A = params.model.A+params.model.B*K_tube;
    nx = params.model.nx;
    omega = Polyhedron('A',[eye(nx);-eye(nx)],'b',zeros(1,2*nx)');
    % display(omega.A)
    % display(omega.b)
    n_iter = 0;
    Hw = params.constraints.DisturbanceMatrix;
    hw = params.constraints.DisturbanceRHS;
    while true 
        omega_last = copy(omega);
        % display(n_iter)
        % A_last = omega.A;
        % b_last = omega.b;
        omega = omega.plus(Polyhedron('A',Hw*(A^n_iter),'b',hw));
        
        if eq(omega.minHRep(),omega_last.minHRep())
        % if eq(omega,omega_last)
            break
        end
        n_iter = n_iter+1;
    end
    H_tube = omega.A;
    h_tube = omega.b;
end