Re: tensor/matrix calculations
- To: mathgroup@smc.vnet.net
- Subject: [mg10359] Re: tensor/matrix calculations
- From: Paul Abbott <paul@physics.uwa.edu.au>
- Date: Mon, 12 Jan 1998 04:09:55 -0500
- Organization: University of Western Australia
- References: <694bpr$mqt@smc.vnet.net>
Jan-Willem Roorda wrote:
> How can I calculate the standard matrix product of two
> matrixrepresentations of a tensor. The dot . produkt does'nt work.
>
> Jan-Willem Roorda
For the Kronecker product you need to use Outer. Here is a simple
example:
In[1]:= << "LinearAlgebra`MatrixManipulation`" In[2]:= A = Table[a[i,
j], {i, 2}, {j, 2}]; In[3]:= B = Table[b[i, j], {i, 2}, {j, 2}];
In[4]:= BlockMatrix[Outer[Times, A, B]] Out[4]=
{{a[1, 1] b[1, 1], a[1, 1] b[1, 2], a[1, 2] b[1, 1],
a[1, 2] b[1, 2]}, {a[1, 1] b[2, 1], a[1, 1] b[2, 2],
a[1, 2] b[2, 1], a[1, 2] b[2, 2]},
{a[2, 1] b[1, 1], a[2, 1] b[1, 2], a[2, 2] b[1, 1],
a[2, 2] b[1, 2]}, {a[2, 1] b[2, 1], a[2, 1] b[2, 2],
a[2, 2] b[2, 1], a[2, 2] b[2, 2]}}
This was discussed in The Mathematica Journal 2(2):36-37 and 2(4):38. I
have appended a Notebook below which gives a better-formatted example
(using CircleTimes).
____________________________________________________________________
Paul Abbott Phone: +61-8-9380-2734
Department of Physics Fax: +61-8-9380-1014
The University of Western Australia Nedlands WA 6907
mailto:paul@physics.uwa.edu.au AUSTRALIA
http://www.pd.uwa.edu.au/~paul
God IS a weakly left-handed dice player
____________________________________________________________________
Notebook[{
Cell[CellGroupData[{
Cell["Kronecker Products", "Section"],
Cell[TextData[{
StyleBox["TMJ ",
FontSlant->"Italic"],
StyleBox["2",
FontWeight->"Bold"],
"(2):36-37, ",
StyleBox["2",
FontWeight->"Bold"],
"(4):38 (addendum), ",
StyleBox["1",
FontWeight->"Bold"],
"(3):59 (Distance matrices), Lewis Stiller" }], "Text"],
Cell[TextData[{
"The symbol \[CircleTimes] represents an ",
"infix",
" (and ",
"prefix",
") operator:"
}], "Text",
CellTags->"CircleTimes"],
Cell[CellGroupData[{
Cell[BoxData[
\(\(?\[CircleTimes]\)\)], "Input"],
Cell[BoxData[
\("An infix and prefix operator. \!\(x \[CircleTimes] y\) is by
default \
interpreted as \!\(CircleTimes[x, y]\) ; \!\(\[CircleTimes] x\) is by
default \
interpreted as \!\(CircleTimes[x]\)."\)], "Print"] }, Open ]],
Cell["However, there are no built-in rules for CircleTimes:", "Text"],
Cell[CellGroupData[{
Cell[BoxData[
\(\(?CircleTimes\)\)], "Input"],
Cell[BoxData[
\(Information::"notfound" \( : \ \)
"Symbol \!\(\"CircleTimes\"\) not found."\)], "Message"] }, Open
]],
Cell["\<\
Here is simple implementation of the matrix Kronecker product:\ \>",
"Text",
CellTags->{
"Kronecker product", "Direct product",
"LinearAlgebra`MatrixManipulation`",
"BlockMatrix", "Outer"}],
Cell[BoxData[
\(TraditionalForm\`<< LinearAlgebra`MatrixManipulation`\)],
"Input"],
Cell[BoxData[
\(TraditionalForm
\`a_\[CircleTimes]b_ := BlockMatrix[Outer[Times, a, b]]\)],
"Input"],
Cell[BoxData[
\(TraditionalForm
\`a_\[CircleTimes]b_ := BlockMatrix(Outer(Times, a, b))\)],
"Input"],
Cell["For example,", "Text"],
Cell[CellGroupData[{
Cell[BoxData[
\(TraditionalForm
\`\[ScriptCapitalA] = Table[\[ScriptA]\_\(i, j\), {i, 2}, {j,
2}]\)],
"Input"],
Cell[BoxData[
FormBox[
RowBox[{"(", GridBox[{
{\(\[ScriptA]\_\(1, 1\)\), \(\[ScriptA]\_\(1, 2\)\)},
{\(\[ScriptA]\_\(2, 1\)\), \(\[ScriptA]\_\(2, 2\)\)}
}], ")"}], TraditionalForm]], "Output"] }, Open ]],
Cell[CellGroupData[{
Cell[BoxData[
\(TraditionalForm
\`\[ScriptCapitalB] = Table[\[ScriptB]\_\(i, j\), {i, 2}, {j,
2}]\)],
"Input"],
Cell[BoxData[
FormBox[
RowBox[{"(", GridBox[{
{\(\[ScriptB]\_\(1, 1\)\), \(\[ScriptB]\_\(1, 2\)\)},
{\(\[ScriptB]\_\(2, 1\)\), \(\[ScriptB]\_\(2, 2\)\)}
}], ")"}], TraditionalForm]], "Output"] }, Open ]],
Cell[CellGroupData[{
Cell[BoxData[
\(TraditionalForm\`Outer[Times, \[ScriptCapitalA],
\[ScriptCapitalB]]\)],
"Input"],
Cell[BoxData[
FormBox[
InterpretationBox[
RowBox[{"(", GridBox[{
{
RowBox[{"(", GridBox[{
{\(\[ScriptA]\_\(1, 1\)\ \[ScriptB]\_\(1, 1\)\),
\(\[ScriptA]\_\(1, 1\)\ \[ScriptB]\_\(1, 2\)\)},
{\(\[ScriptA]\_\(1, 1\)\ \[ScriptB]\_\(2, 1\)\),
\(\[ScriptA]\_\(1, 1\)\ \[ScriptB]\_\(2, 2\)\)}
}], ")"}],
RowBox[{"(", GridBox[{
{\(\[ScriptA]\_\(1, 2\)\ \[ScriptB]\_\(1, 1\)\),
\(\[ScriptA]\_\(1, 2\)\ \[ScriptB]\_\(1, 2\)\)},
{\(\[ScriptA]\_\(1, 2\)\ \[ScriptB]\_\(2, 1\)\),
\(\[ScriptA]\_\(1, 2\)\ \[ScriptB]\_\(2, 2\)\)}
}], ")"}]},
{
RowBox[{"(", GridBox[{
{\(\[ScriptA]\_\(2, 1\)\ \[ScriptB]\_\(1, 1\)\),
\(\[ScriptA]\_\(2, 1\)\ \[ScriptB]\_\(1, 2\)\)},
{\(\[ScriptA]\_\(2, 1\)\ \[ScriptB]\_\(2, 1\)\),
\(\[ScriptA]\_\(2, 1\)\ \[ScriptB]\_\(2, 2\)\)}
}], ")"}],
RowBox[{"(", GridBox[{
{\(\[ScriptA]\_\(2, 2\)\ \[ScriptB]\_\(1, 1\)\),
\(\[ScriptA]\_\(2, 2\)\ \[ScriptB]\_\(1, 2\)\)},
{\(\[ScriptA]\_\(2, 2\)\ \[ScriptB]\_\(2, 1\)\),
\(\[ScriptA]\_\(2, 2\)\ \[ScriptB]\_\(2, 2\)\)}
}], ")"}]}
}], ")"}],
MatrixForm[ {{{{
Times[
Subscript[ \[ScriptA], 1, 1],
Subscript[ \[ScriptB], 1, 1]],
Times[
Subscript[ \[ScriptA], 1, 1],
Subscript[ \[ScriptB], 1, 2]]}, {
Times[
Subscript[ \[ScriptA], 1, 1],
Subscript[ \[ScriptB], 2, 1]],
Times[
Subscript[ \[ScriptA], 1, 1],
Subscript[ \[ScriptB], 2, 2]]}}, {{
Times[
Subscript[ \[ScriptA], 1, 2],
Subscript[ \[ScriptB], 1, 1]],
Times[
Subscript[ \[ScriptA], 1, 2],
Subscript[ \[ScriptB], 1, 2]]}, {
Times[
Subscript[ \[ScriptA], 1, 2],
Subscript[ \[ScriptB], 2, 1]],
Times[
Subscript[ \[ScriptA], 1, 2],
Subscript[ \[ScriptB], 2, 2]]}}}, {{{
Times[
Subscript[ \[ScriptA], 2, 1],
Subscript[ \[ScriptB], 1, 1]],
Times[
Subscript[ \[ScriptA], 2, 1],
Subscript[ \[ScriptB], 1, 2]]}, {
Times[
Subscript[ \[ScriptA], 2, 1],
Subscript[ \[ScriptB], 2, 1]],
Times[
Subscript[ \[ScriptA], 2, 1],
Subscript[ \[ScriptB], 2, 2]]}}, {{
Times[
Subscript[ \[ScriptA], 2, 2],
Subscript[ \[ScriptB], 1, 1]],
Times[
Subscript[ \[ScriptA], 2, 2],
Subscript[ \[ScriptB], 1, 2]]}, {
Times[
Subscript[ \[ScriptA], 2, 2],
Subscript[ \[ScriptB], 2, 1]],
Times[
Subscript[ \[ScriptA], 2, 2],
Subscript[ \[ScriptB], 2, 2]]}}}}, TableDepth -> 2]],
TraditionalForm]], "Output"]
}, Open ]],
Cell[CellGroupData[{
Cell[BoxData[
\(TraditionalForm
\`\[ScriptCapitalA]\[ScriptCapitalB] =
\[ScriptCapitalA]\[CircleTimes]\[ScriptCapitalB]\)], "Input"],
Cell[BoxData[
FormBox[
RowBox[{"(", GridBox[{
{\(\[ScriptA]\_\(1, 1\)\ \[ScriptB]\_\(1, 1\)\),
\(\[ScriptA]\_\(1, 1\)\ \[ScriptB]\_\(1, 2\)\),
\(\[ScriptA]\_\(1, 2\)\ \[ScriptB]\_\(1, 1\)\),
\(\[ScriptA]\_\(1, 2\)\ \[ScriptB]\_\(1, 2\)\)},
{\(\[ScriptA]\_\(1, 1\)\ \[ScriptB]\_\(2, 1\)\),
\(\[ScriptA]\_\(1, 1\)\ \[ScriptB]\_\(2, 2\)\),
\(\[ScriptA]\_\(1, 2\)\ \[ScriptB]\_\(2, 1\)\),
\(\[ScriptA]\_\(1, 2\)\ \[ScriptB]\_\(2, 2\)\)},
{\(\[ScriptA]\_\(2, 1\)\ \[ScriptB]\_\(1, 1\)\),
\(\[ScriptA]\_\(2, 1\)\ \[ScriptB]\_\(1, 2\)\),
\(\[ScriptA]\_\(2, 2\)\ \[ScriptB]\_\(1, 1\)\),
\(\[ScriptA]\_\(2, 2\)\ \[ScriptB]\_\(1, 2\)\)},
{\(\[ScriptA]\_\(2, 1\)\ \[ScriptB]\_\(2, 1\)\),
\(\[ScriptA]\_\(2, 1\)\ \[ScriptB]\_\(2, 2\)\),
\(\[ScriptA]\_\(2, 2\)\ \[ScriptB]\_\(2, 1\)\),
\(\[ScriptA]\_\(2, 2\)\ \[ScriptB]\_\(2, 2\)\)}
}], ")"}], TraditionalForm]], "Output"] }, Open ]]
}, Open ]]
}
]