I'm trying to implement a matrix called Gamma in Matlab. It will include smaller matrices called H as seen in the figure below
I am having a trouble implementing this in Matlab.
What I have done is as follows:
I created a function called
function [Gamma] = get_Gamma(N,A,B,Cz)
then I create the H matrices
for i=1:N
H(:,:,i) = Cz*Ad^(i-1)*Bd;
end
Hn = size(H,1);
Hm = size(H,2);
and my problem is how I can do iterations as this:
Gamma = [H(:,:,1) zeros(2,2) zeros(2,2)]
Gamma = [Gamma ; H(:,:,2) H(:,:,1) zeros(2,2)]
Gamma = [Gamma ; H(:,:,3) H(:,:,2) H(:,:,1)]
I have been trying to do something like this
Gamma = [];
counter = 1;
for i=1:N
for j=1:N
if i <= counter
Gamma_update = H(:,:,j);
Gamma = [Gamma Gamma_update];
else
Gamma_update = zeros(Hn,Hm);
Gamma = [Gamma Gamma_update];
end
Gamma = [Gamma ; H(:,:,2) H(:,:,1) zeros(2,2)]
end
end
but I know this is not going to work. I hope you can help me out with this please!
CodePudding user response:
I just managed to find a solution to my problem and it is as follows:
function [Gamma] = get_Gamma(N,Ad,Bd,Czd)
% N: number of impulse response matrices to find Markov Parameters
for i=1:N
H(:,:,i) = Czd*Ad^(i-1)*Bd;
end
Hn = size(H,1);
Hm = size(H,2);
Gamma = [];
counter = 1;
for i=1:N
Gamma_update = [];
for k=N:-1:counter 1
Gamma_update = [zeros(Hn,Hm) Gamma_update];
end
for j=1:counter
Gamma_update = [H(:,:,j) Gamma_update];
end
Gamma = [Gamma ; Gamma_update];
counter = counter 1;
end
end