1
$\begingroup$

So I need to calculate a 3x3 rotation operator (basically a matrix). I have an index-notation expression, and I was wondering if with pre-calculated theta, K1, K2, and K3, could Mathematica compute each cell of this matrix for me?

The rotation operator M is defined as such, for i, j, and k from 1 to 3.

M(i,j) = K(i) * K(j) + cos(theta) * (kronecker_delta(i,j) - K(i)*K(j)) +
                       sin(theta) * (levi_civita_tensor(i,k,j) * K(k))

I tried something new:

n = {0, 0, 1}
mat = Table[
  n[[i]]*n[[j]] + 
   Cos[Theta] * (KroneckerDelta[i, j] - n[[i]]*n[[j]]) + 
   Sin[Theta] * LeviCivitaTensor[3][[i, k, j]] * n[[k]], 
   {i, 3}, {j, 3}, {k, 3}] (*//MatrixForm*)

The following output is pretty distinctly not a 3 * 3 matrix:

{{{Cos[Theta], Cos[Theta], Cos[Theta]}, {0, 0, -Sin[Theta]}, {0, 0, 
    0}}, {{0, 0, Sin[Theta]}, {Cos[Theta], Cos[Theta], Cos[Theta]}, {0,
    0, 0}}, {{0, 0, 0}, {0, 0, 0}, {1, 1, 1}}}

How do I fix this? I think it's iterating through k as if k were indices in the matrix.

Edit to the edit:

I tried summing k over the dimensions i needed, for some reason it's still being taken as a 3d matrix.

dimensions = 3
n = {0, 0, 1}
mat = Table[
    n[[i]]*n[[j]] + 
      Cos[Theta] * (KroneckerDelta[i, j] - n[[i]]*n[[j]]) + 
      Sum[Sin[Theta] * LeviCivitaTensor[3][[i, k, j]] * n[[k]], {k, 1, dimensions}], 
      {i, dimensions}, {j, dimensions}, {k, dimensions}] // MatrixForm
$\endgroup$
5
  • $\begingroup$ Consider giving a Working Minimal Example. $\endgroup$
    – anderstood
    Sep 30, 2015 at 20:43
  • $\begingroup$ I have zero idea how to even start is the issue.... $\endgroup$
    – laudiacay
    Sep 30, 2015 at 20:44
  • $\begingroup$ At the very least, write your definition in something Mathematica-like syntax $\endgroup$ Sep 30, 2015 at 20:48
  • $\begingroup$ In mat, the Table has three indices i,j,k resulting in a 3 by 3 by 3 table. It should have only two indices. $\endgroup$
    – anderstood
    Sep 30, 2015 at 21:09
  • $\begingroup$ It should be adding in each iteration of k, as if it was adding a sum over k of that third term. $\endgroup$
    – laudiacay
    Sep 30, 2015 at 21:10

3 Answers 3

2
$\begingroup$

You defined the function as if Mathematica was using Einstein summation convention. Make the summation on $k$ explicit:

n = {0, 0, 1}
mat = Table[
   n[[i]]*n[[j]] + Cos[Theta]*(KroneckerDelta[i, j] - n[[i]]*n[[j]]) +
     Sin[Theta]*
     Sum[LeviCivitaTensor[3][[i, k, j]]*n[[k]], {k, 1, 3}], {i, 
    3}, {j, 3}] // MatrixForm

which gives you a rotation matrix.

$\endgroup$
2
1
$\begingroup$

As it turns out, I was getting a 3x3x3 because it was working as if I was calculating the kth index of a matrix rather than just finding the sum of an expression with index notation. Adding a sum in there with the Tensor term worked this out fine.

ClearAll[dimensions, n, mat, i, j, k]
dimensions = 2
n = {1, 0}
mat = Table[
    n[[i]]*n[[j]] + 
     Cos[Theta] * (KroneckerDelta[i, j] - n[[i]]*n[[j]]) + 
      Sum[Sin[Theta] * LeviCivitaTensor[3][[i, k, j]] * n[[k]], {k, 1, 
       dimensions}], {i, dimensions}, {j, dimensions}] // MatrixForm
$\endgroup$
1
$\begingroup$
n = {0, 0, 1}
mat = Outer[Times, n, n]
       + Cos[θ] (IdentityMatrix[3] - Outer[Times, n, n])
       + Sin[θ] Transpose[LeviCivitaTensor[3], {1, 3, 2}].n;
mat // MatrixForm

enter image description here

$\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.