Tag Info

New answers tagged

11

The Pitsianis-Van Loan algorithm turns out to be surprisingly easy to implement in Mathematica: nearestKroneckerProduct[mat_?MatrixQ, dim1_?VectorQ, dim2_?VectorQ] /; TrueQ[Dimensions[mat] == dim1 dim2] := Module[{bv, cv, sig}, {bv, sig, cv} = SingularValueDecomposition[Flatten[ Map[Composition[Flatten, Transpose], ...


0

Some people (see The ubiquitous Kronecker product by Van Loan) have worked on finding two matrices $A, B$ of specified size whose tensor product $A \otimes B$ is closest (in a norm) to a given (larger) matrix $C$. That is, find $A, B$ which minimize $||C-A \otimes B||$. The algorithm is based on the SVD. There is a matlab implementation somewhere. It would ...


9

There is another option, using the relatively new tensor capabilities of Mathematica. This is pretty much copied from another answer by jose, but I don't need any assumptions here: TensorExpand[KroneckerProduct[X, X] + KroneckerProduct[-X, X]] (* ==> 0 *) TensorExpand[KroneckerProduct[2 X, 3 Y]] (* ==> 6 KroneckerProduct[X, Y] *) There is a ...


3

How about: av = Array[Subscript[a, ##] &, {2}]; bv = Array[Subscript[b, ##] &, {2}]; KroneckerProduct[av, bv] + KroneckerProduct[-av, bv] {{0, 0}, {0, 0}}


0

As used in a recent answer recent answer, one can easily define a function which contracts two tensors: DotAt[T_?TensorQ, U_?TensorQ, m_Integer?Positive, n_Integer?Positive] := With[{dimT = Length@Dimensions@T, dimU = Length@Dimensions@U}, Dot[Transpose[T, Insert[Range[dimT - 1], dimT, m]], Transpose[U, Insert[Range[2, dimU], 1, ...


2

You can define your tensor contraction routine using the builtins Dot and Transpose. Here is an example: DotAt[T_?TensorQ, U_?TensorQ, m_Integer?Positive, n_Integer?Positive] := With[{dimT = ArrayDepth@T, dimU = ArrayDepth@U}, Dot[Transpose[T, Insert[Range[dimT - 1], dimT, m]], Transpose[U, Insert[Range[2, dimU], 1, n]]]] DotAt[T, ...


1

In five days no one gave an answer, so I will post what I developed, although it is a poor solution: You can fill zeros of the tensor with variables that are not used, like z1,z2,z3,.... Now the derivative over this variables is zero, so I got desired result



Top 50 recent answers are included