0
$\begingroup$

I would like to create an array of length n with each element i equal to the function

σEk[j_, k_, n_] := 
 Insert[ConstantArray[IdentityMatrix[2], n - 1], PauliMatrix[j], k ]

evaluated at k=i, i.e.

σEklist[j_, n_] := {σEk[j, 1, n], σEk[j, 2, n], ..., σEk[j, n, n]}

I tried using the Mathematica function for one-variable functions, Array[f,n] = {f[i], ..., f[n]}, using:

σEklist[j_, n_] := Array[σEk, n]

and I also tried to define σEk[j, k, n] as a function of the variable k only within the function σEklist[j_, n_] using Module, i.e.

σEklist[j_, n_] := 
 Module[{f[k_] := σEk[j, k, n]}, Array[f, n]]

but in each case the function σEklist[j_, n_] doesn't read the n and j variables in the function σEk[j, k, n] as being its own variables.

Any help or tips would be appreciated, thanks.

$\endgroup$
1
  • $\begingroup$ Like this σEklist[j_, n_] := Array[σEk[j,#,n]&, n]? $\endgroup$
    – swish
    Nov 4, 2019 at 18:19

1 Answer 1

1
$\begingroup$
Clear["Global`*"]

σEk[j_Integer?(0 <= # <= 4 &), k_Integer?Positive, 
  n_Integer?Positive] :=
 Insert[ConstantArray[IdentityMatrix[2], n - 1], PauliMatrix[j], k]

σEklist[j_Integer?(0 <= # <= 4 &), 
  n_Integer?Positive] := σEk[j, #, n] & /@ Range[n]

or

σEklist2[j_Integer?(0 <= # <= 4 &), n_Integer?Positive] :=
 Array[σEk[j, #, n] &, n]

σEklist and σEklist2 are equivalent

And @@ (Table[σEklist[j, n] == σEklist2[j, n], {j, 0, 4}, {n, 1,
      5}] // Flatten)

(* True *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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