This question already has an answer here:

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?

Thank you for your help.


marked as duplicate by rm -rf Nov 9 '14 at 4:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ 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. $\endgroup$ – 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}};
 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];

which gives the desired form.

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.