# What would be a good way to implement index notation?

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[[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[[i, k, j]] * n[[k]], {k, 1, dimensions}],
{i, dimensions}, {j, dimensions}, {k, dimensions}] // MatrixForm

• Consider giving a Working Minimal Example. – anderstood Sep 30 '15 at 20:43
• I have zero idea how to even start is the issue.... – laudiacay Sep 30 '15 at 20:44
• At the very least, write your definition in something Mathematica-like syntax – Dr. belisarius Sep 30 '15 at 20:48
• 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. – anderstood Sep 30 '15 at 21:09
• It should be adding in each iteration of k, as if it was adding a sum over k of that third term. – laudiacay Sep 30 '15 at 21:10

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[[i, k, j]]*n[[k]], {k, 1, 3}], {i,
3}, {j, 3}] // MatrixForm


which gives you a rotation matrix.

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[[i, k, j]] * n[[k]], {k, 1,
dimensions}], {i, dimensions}, {j, dimensions}] // MatrixForm

n = {0, 0, 1}
mat = Outer[Times, n, n]
+ Cos[θ] (IdentityMatrix - Outer[Times, n, n])
+ Sin[θ] Transpose[LeviCivitaTensor, {1, 3, 2}].n;
mat // MatrixForm 