Re: Kronecker product of matrices
- To: mathgroup at smc.vnet.net
- Subject: [mg18518] Re: [mg18429] Kronecker product of matrices
- From: Markus van Almsick <m.van.almsick at cityweb.de>
- Date: Thu, 8 Jul 1999 22:32:54 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Here is a solution to the following: >Is there a simple way to make Outer[Times,A,B] produce the Kronecker >product of A and B? What I mean is that if A is nxn and B mxm, Outer >produces a block form, instead of a plain (mn)x(mn) matrix. Ciao, Markus van Almsick (*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 4.0, MathReader 4.0, or any compatible application. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info at wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. ***********************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 3455, 119]*) (*NotebookOutlinePosition[ 4326, 147]*) (* CellTagsIndexPosition[ 4282, 143]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Kronecker Sum and Kronecker Product", "Title", AspectRatioFixed->False, ImageRegion->{{0, 1}, {0, 1}}], Cell["Markus van Almsick", "Subsubtitle"], Cell[CellGroupData[{ Cell["Implementation", "Section"], Cell[BoxData[ \(\(SquareMatrixQ[mat_]\ := \ MatrixQ[mat]\ && \ Apply[SameQ, \(Dimensions[mat]\)[\([{1, 2}]\)]];\)\)], "Input", InitializationCell->True], Cell["\<\ KroneckerFlatten[mat_] := \ Flatten[Map[Flatten[#,1]&,Transpose[mat,{1,3,2}],{2}],1] /; \ MatrixQ[mat,MatrixQ];\ \>", "Input", InitializationCell->True, AspectRatioFixed->False, ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ KroneckerTimes[mat1_?MatrixQ,mat2_?MatrixQ] := \ DirectFlatten[Outer[Times,mat1,mat2]];\ \>", "Input", InitializationCell->True, ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ KroneckerPlus[mat1_?SquareMatrixQ,mat2_?SquareMatrixQ] := \ KroneckerFlatten[Outer[Times,mat1,IdentityMatrix[Length[mat2]]] + \tOuter[Times,IdentityMatrix[Length[mat1]],mat2]];\ \>", "Input", InitializationCell->True, AspectRatioFixed->False, ImageRegion->{{0, 1}, {0, 1}}] }, Closed]], Cell[CellGroupData[{ Cell["Example", "Section"], Cell[BoxData[ \(\((A\ = \ Array[\((a\_\(SequenceForm[##]\))\) &, {3, 3}])\)\ // MatrixForm\)], "Input"], Cell[BoxData[ \(\((B\ = \ Array[\((b\_\(SequenceForm[##]\))\) &, {4, 4}])\)\ // \ MatrixForm\)], "Input"], Cell[BoxData[ \(Outer[Times, A, B] // MatrixForm\)], "Input"], Cell[BoxData[ \(KroneckerFlatten[Outer[Times, A, B]] // MatrixForm\)], "Input"], Cell[BoxData[ \(KroneckerTimes[A, B] // MatrixForm\)], "Input"], Cell[BoxData[ \(KroneckerPlus[A, B] // MatrixForm\)], "Input"] }, Closed]] }, Open ]] }, FrontEndVersion->"4.0 for Macintosh", ScreenRectangle->{{0, 1024}, {0, 748}}, AutoGeneratedPackage->None, WindowSize->{643, 616}, WindowMargins->{{9, Automatic}, {Automatic, 9}}, MacintoshSystemPageSetup->"\<\ 00<0001804P000000]P2:?oQon82n at 960dL5:0?l0080001804P000000]P2:001 0000I00000400`<300000BL?00400 at 0000000000000004P801T1T00000000000 00000000000000000000000000000000\>" ] (*********************************************************************** Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. ***********************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1739, 51, 112, 2, 136, "Title"], Cell[1854, 55, 41, 0, 53, "Subsubtitle"], Cell[CellGroupData[{ Cell[1920, 59, 33, 0, 50, "Section"], Cell[1956, 61, 180, 4, 39, "Input", InitializationCell->True], Cell[2139, 67, 224, 7, 54, "Input", InitializationCell->True], Cell[2366, 76, 173, 5, 39, "Input", InitializationCell->True], Cell[2542, 83, 289, 7, 69, "Input", InitializationCell->True] }, Closed]], Cell[CellGroupData[{ Cell[2868, 95, 26, 0, 30, "Section"], Cell[2897, 97, 116, 2, 28, "Input"], Cell[3016, 101, 118, 2, 28, "Input"], Cell[3137, 105, 65, 1, 27, "Input"], Cell[3205, 108, 83, 1, 27, "Input"], Cell[3291, 111, 67, 1, 27, "Input"], Cell[3361, 114, 66, 1, 27, "Input"] }, Closed]] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)