Tensor applications in physics class with Mathematica

Hee-Joong Yun

Mathematica programs for the tensor calculations are presented. We have shown the calculation examples such as quadrupole moment tensor,  moment of inertia tensor, field tensors  (F^α)β and the others mostly appear in physics textbooks.

Introduction

The transformations between inertial frames that keep the velocity of light constant are known as Lorentz transformations. A Lorentz transformation relates the coordinates {t, x, y, z} of an event in S to the coordinates{t', x', y', z'} of the same event in another inertial frame S' by the 1st postulate of the special relativity. The 2nd postulate of relativity requires the equations to have the same form in all inertial coordinate systems. An equation written in a form-independent manner is said to be covariant. So the construction of a covariant equation leads to study of tensors. A scalar, the simplest of all tensors, is trivially invariant under coordinate transformations. Tensors are mathematical objects that give generalization of vectors and matrices[1-6]. In Mathematica, a tensor is presented as a set of lists, nested to a certain number of levels.  The  ranks of the tensor are:

In the study of physics in undergraduate or graduate course, most objects include scalar, vector, and tensor analysis. Namely, tensor analysis is a basic fundamental tool in studying physics overall course. However, the educational status of college recently, it is seldom to study the tensor analysis in the under or graduate course of physics because of put more weights to application parts of college education. In the age of high technology in communication, it is an ineludible work to study tensor analysis for the working with phenomena of the special or general relativity. It is desirable to set of computer algebra system integrated with fast calculation engine such as Mathematica for the calculations for the high level mathematica problems. The computer algebra system Mathematica has been the frame work of several applications to perform tensor and vector calculations easily to use[5-8].  We emphasized that the mathematical intrinsic notation for tensor calculus, for tensor(include vector calculus) in particular, is surprisingly well suit to be implemented in a modern computer system like Mathematica. The notation for the inputs in the Mathematica is close to that found in textbooks. The work we present here is a Mathematica implementation to the subjects which including tensors in the physics textbooks. We shall show that the  implementation of Mathematica  into physic class would be a useful method to enhance the ability in learning or teaching physics[9-12].

Vector calculation with Mathematica

The segments of Mathematica codes shown below are  easy to understand for physicists  even though unfamiliarity  with Mathematica program if they were familiar with vector or tensor calculus.You will be recognize to illuminate the vector properties  and vector identities easily with Mathematica  system[5-6].

Vector algebra

<< Calculus`VectorAnalysis`;
<< Graphics`ParametricPlot3D`;
<< Graphics`PlotField`;

Clear["Global`*"];
SetCoordinates[Cartesian[x, y, z]]

Unprotect[C]

A = {2, -3, 4};
B = {1, -4, 1};
C = {1, -1, -1};

A . B

AA = Sqrt[A . A]; BB = Sqrt[B . B];

angle = 
      N[ArcCos[ A . (B/(AA BB))]*(180/Pi)] "°"

A\[Cross]B

(A\[Cross]B)\[Cross]C

A \[Cross](B\[Cross]C)

B (A . C) - C (A . B)

A \[Cross](B\[Cross]C) == B (A . C) - C (A . B)

A . B\[Cross]C
C . A\[Cross]B
B . C\[Cross]A

The following five vector identities were testified easily with Mathematica.  Observe  the Mathematica code followed answer, you would understand the program even if  you were unfamiliar with Mathematica program.

Solutions

a = {ax[x, y, z], ay[x, y, z], 
          az[x, y, z]};
b = {bx[x, y, z], by[x, y, z], bz[x, y, z]};
c = {cx[x, y, z], cy[x, y, z], cz[x, y, z]};
f = func[x, y, z];

1.   (Overscript[∇, ⇀])·( (Overscript[∇, ⇀])×A) = 0

Div[Curl[a]]

2.   (Overscript[∇, ⇀])×( (Overscript[∇, ⇀]) 
                f) = 0

Curl[Grad[f]]

3.   (Overscript[∇, ⇀])·(fA) = 
      f ( (Overscript[∇, ⇀])·A) + 
        A·( (Overscript[∇, ⇀]) f)

(Div[f a] - f Div[a] - Dot[a, Grad[f]]) // Simplify

4.   ∇×(∇ × A) = ∇(∇·A) - (∇^2) A

Curl[Curl[a]] - Grad[Div[a]] + Laplacian /@ a

5.   A×(B × C) = 
      B (A . C) - C (A . B)

Cross[a, Cross[b, c]] - b Dot[a, c] +  c Dot[a, b] // 
      Simplify

Clear[a, b, c, f]

Mathematica represents vectors and matrices by lists and nested lists, respectively; for the matrix m,Transpose[m], Eigenvalues[m], Eigenvectors[m], and MatrixForm[list] are utilized for the matrix calculations. Especially Eigenvalues[m] and Eigenvectors[m] are useful for physicists.

samplevector = {x, y}
samplematrix = {{a, b}, {c, d}}

samplematrix . samplevector // MatrixForm

m1 = {{2, 0, -2}, {-2 I, I, 2  I}, {1, 
            0, -1}};
Eigenvalues[m1]
Eigenvectors[m1]

hermitian = (1/(Sqrt[2])) {{0, -I, 0}, {I, 0, -I}, {0, I, 
              0}};
hermitiandagga = 
        Conjugate[Transpose[hermitian]];
Eigenvalues[hermitian]
hermitian == hermitiandagga

hermitian // MatrixForm
hermitiandagga // MatrixForm

Thus the hermitian is a Hermitian operator since  its eigenvalues are real .

m =.

Creating and testing the structure of tensor

