# Tensors constructed using KroneckerDelta's - and/or displaying KroneckerDelta as a matrix

I am doing some work in elasticity and as a result am working with tensors. In particular, I would like to calculate the contraction of a fourth order tensor (the stiffness tensor) with a second order tensor (the velocity gradient) to get another tensor (the time derivative of the stress, for anyone interested).

For my material, the stiffness tensor is easily written down in terms of products of Kronecker Delta Functions such as $\delta_{ij}\delta_{kl}$. I can then easily compute the contraction by manually entering the second order tensor of interest, and using Sum in combination with Part to extract the result.

The problem is that, naturally, Mathematica displays the output in terms of KroneckerDelta[3, i], for example, and there's a lot of them - it's essentially writing the matrix out elementwise using delta functions. Is there a way I can easily view this as a matrix, or map them to a matrix, or alternatively, approach this problem from a different perspective which would avoid this issue altogether? I am trying to apply something along the lines of the following to my expression:

Replace[KroneckerDelta[i, j], KroneckerDelta[i, j] -> TensorProduct[Part[IdentityMatrix[3], i], Part[IdentityMatrix[3], j]]]

If this were valid Mathematica code, it would work in theory, but I get the error The expression i cannot be used as a part specification. along with the same for j.

• The tensors you speak of do not have definite dimensions? – J. M. will be back soon Jul 19 '16 at 17:11
• They do, what do you mean by that? – The Wind-Up Bird Jul 19 '16 at 17:29
• Do you have definite tensors like SparseArray[{k_, k_, k_} -> 1, {3, 3, 3}] or are you just manipulating symbolic tensors? – J. M. will be back soon Jul 19 '16 at 17:30
• I'm not sure I know the difference. I have the definite tensors analytically, but I have input the tensors basically as a function defined using KroneckerDelta as, for example, stiff[i_, j_, k_, l_] = L KroneckerDelta[i, j] KroneckerDelta[k, l] + \[Mu] (KroneckerDelta[i, k] KroneckerDelta[j, l] + KroneckerDelta[i, l] KroneckerDelta[j, k]) – The Wind-Up Bird Jul 19 '16 at 17:49
• Try SparseArray[{{i_, j_, k_, l_} :> L KroneckerDelta[i, j] KroneckerDelta[k, l] + μ (KroneckerDelta[i, k] KroneckerDelta[j, l] + KroneckerDelta[i, l] KroneckerDelta[j, k])}, {3, 3, 3, 3}]. Consider reading the docs for SparseArray[] and SymmetrizedArray[] too, while you're at it. – J. M. will be back soon Jul 19 '16 at 19:19

As far as I understood from your answers to comments you like KronekerDelta in the stiffness tensor, but not in the stress tensor. You can do as follows:

stiff[i_, j_, k_, l_] :=
L KroneckerDelta[i, j] KroneckerDelta[k,
l] + \[Mu] (KroneckerDelta[i, k] KroneckerDelta[j, l] +
KroneckerDelta[i, l] KroneckerDelta[j, k])
vg = Array[v, {3, 3}];
vg // MatrixForm
stress[i_, j_] := Sum[stiff[i, j, k, l] vg[[k, l]], {k, 3}, {l, 3}]
stressT = Table[stress[i, j], {i, 3}, {j, 3}] // Simplify;
stressT // MatrixForm


$\begin{pmatrix} v(1,1) & v(1,2) & v(1,3) \\ v(2,1) & v(2,2) & v(2,3) \\ v(3,1) & v(3,2) & v(3,3) \\ \end{pmatrix}$
$\left(\begin{smallmatrix} 2 \mu v(1,1)+L (v(1,1)+v(2,2)+v(3,3)) & \mu (v(1,2)+v(2,1)) & \mu (v(1,3)+v(3,1)) \\ \mu (v(1,2)+v(2,1)) & 2 \mu v(2,2)+L (v(1,1)+v(2,2)+v(3,3)) & \mu (v(2,3)+v(3,2)) \\ \mu (v(1,3)+v(3,1)) & \mu (v(2,3)+v(3,2)) & 2 \mu v(3,3)+L (v(1,1)+v(2,2)+v(3,3)) \\ \end{smallmatrix}\right)$