Math and Stats: Exercises


4. Matrix-matrix multiplication. The matrices, X and Y, have been defined for you. You can check the dimensions of a matrix in R with the dim() function.

In order to perform matrix multiplication, the number of columns of the first matrix must be equal to the number of rows of the second. Multiply the X and Y in the order that makes it a conformable operation using the %*% operation.


X <- matrix(c(1,0,0,0,1,0,0,0,1), nrow=3, ncol=3) Y <- matrix(c(1,2,3,4,5,6), nrow=3, ncol=2) # Compute the dimensions of X. ___(X) # Compute the dimensions of Y. ___ # Multiply X and Y in the correct order. ___ ___ ___ # Compute the dimensions of X. dim(X) # Compute the dimensions of Y. dim(Y) # Multiply X and Y in the correct order. X %*% Y test_error() test_function("dim", incorrect_msg="Did you use the `dim()` function?") success_msg("Excellent work. What happens if you switch the order of X and Y?")
You can use the dim() function to check a matrix's dimensions.

Previous Exercise Next Exercise