Tensor product 2 matrices - kronecker product

조회 수: 3 (최근 30일)
Dick Oosthuizen
Dick Oosthuizen 2019년 6월 26일
답변: Matt J 2019년 6월 29일
A question regarding the tensor product of 2 matrices, in combination with the Kronecker product.
I have 2 matrices: Qz and Qx.
Qx is Ns* Nx;
Qz is Ns * Nz.
Ns is the total states, consisting of all possible combinations of x and z (so Ns = Nx * Nz).
Lets say Ns = 14400; Nx = 3600; Nz = 4.
Then, I would like to multiply them using Tensor products, i.e. Q = Qz * Qx.
Is there any way to do this and to avoid to have a loop and apply the kron-function Ns times, to fill the matrix?
  댓글 수: 3
Dick Oosthuizen
Dick Oosthuizen 2019년 6월 26일
This is what I want, code:
Nstates = 6;
Qz = ones(Nstates, 2)*0.5;
Qx = linspace(1,Nstates*3, Nstates*3);
Qx = reshape(Qx, Nstates, 3);
Q = zeros(Nstates, Nstates);
for si = 1: Nstates
Q(si,:)= kron(Qz(si,:), Qx(si,:));
end
So the input is:
Qz =
0.5000 0.5000
0.5000 0.5000
0.5000 0.5000
0.5000 0.5000
0.5000 0.5000
0.5000 0.5000
Qx =
1 7 13
2 8 14
3 9 15
4 10 16
5 11 17
6 12 18
And then I do a Kronecker product of Qz times Qx, for each row of Qx.
So then the total matrix Q will be Ns*Ns, while Qz is Ns*Nz and Qx is Ns*Nx.
Q =
0.5000 3.5000 6.5000 0.5000 3.5000 6.5000
1.0000 4.0000 7.0000 1.0000 4.0000 7.0000
1.5000 4.5000 7.5000 1.5000 4.5000 7.5000
2.0000 5.0000 8.0000 2.0000 5.0000 8.0000
2.5000 5.5000 8.5000 2.5000 5.5000 8.5000
3.0000 6.0000 9.0000 3.0000 6.0000 9.0000
Dick Oosthuizen
Dick Oosthuizen 2019년 6월 29일
Do you know if there is a way to avoid the loop?

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2019년 6월 29일
Q=reshape(Qz,Ns,1,[]).*Qx;
Q=Q(:,:);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by