I have a 2 by 2 matrix A = rand(2,2)
.
I have a 3d array of dimension 2 by 2 by 5.
Call it T
such that
T(:,:,1) = [1 2;3 4];
T(:,:,2) = [5 6;7 8];
T(:,:,3) = [12 11;10 9];
T(:,:,4) = [13 15;17 19];
T(:,:,5) = [21 22;23 28];
How can I do the operations of
J=zeros(2);
K=zeros(2);
for i = 1:5
J = J + T(:,:,i)'*A*T(:,:,i);
K = K + T(:,:,i)'*T(:,:,i);
end
by vectorization in the fastest way. I want to do it because the 3d array very huge dimension generally.