Kronecker product: Difference between revisions

Content deleted Content added
Laurence (talk | contribs)
Line 4,457: Line 4,457:


=={{header|VBScript}}==
=={{header|VBScript}}==
<syntaxhighlight lang="vb">' Kronecker product - 05/04/2017
<syntaxhighlight lang="vb">' Kronecker product - 05/04/2017 ' array boundary iteration corrections 06/13/2023
dim a(),b(),r()
dim a(),b(),r()
Line 4,474: Line 4,474:
end sub 'kroneckerproduct
end sub 'kroneckerproduct
sub printmatrix(text,m,w)
Private Sub printmatrix(text, m, w)
wscript.stdout.writeline text
wscript.stdout.writeline text
select case m
Dim myArr()
Select Case m
case "a": ni=ubound(a,1): nj=ubound(a,2)
case "b": ni=ubound(b,1): nj=ubound(b,2)
Case "a": myArr = a()
case "r": ni=ubound(r,1): nj=ubound(r,2)
Case "b": myArr = b()
Case "r": myArr = r()
end select
for i=1 to ni
End Select
for j=1 to nj
For i = LBound(myArr, 1) To UBound(myArr, 1)
select case m
text = vbNullString
case "a": k=a(i,j)
For j = LBound(myArr, 2) To UBound(myArr, 2)
case "b": k=b(i,j)
Select Case m
case "r": k=r(i,j)
Case "a": k = a(i, j)
end select
Case "b": k = b(i, j)
wscript.stdout.write right(space(w)&k,w)
Case "r": k = r(i, j)
next
End Select
wscript.stdout.writeline
text = text & " " & k
next
Next
wscript.stdout.writeline text
end sub 'printmatrix
Next
End Sub 'printmatrix

sub printall(w)
sub printall(w)
printmatrix "matrix a:", "a", w
printmatrix "matrix a:", "a", w
Line 4,501: Line 4,503:
sub main()
sub main()
xa=array( 1, 2, _
xa = Array(1, 2, _
3, 4)
3, 4)
ReDim a(LBound(xa, 1) To LBound(xa, 1) + 1, LBound(xa, 1) To LBound(xa, 1) + 1)
redim a(2,2)
k=0: for i=1 to ubound(a,1): for j=1 to ubound(a,1)
k = LBound(a, 1)
a(i,j)=xa(k): k=k+1
For i = LBound(a, 1) To UBound(a, 1): For j = LBound(a, 1) To UBound(a, 1)
a(i, j) = xa(k): k = k + 1
next:next
Next: Next
xb=array( 0, 5, _
6, 7)
xb = Array(0, 5, _
redim b(2,2)
6, 7)
k=0: for i=1 to ubound(b,1): for j=1 to ubound(b,1)
ReDim b(LBound(xb, 1) To LBound(xb, 1) + 1, LBound(xb, 1) To LBound(xb, 1) + 1)
b(i,j)=xb(k): k=k+1
k = LBound(b, 1)
For i = LBound(b, 1) To UBound(b, 1): For j = LBound(b, 2) To UBound(b, 2)
next:next
b(i, j) = xb(k): k = k + 1
Next: Next
kroneckerproduct
kroneckerproduct
printall 3
printall 3

xa=array( 0, 1, 0, _
xa = Array(0, 1, 0, _
1, 1, 1, _
1, 1, 1, _
0, 1, 0)
0, 1, 0)
ReDim a(LBound(xa, 1) To LBound(xa, 1) + 2, LBound(xa, 1) To LBound(xa, 1) + 2)
redim a(3,3)
k=0: for i=1 to ubound(a,1): for j=1 to ubound(a,1)
k = LBound(a, 1)
a(i,j)=xa(k): k=k+1
For i = LBound(a, 1) To UBound(a, 1): For j = LBound(a, 1) To UBound(a, 1)
a(i, j) = xa(k): k = k + 1
next:next
Next: Next
xb=array( 1, 1, 1, 1, _
1, 0, 0, 1, _
xb = Array(1, 1, 1, 1, _
1, 1, 1, 1)
1, 0, 0, 1, _
redim b(3,4)
1, 1, 1, 1)
k=0: for i=1 to ubound(b,1): for j=1 to ubound(b,1)
ReDim b(LBound(xb, 1) To LBound(xb, 1) + 2, LBound(xb, 1) To LBound(xb, 1) + 3)
b(i,j)=xb(k): k=k+1
k = LBound(b, 1)
For i = LBound(b, 1) To UBound(b, 1): For j = LBound(b, 2) To UBound(b, 2)
next:next
b(i, j) = xb(k): k = k + 1
Next: Next

kroneckerproduct
kroneckerproduct
printall 2
printall 2
Line 4,548: Line 4,555:
0 15 0 20
0 15 0 20
18 21 24 28
18 21 24 28

matrix a:
matrix a:
0 1 0
0 1 0
Line 4,553: Line 4,561:
0 1 0
0 1 0
matrix b:
matrix b:
1 1 1
1 1 1 1
1 1 0
1 0 0 1
0 1 1
1 1 1 1
kronecker product:
kronecker product:
0 0 0 0 1 1 1 0 0 0 0 0
0 0 0 0 1 1 1 1 0 0 0 0
0 0 0 0 1 1 0 0 0 0 0 0
0 0 0 0 1 0 0 1 0 0 0 0
0 0 0 0 0 1 1 0 0 0 0 0
0 0 0 0 1 1 1 1 0 0 0 0
1 1 1 0 1 1 1 0 1 1 1 0
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 0 0 1 1 0 0 1 1 0 0 1
0 1 1 0 0 1 1 0 0 1 1 0
1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 1 1 1 0 0 0 0 0
0 0 0 0 1 1 1 1 0 0 0 0
0 0 0 0 1 1 0 0 0 0 0 0
0 0 0 0 1 0 0 1 0 0 0 0
0 0 0 0 0 1 1 0 0 0 0 0
0 0 0 0 1 1 1 1 0 0 0 0
</pre>
</pre>