Challenge - 5 Problems
Matrix Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Matrix multiplication output
What is the output of this R code that multiplies two matrices?
R Programming
A <- matrix(c(1, 2, 3, 4), nrow=2, byrow=TRUE) B <- matrix(c(2, 0, 1, 2), nrow=2, byrow=TRUE) result <- A %*% B print(result)
Attempts:
2 left
💡 Hint
Remember matrix multiplication sums the products of rows and columns.
✗ Incorrect
Matrix multiplication multiplies rows of the first matrix by columns of the second. For example, element (1,1) is 1*2 + 2*1 = 4.
🧠 Conceptual
intermediate1:30remaining
Why matrices are good for tabular math
Why do matrices naturally handle tabular math operations in programming?
Attempts:
2 left
💡 Hint
Think about how tables look and how matrices store data.
✗ Incorrect
Matrices organize data in rows and columns, just like tables, making math operations on rows and columns straightforward.
🔧 Debug
advanced2:30remaining
Fix the matrix multiplication error
This R code tries to multiply two matrices but gives an error. Which option shows the correct fix?
R Programming
A <- matrix(1:6, nrow=2) B <- matrix(1:4, nrow=2) result <- A %*% B print(result)
Attempts:
2 left
💡 Hint
Matrix multiplication requires the number of columns in the first matrix to equal the number of rows in the second.
✗ Incorrect
Matrix A has 2 rows and 3 columns, B has 2 rows and 2 columns. Columns of A (3) != rows of B (2). Option B changes B to have 3 columns (making it 2x3), so columns of A (3) == rows of B (3), fixing the error.
📝 Syntax
advanced1:30remaining
Identify the syntax error in matrix creation
Which option contains a syntax error when creating a matrix in R?
Attempts:
2 left
💡 Hint
Check the argument names for matrix dimensions.
✗ Incorrect
The correct argument names are 'nrow' and 'ncol'. Using 'rows' and 'cols' causes a syntax error.
🚀 Application
expert2:00remaining
Calculate the determinant of a matrix
What is the determinant of this matrix in R?
matrix <- matrix(c(4, 2, 3, 1), nrow=2)
det(matrix)
R Programming
matrix <- matrix(c(4, 2, 3, 1), nrow=2) det(matrix)
Attempts:
2 left
💡 Hint
Determinant of 2x2 matrix [[a,b],[c,d]] is ad - bc.
✗ Incorrect
For matrix [[4,3],[2,1]], determinant = 4*1 - 2*3 = 4 - 6 = -2.