Tensors are mathematical objects that give generalizations of vectors and matrices. In Mathematica, tensor is represented  as a set of lists,  nested to a certain number of levels[8]. The nesting level is the rank of the tensor. A tensor of rank is essentially a k-dimensional table of values. To be a true rank k tensor, it must be  possible to arrange the elements in the table in a k-dimensional cuboidal array. There can be no holes or protrusions in the cuboid. The indices that specify a particular element in the tensors correspond to the coordinates in cuboid. In physics, the tensors occur typically have indices which run over the possible directions in space or spacetime. Because the elements of (Subscript[n, 1])×(Subscript[n, 2])× ...  (Subscript[n, k]) are creating for rank k tensor, it is really hard work in listing the tensor elements with hand. It is desirable to creating the tensor in Mathematica system. Notice, however, that there is no built in notion of covariant and contravariant tensor indices in Mathematica : we should set these up explicitly using metric tensors. Our treatment of tensor with Mathematica somewhat crude. The treatment in Mathematica for the students, however, who needs to get a conception on the tensor creating and structure of tensors should be a helpful practice. The reader who needs to do a lot of tensor analysis should consider using a package such as MathTensor[7].  First, we introduce to make a tensor with Mathematica using a list manupulations like matrix generation. And we will show the  emthod to make some tensor apper in the typical textbooks. In this paper, quadrupole moment tensor, moment of inertia tensor and field tesor are presented as a examples.   You will find to understand easily the structure and creating of tensors if you have only to read the interactive Mathematica  codes.

t232 = 
      Table[i1 + i2  i3, {i1, 2}, {i2, 3}, {i3, 2}]

% // MatrixForm

t234 = 
      Table[i1 + i2 + i3, {i1, 2}, {i2, 3}, {i3, 4}] // 
        MatrixForm

t5432 = 
      Table[i1 + i2 + i3 + i4, {i1, 5}, {i2, 4}, {i3, 3}, {i4, 2}] // 
        MatrixForm

The above tensor shows his structure when they present in the MatrixForm in Mathematica. Tensor t232 shows 2××3 matrix with 2 rows, t234  2××3 matrix with 4 rows and  t5432 is 5××4 with 3××2 matrix.

s = a;
v = {a, b, c};
m = {{a, b}, {c, d}};
t1 = Table[i1 + i2  i3, {i1, 2}, {i2, 3}, {i3, 2}];
TensorRank[s]
TensorRank[v]
TensorRank[m]
TensorRank[t1]

It is convenient to transform a coordinate system into another system in Mathematica system. We have the examples for the vector calculation and proofs of the vector identities.

SetCoordinates[Spherical[r, ϑ, ϕ]]

Div[{r, 0, 0}]

Grad[(r^2) Cos[ϑ] ]

Curl[{r, 0, 0}]

Laplacian[1/r]

φ1 = -E0  r Cos[ϑ]  + ((K - 1)/(K + 2))  (a^3) (1/(r^2)) Cos[ϑ];
φ2 = -(3/(K+2 )) E0  r Cos[ϑ];
-Grad[φ1] // Simplify
-Grad[φ2] // Simplify

Coordinates[]

Clebsh-Gordan Coefficients calculation

We can calculate Clebsh-Gordan Coefficients and Wigner-3J Symbol directly in the Mathematica[4].

m2 = (1/2); j = j1 + (1/2); m1 = m - (1/2); 
    j2 = (1/2);
ClebschGordan[{j1, m1}, {j2, m2}, {j, m}]
ClebschGordan[{1/2, -1/2}, {1/2, -1/
          2}, {1, -1}]

ClebschGordan[{1/2, 1/2}, {1/2, -1/2}, {1, 0}]

Wigner - 3  J  = 
      ThreeJSymbol[{j, m}, {j + 1/2, -m - 1/2}, {1/2,  1/2}]

ThreeJSymbol[{1, 0}, {1, 0}, {2, 0}]

Calculation examples of tensors in textbooks

In the undergraduate course,  tensors appear in the physics texts such as quadrupole moment tensor, susceptivity, field tensor in the electromagnetism theory; moment of inertia tensor in the mechanics which commit to evaluation for clarifying the problems. We have shown the calculated  tensors among them as a calculation examples employing the Mathematica.

Quadrupole Moment Tensor [Reitz p48]

\(The\ quadrupole\ moment\ tensor\ Q\_ij\ in\ the\ potential\ of\ the\ multipole\ expansion\ of\ electric\ field\ is \((Reitz\ 2 - 52)\) 
      calculated\ in\ Mathematica\ as\ \(\(follows[1]\)\(.\)\)\)

\(TextForm\`Q\_ij = ∫\_v\((3  x\_i' x\_j' - \(δ\_ij\) 
                r'\^2)\) ρ \((r')\) 
          dv'\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\((Reitz\ 2 - 52)\)\(.\)\(\ \)\)\)

kdel[i_, j_] := 1 /; i == j;
kdel[i_, j_] := 0 /; i! ≠ j;

quadrupoleij = 
Table[
          Integrate
[ ρ (3 (Subscript[x, i]) (Subscript[x, j]) -  
                  kdel[i, j] (∑_(k = 1)^3) 
                      ((Subscript[x, k])^2)) , {(Subscript[x, 1 ]), 0, 
              1}, {(Subscript[x, 2 ]), 0, 1}, {(Subscript[x, 3 ]), 0, 
              1}]
                                                                         , {i, 3}, {j, 3}] // 
        MatrixForm

Moment of inertia tensor[Marion  p364]

As an example of the calculation of the elements of the inertia tensor, we consider a homogeneous cube of density  ρ, mass M,  and side of length b [2]. The inertia tensor for a cube will be written directly  with Mathematica code according to the equation as follows