Recall & Review
beginner
What does the operator %*% do in R?
The operator %*% performs matrix multiplication between two matrices or vectors in R. It multiplies rows of the first matrix by columns of the second matrix and sums the products.
Click to reveal answer
beginner
Given matrices A (2x3) and B (3x2), what will be the dimension of A %*% B?
The result will be a 2x2 matrix because the number of rows comes from A and the number of columns comes from B.
Click to reveal answer
intermediate
Why can't you multiply two matrices with %*% if the number of columns in the first doesn't equal the number of rows in the second?
Because matrix multiplication requires each element in a row of the first matrix to multiply with the corresponding element in a column of the second matrix. If sizes don't match, this pairing is impossible.
Click to reveal answer
beginner
How is matrix multiplication different from element-wise multiplication in R?
Matrix multiplication (%*%) multiplies rows by columns and sums products, producing a new matrix. Element-wise multiplication (*) multiplies corresponding elements directly without summing.
Click to reveal answer
beginner
What will be the output of this R code?<br>
A <- matrix(c(1,2,3,4), nrow=2)<br>B <- matrix(c(5,6,7,8), nrow=2)<br>A %*% B
The output will be a 2x2 matrix:<br>
[,1] [,2]<br>[1,] 19 22<br>[2,] 43 50<br>Explanation: Each element is the sum of products of rows of A and columns of B.
Click to reveal answer
What does the %*% operator do in R?
✗ Incorrect
The %*% operator multiplies matrices according to matrix multiplication rules.
If A is 3x2 and B is 2x4, what is the dimension of A %*% B?
✗ Incorrect
The result has rows from A and columns from B, so 3x4.
Which condition must be true to multiply matrices A and B with %*%?
✗ Incorrect
Matrix multiplication requires columns of A to match rows of B.
What is the difference between * and %*% in R?
✗ Incorrect
* multiplies elements one by one; %*% multiplies matrices properly.
What will happen if you try to multiply a 2x3 matrix by a 4x2 matrix using %*%?
✗ Incorrect
Number of columns in first (3) does not equal number of rows in second (4), so multiplication fails.
Explain how matrix multiplication works with the %*% operator in R.
Think about how each element in the result is calculated.
You got /3 concepts.
Describe the difference between element-wise multiplication (*) and matrix multiplication (%*%) in R.
Consider how the two operators treat the input matrices.
You got /3 concepts.