Skip to main content
3 of 3
added 107 characters in body
jak
  • 950
  • 4
  • 14

TensorContract with KroneckerProduct instead of ordinary Times

Is it possible somehow to contract two tensors, say A={{a1,a2,a3},{a4,a5,a6}} and B={b1,b2,b3}, where the elements a1,a2,...,b1,b2 are themselves vectors:

 A = {{a1, a2, -a3}, {a4, -a5, a6}, {a7, a8, a9}};
 B={b1,b2,b3};
 x=TensorProduct[A,B];
 TensorContract[x,{1,3}];

 (*{a1 b1 + a4 b2 + a7 b3, a2 b1 - a5 b2 + a8 b3, -a3 b1 + a6 b2 + a9 b3} *)

and get instead of the ordinary Times between elements like a1 b1 the KroneckerProduct[a1,b1]. A replacement rule like Times->KroneckerProduct does not work unfortunately, because a minus sign in Mathematica is handled as Times[-1,a5,b2]. Thus replacing here Times->KroneckerProduct yields something nonsensible, because -1 is not a tensor.

jak
  • 950
  • 4
  • 14