I want to create a matrix of the form:

$X_\alpha = 1\otimes 1\otimes 1 ...\otimes X \otimes ... \otimes 1$

where $X$ is the Pauli $x$ matrix and is the $\alpha$th factor, and $1$ is the $2\times 2$ identity matrix. I have found answer on how to create a block diagonal matrices of this form for a specific placement of $X$ but I am trying to generalize it for an arbitrary $\alpha$.


See this book on page 53 (section 3.4.1):

SpinQ[S_] := IntegerQ[2S] && S>=0
op[S_?SpinQ, n_Integer, k_Integer, a_?MatrixQ] /;
               1<=k<=n && Dimensions[a] == {2S+1,2S+1} :=
  KroneckerProduct[IdentityMatrix[(2S+1)^(k-1), SparseArray],
                   IdentityMatrix[(2S+1)^(n-k), SparseArray]]

You'll be using S=1/2 and can simplify the above to

op[n_Integer, k_Integer, a_?MatrixQ] /;
             1<=k<=n && Dimensions[a] == {2,2} :=
  KroneckerProduct[IdentityMatrix[2^(k-1), SparseArray],
                   IdentityMatrix[2^(n-k), SparseArray]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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