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h2, Kh3, Kh4, Kh5, Kh6)
ThL(:,:,i) = circshift(T2,[0,i*3])
TrL(2,22) = -sind(alpha);
TrL(5,25) = -sind(alpha);
TrR(1,25) = cosd(-alpha);
TrR(1,26) = sind(-alpha);
TrR(2,25) = -sind(-alpha);
TrR(2,26) = cosd(-alpha);
TrR(4,28) = cosd(-alpha);
TrR(4,29) = sind(-alpha);
TrR(5,28) = -sind(-alpha);
TrR(5,29) = cosd(-alpha);
Th3(1,28) = cosd(-alpha);
Th3(1,29) = sind(-alpha);
Th3(2,28) = -sind(-alpha);
Th3(2,29) = cosd(-alpha);
Th3(4,31) = cosd(-alpha);
Th3(4,32) = sind(-alpha);
Th3(5,31) = -sind(-alpha);
Th3(5,32) = cosd(-alpha);
ThR(:,:,i) = circshift(Th3,[0,i*3])
(Relevant Code) for i = 1:5
KmhL(:,:,i) = ThL(:,:,i)'*Kh(i+1)*ThL(:,:,i);
KmhR(:,:,i) = ThR(:,:,i)'*Kh(6-i)*ThR(:,:,i);
Ks = KmhL(:,:,1) + KmhL(:,:,2) + KmhL(:,:,3)+ KmhL(:,:,4)+ KmhL(:,:,5)+ KmhR(:,:,1)+ KmhR(:,:,2)+KmhR(:,:,3)+KmhR(:,:,4)+KmhR(:,:,5) + Km1 + Km2 + Km3 + Km4 + Km5 + Km6
Ux = [0 0 U(1:46)' 0 0 U(47)]'