# Suggest how to do this matrix multiplication [duplicate]

Have a look at the Mathematica calculation

z = {{1}, {0}};

o = {{0}, {1}};

Ψ = Sin[θ]*KroneckerProduct[z, z, z] +
Cos[θ]*KroneckerProduct[o, o, o] // MatrixForm

Ψt =
Transpose[{{Sin[θ]}, {0}, {0}, {0}, {0}, {0}, {0}, {Cos[θ]}}] // MatrixForm

ρ = Ψ.Ψt;

ρ // MatrixForm


After calculation at the last step we shall get a $6\times 6$ matrix ρ. But Mathematica is showing me $$\begin{bmatrix}\sin[\theta] \\ 0\\0\\0\\0\\0\\0\\ \cos[\theta]\end{bmatrix} . \begin{bmatrix} \sin[\theta] & 0 & 0 & 0 & 0 & 0 & 0& \cos[\theta]\end{bmatrix}$$

I like to get the in matrix form for farther calculations. Might be I have done some mistake, that I do not know. What changes to do?

• Welcome to Mathematica.SE! In case you didn't know, you can format your code better by putting four spaces at the front of every code block (or click on the curly-brace button above the question editing area). Further, wrap short inline code snippets in a pair of backticks . This will make your post easier to read. – user9660 Nov 9 '14 at 4:03

One problem is you're assigning the matrix form to your variable. Put matrix form on after setting your variable, e.g. MatrixForm[p = mat] not p = mat // MatrixForm.

z = {{1}, {0}};
o = {{0}, {1}};
MatrixForm[
p = Sin[t]*KroneckerProduct[z, z, z] +
Cos[t]*KroneckerProduct[o, o, o]]
MatrixForm[pt = Transpose[p]]
r = p.pt;
r // MatrixForm


Since you are comfortable with the Kronecker product, you might also be interested in the command Outer which can be used quite succinctly in this setting:

z = {1, 0};
o = {0, 1};
p = Flatten[Sin[t]*KroneckerProduct[z, z, z] +  Cos[t]*KroneckerProduct[o, o, o]];
mat = Outer[Times, p, p];
MatrixForm[mat]


which gives the desired form.

• Thank you. Your answer gave me something new to learn. – Dutta Nov 9 '14 at 4:45