I have a Cartesian tensor $\chi_{ijk}$ and I want to express the elements in terms of a new basis to get $\chi_{ijk}^\prime$. The transformation is represented using $a_{ij}$. The tensor transforms as $\chi_{ijk}^\prime = a_{il}a_{jm}a_{kn}\chi_{lmn}$. Is there a way to implement this change of basis in Mathematica? I am new to tensors in general as well as their representation in Mathematica so any help is appreciated.


You can do it as follows:

X = Array[x, {3, 3, 3}];
A = Array[a, {3, 3}];

TensorContract[TensorProduct[A, A, A, X], {{2, 7}, {4, 8}, {6, 9}}]

Look at your expression A[i,l] A[j,m] A[k,n] X[l,m,n], count positions of repeated indices and you will see that each contraction pair corresponds to a repeated index.

However, there is a problem there: TensorProduct constructs a big intermediate array, and we don't need it. If your arrays have large dimensions, this intermediate array can be enormous. It can be avoided as follows:

Activate[TensorContract[Inactive[TensorProduct][A, A, A, X], {{2, 7}, {4, 8}, {6, 9}}]]

The idea is that Inactive prevents the construction of the intermediate array, but TensorContract knows what to do. It returns another Inactive[TensorProduct][...] expression, so we need to undo that with the final Activate.

| improve this answer | |
  • $\begingroup$ Thanks a lot! I was looking at using higher order tensors and this will help me save some computation time. $\endgroup$ – user27480 Oct 22 '14 at 22:19

I used the ideas from this post, Ways to compute inner products of tensors, to help in obtaining a solution. The main idea here is to transpose the tensor so that the indices in the original expression for $\chi^{\prime}_{ijk}$ are near each other then use the inner product. In Mathematica, use the transpose function to exchange the indices. The proper sequence in Mathematica code for changing the basis of a rank three tensor is:

T = Table[Subscript[t, i, j, k], {i, 3}, {j, 3}, {k, 3}];
R = Table[Subscript[r, i, j], {i, 3}, {j, 3}];
Tprime = Transpose[
R.Transpose[(R.Transpose[(R.Transpose[T, {3, 2, 1}]), {2, 1, 
     3}]), {3, 2, 1}], {1, 3, 2}];

R represents the rotation matrix, T represents the $3^{rd}$ rank tensor, and Tprime is the tensor in the new basis.

| improve this answer | |

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.