Message Boards Message Boards

0
|
6317 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Contract a Rank Two Tensor with one Indice of another Rank Two Tensor

Posted 5 years ago

I am looking to take two rank two tensors and then contract one of the indices with one of the indices of the second tensor to get another rank two tensor, so something like

$A_{ij}B_{ik}=C_{jk}$

Could someone advise how I would do this in Mathematica?

POSTED BY: Hollis Williams
2 Replies
Posted 5 years ago

An alternative could be to use TensorProduct and TensorContract:

mA = {{a11, a12}, {a21, a22}};
mB = {{b11, b12}, {b21, b22}};

In[3]:= TensorContract[TensorProduct[mA, mB], {1, 3}]
Out[3]= {{a11 b11 + a21 b21, a11 b12 + a21 b22}, {a12 b11 + a22 b21, a12 b12 + a22 b22}}

Same result as with Sam's method:

In[4]:= Transpose[mA].mB
Out[4]= {{a11 b11 + a21 b21, a11 b12 + a21 b22}, {a12 b11 + a22 b21, a12 b12 + a22 b22}}
POSTED BY: Hans Milton
Posted 5 years ago

That is standard matrix multiplication, which you can do with the dot operator in Mathematica. Since the inner indices are summed over in matrix multiplication, you have to transpose A first.

Transpose[A].B

or, if you want to show the summation indices more explicitly, you can do something like

Table[Sum[A[[i, j]]*B[[i, k]], {i, 1, 3}], {j, 1, 3}, {k, 1, 3}]

the latter approach may generalize better for higher rank tensors

POSTED BY: Sam M
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract