Tensor product 2 matrices - kronecker product

3 visualizzazioni (ultimi 30 giorni)
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 Commenti
Dick Oosthuizen
Dick Oosthuizen il 26 Giu 2019
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 il 29 Giu 2019
Do you know if there is a way to avoid the loop?

Accedi per commentare.

Risposta accettata

Matt J
Matt J il 29 Giu 2019
Q=reshape(Qz,Ns,1,[]).*Qx;
Q=Q(:,:);

Più risposte (0)

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by