<- matrix(1:16, nrow = 4, ncol = 4))
(A1 #> [,1] [,2] [,3] [,4]
#> [1,] 1 5 9 13
#> [2,] 2 6 10 14
#> [3,] 3 7 11 15
#> [4,] 4 8 12 16
<- matrix(1:20, nrow = 4, ncol = 5))
(B1 #> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 5 9 13 17
#> [2,] 2 6 10 14 18
#> [3,] 3 7 11 15 19
#> [4,] 4 8 12 16 20
<- matrix(1:40, nrow = 5, ncol = 8))
(A2 #> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#> [1,] 1 6 11 16 21 26 31 36
#> [2,] 2 7 12 17 22 27 32 37
#> [3,] 3 8 13 18 23 28 33 38
#> [4,] 4 9 14 19 24 29 34 39
#> [5,] 5 10 15 20 25 30 35 40
<- matrix(1:50, nrow = 10, ncol = 5))
(B2 #> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 11 21 31 41
#> [2,] 2 12 22 32 42
#> [3,] 3 13 23 33 43
#> [4,] 4 14 24 34 44
#> [5,] 5 15 25 35 45
#> [6,] 6 16 26 36 46
#> [7,] 7 17 27 37 47
#> [8,] 8 18 28 38 48
#> [9,] 9 19 29 39 49
#> [10,] 10 20 30 40 50
Lab 5
- Please ensure you review the document STAT 385 Lab 5 Help Document – Kronecker Product Illustration on Canvas or visit the weblink https://ycjiaweijia.github.io/F24STAT385/Lab5HelpDoc/Lab5HelpDoc.html for helpful guidance on this lab.
- Please complete the following questions and submit your Lab 5 to Gradescope.
Mathemetical Definition of Kronecker Product
In mathematics, the Kronecker product, sometimes denoted by
- You can find more information about Kronecker Product on Wikipedia https://en.wikipedia.org/wiki/Kronecker_product.
If
more explicitly,
Question 1
[20 pts] Please define the function forloop_kronecker()
, using for loop, to calculate the Kronecker product of matrices A and B with arbitrary dimensions.
Question 2
[20 pts] Please define the function vectorization_kronecker()
, using vectorization, to calculate the Kronecker product of matrices A and B with arbitrary dimensions.
Question 3
[20 pts] Compare the CPU times for three Kronecker product calculation methods below for matrices A1
and B1
, A2
and B2
, and other pairs of matrices you choose to test. Use times = 10000L
for each calculation. Discuss the computational efficiency of the three methods based on your findings.
vectorization_kronecker()
kronecker()
forloop_kronecker()