Kronecker product: Difference between revisions

(→‎{{header|VBScript}}: Section added)
Line 1,031:
└ ┘
</pre>
 
=={{header|VBScript}}==
<lang vb>' Kronecker product - 05/04/2017
dim a(),b(),r()
sub kroneckerproduct '(a,b)
m=ubound(a,1): n=ubound(a,2)
p=ubound(b,1): q=ubound(b,2)
rtn=m*p
ctn=n*q
redim r(rtn,ctn)
for i=1 to m
for j=1 to n
for k=1 to p
for l=1 to q
r(p*(i-1)+k,q*(j-1)+l)=a(i,j)*b(k,l)
next: next: next: next
end sub 'kroneckerproduct
sub printmatrix(text,m,w)
wscript.stdout.writeline text
select case m
case "a": ni=ubound(a,1): nj=ubound(a,2)
case "b": ni=ubound(b,1): nj=ubound(b,2)
case "r": ni=ubound(r,1): nj=ubound(r,2)
end select
for i=1 to ni
for j=1 to nj
select case m
case "a": k=a(i,j)
case "b": k=b(i,j)
case "r": k=r(i,j)
end select
wscript.stdout.write right(space(w)&k,w)
next
wscript.stdout.writeline
next
end sub 'printmatrix
sub printall(w)
printmatrix "matrix a:", "a", w
printmatrix "matrix b:", "b", w
printmatrix "kronecker product:", "r", w
end sub 'printall
sub main()
xa=array( 1, 2, _
3, 4)
redim a(2,2)
k=0: for i=1 to ubound(a,1): for j=1 to ubound(a,1)
a(i,j)=xa(k): k=k+1
next:next
xb=array( 0, 5, _
6, 7)
redim b(2,2)
k=0: for i=1 to ubound(b,1): for j=1 to ubound(b,1)
b(i,j)=xb(k): k=k+1
next:next
kroneckerproduct
printall 3
xa=array( 0, 1, 0, _
1, 1, 1, _
0, 1, 0)
redim a(3,3)
k=0: for i=1 to ubound(a,1): for j=1 to ubound(a,1)
a(i,j)=xa(k): k=k+1
next:next
xb=array( 1, 1, 1, 1, _
1, 0, 0, 1, _
1, 1, 1, 1)
redim b(3,4)
k=0: for i=1 to ubound(b,1): for j=1 to ubound(b,1)
b(i,j)=xb(k): k=k+1
next:next
kroneckerproduct
printall 2
end sub 'main
 
main</lang>
{{out}}
<pre>
matrix a:
1 2
3 4
matrix b:
0 5
6 7
kronecker product:
0 5 0 10
6 7 12 14
0 15 0 20
18 21 24 28
matrix a:
0 1 0
1 1 1
0 1 0
matrix b:
1 1 1
1 1 0
0 1 1
kronecker product:
0 0 0 0 1 1 1 0 0 0 0 0
0 0 0 0 1 1 0 0 0 0 0 0
0 0 0 0 0 1 1 0 0 0 0 0
1 1 1 0 1 1 1 0 1 1 1 0
1 1 0 0 1 1 0 0 1 1 0 0
0 1 1 0 0 1 1 0 0 1 1 0
0 0 0 0 1 1 1 0 0 0 0 0
0 0 0 0 1 1 0 0 0 0 0 0
0 0 0 0 0 1 1 0 0 0 0 0
</pre>
 
 
=={{header|zkl}}==
1,392

edits