Skip to main content
added 107 characters in body
Source Link
jak
  • 950
  • 4
  • 14

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=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,a3a5,b2]. Thus replacing here Times->KroneckerProduct yields something nonsensible, because -1 is not a tensor.

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}};
 B={b1,b2,b3};
 x=TensorProduct[A,B];
 TensorContract[x,{1,3}];

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,a3,b2]. Thus replacing here Times->KroneckerProduct yields something nonsensible, because -1 is not a tensor.

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.

added 23 characters in body
Source Link
Jason B.
  • 70.2k
  • 3
  • 144
  • 298

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

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

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

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}};
 B={b1,b2,b3};
 x=TensorProduct[A,B];
 TensorContract[x,{1,3}];

and get instead of the ordinary Times between elements like a1b1 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,a3,b2]. Thus replacing here Times->KroneckerProduct yields something nonsensible, because -1 is not a tensor.

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}};
 B={b1,b2,b3};
 x=TensorProduct[A,B];
 TensorContract[x,{1,3}];

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,a3,b2]. Thus replacing here Times->KroneckerProduct yields something nonsensible, because -1 is not a tensor.

Source Link
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}};
 B={b1,b2,b3};
 x=TensorProduct[A,B];
 TensorContract[x,{1,3}];

and get instead of the ordinary Times between elements like a1b1 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,a3,b2]. Thus replacing here Times->KroneckerProduct yields something nonsensible, because -1 is not a tensor.