Kronecker product: Difference between revisions
Content added Content deleted
(Added solution for Action!) |
(Frink) |
||
Line 1,542: | Line 1,542: | ||
[0 0 0 0 1 0 0 1 0 0 0 0] |
[0 0 0 0 1 0 0 1 0 0 0 0] |
||
[0 0 0 0 1 1 1 1 0 0 0 0]</pre> |
[0 0 0 0 1 1 1 1 0 0 0 0]</pre> |
||
=={{header|Frink}}== |
|||
The Frink library [https://frinklang.org/fsp/colorize.fsp?f=Matrix.frink Matrix.frink] contains an implementation of Kronecker product. The following example demonstrates calculating the Kronecker product and typesetting the equations using Frink's layout routines. |
|||
<lang frink>use Matrix.frink |
|||
a = new Matrix[ [[1,2],[3,4] ]] |
|||
b = new Matrix[ [[0,5],[6,7] ]] |
|||
println[formatProd[a,b]] |
|||
c = new Matrix[ [[0,1,0],[1,1,1],[0,1,0] ]] |
|||
d = new Matrix[ [[1,1,1,1],[1,0,0,1],[1,1,1,1]] ] |
|||
println[formatProd[c,d]] |
|||
formatProd[a,b] := formatTable[[[a.formatMatrix[], "\u2297", b.formatMatrix[], "=", a.KroneckerProduct[b].formatMatrix[]]]]</lang> |
|||
{{out}} |
|||
<pre> |
|||
┌ ┐ |
|||
┌ ┐ ┌ ┐ │ 0 5 0 10│ |
|||
│1 2│ │0 5│ │ 6 7 12 14│ |
|||
│3 4│ ⊗ │6 7│ = │ 0 15 0 20│ |
|||
└ ┘ └ ┘ │18 21 24 28│ |
|||
└ ┘ |
|||
┌ ┐ |
|||
│0 0 0 0 1 1 1 1 0 0 0 0│ |
|||
│0 0 0 0 1 0 0 1 0 0 0 0│ |
|||
┌ ┐ ┌ ┐ │0 0 0 0 1 1 1 1 0 0 0 0│ |
|||
│0 1 0│ │1 1 1 1│ │1 1 1 1 1 1 1 1 1 1 1 1│ |
|||
│1 1 1│ ⊗ │1 0 0 1│ = │1 0 0 1 1 0 0 1 1 0 0 1│ |
|||
│0 1 0│ │1 1 1 1│ │1 1 1 1 1 1 1 1 1 1 1 1│ |
|||
└ ┘ └ ┘ │0 0 0 0 1 1 1 1 0 0 0 0│ |
|||
│0 0 0 0 1 0 0 1 0 0 0 0│ |
|||
│0 0 0 0 1 1 1 1 0 0 0 0│ |
|||
└ ┘ |
|||
</pre> |
|||
=={{header|Fōrmulæ}}== |
=={{header|Fōrmulæ}}== |