Challenge - 5 Problems
Matrix Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of matrix multiplication with compatible dimensions
What is the output of the following R code using matrix multiplication (%*%)?
R Programming
A <- matrix(c(1, 2, 3, 4), nrow=2, ncol=2, byrow=TRUE) B <- matrix(c(2, 0, 1, 3), nrow=2, ncol=2, byrow=TRUE) C <- A %*% B print(C)
Attempts:
2 left
💡 Hint
Remember matrix multiplication sums the products of rows of the first matrix with columns of the second.
✗ Incorrect
Matrix multiplication multiplies rows of A by columns of B and sums the products. For example, element (1,1) is 1*2 + 2*1 = 4.
❓ Predict Output
intermediate2:00remaining
Result of multiplying a matrix by a vector
What is the output of this R code multiplying a matrix by a vector using %*%?
R Programming
M <- matrix(c(1, 2, 3, 4, 5, 6), nrow=2, ncol=3, byrow=TRUE) v <- c(1, 0, -1) result <- M %*% v print(result)
Attempts:
2 left
💡 Hint
Multiply each row of the matrix by the vector elements and sum.
✗ Incorrect
M (with byrow=TRUE) is:
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
First row: 1*1 + 2*0 + 3*(-1) = -2
Second row: 4*1 + 5*0 + 6*(-1) = -2
❓ Predict Output
advanced2:00remaining
Output of matrix multiplication with incompatible dimensions
What happens when you try to multiply these two matrices with %*% in R?
R Programming
X <- matrix(1:6, nrow=2, ncol=3) Y <- matrix(1:4, nrow=2, ncol=2) Z <- X %*% Y
Attempts:
2 left
💡 Hint
Check if the number of columns in the first matrix equals the number of rows in the second.
✗ Incorrect
Matrix multiplication requires the number of columns in the first matrix to equal the number of rows in the second. Here, X has 3 columns but Y has 2 rows, so multiplication is not possible.
🧠 Conceptual
advanced1:30remaining
Understanding the dimensions of the product matrix
If matrix A is 4x3 and matrix B is 3x5, what will be the dimensions of A %*% B in R?
Attempts:
2 left
💡 Hint
The resulting matrix has the number of rows of the first and columns of the second.
✗ Incorrect
When multiplying matrices, the result has the number of rows of the first matrix and the number of columns of the second matrix.
❓ Predict Output
expert3:00remaining
Output of chained matrix multiplication with transposes
What is the output of this R code involving chained matrix multiplication and transpose?
R Programming
P <- matrix(c(1, 2, 3, 4), nrow=2) Q <- matrix(c(0, 1, 1, 0), nrow=2) R <- t(P) %*% Q %*% P print(R)
Attempts:
2 left
💡 Hint
Calculate t(P), then multiply by Q, then multiply by P, carefully following matrix multiplication rules.
✗ Incorrect
P is [[1,3],[2,4]], t(P) is [[1,2],[3,4]].
t(P) %*% Q = [[1*0+2*1, 1*1+2*0], [3*0+4*1, 3*1+4*0]] = [[2,1],[4,3]].
Then [[2,1],[4,3]] %*% P = [[2*1+1*2, 2*3+1*4], [4*1+3*2, 4*3+3*4]] = [[4,10],[10,24]].