1.7 Problems

  1. Build a \(4 \times 3\) matrix with the numbers 1 through 3 in each column. Try the same with the numbers 1 through 4 in each row.

  2. Extract the elements in the 1st and 2nd rows and 1st and 2nd columns (you’ll have a \(2 \times 2\) matrix). Show the R code that will do this.

  3. Build a \(4 \times 3\) matrix with the numbers 1 through 12 by row (meaning the first row will have the numbers 1 through 3 in it).

  4. Extract the 3rd row of the above. Show R code to do this where you end up with a vector and how to do this where you end up with a \(1 \times 3\) matrix.

  5. Build a \(4 \times 3\) matrix that is all 1s except a 2 in the (2,3) element (2nd row, 3rd column).

  6. Take the transpose of the above.

  7. Build a \(4 \times 4\) diagonal matrix with 1 through 4 on the diagonal.

  8. Build a \(5 \times 5\) identity matrix.

  9. Replace the diagonal in the above matrix with 2 (the number 2).

  10. Build a matrix with 2 on the diagonal and 1s on the offdiagonals.

  11. Take the inverse of the above.

  12. Build a \(3 \times 3\) matrix with the first 9 letters of the alphabet. First column should be “a,” “b,” “c.” letters[1:9] gives you these letters.

  13. Replace the diagonal of this matrix with the word “cat.”

  14. Build a \(4 \times 3\) matrix with all 1s. Multiply by a \(3 \times 4\) matrix with all 2s.

  15. If \(\mathbf{A}\) is a \(4 \times 3\) matrix, is \(\mathbf{A} \mathbf{A}\) possible? Is \(\mathbf{A} \mathbf{A}^\top\) possible? Show how to write \(\mathbf{A}\mathbf{A}^\top\) in R.

  16. In the equation, \(\mathbf{A} \mathbf{B} = \mathbf{C}\), let \(\mathbf{A}=\left[ \begin{smallmatrix}1&4&7\\2&5&8\\3&6&9\end{smallmatrix}\right]\). Build a \(3 \times 3\) \(\mathbf{B}\) matrix with only 1s and 0s such that the values on the diagonal of \(\mathbf{C}\) are 1, 8, 6 (in that order). Show your R code for \(\mathbf{A}\), \(\mathbf{B}\) and \(\mathbf{A} \mathbf{B}\).

  17. Same \(\mathbf{A}\) matrix as above and same equation \(\mathbf{A} \mathbf{B} = \mathbf{C}\). Build a \(3 \times 3\) \(\mathbf{B}\) matrix such that \(\mathbf{C}=2\mathbf{A}\). So \(\mathbf{C}=\left[ \begin{smallmatrix}2&8&14\\ 4&10&16\\ 6&12&18\end{smallmatrix}\right]\). Hint, \(\mathbf{B}\) is diagonal.

  18. Same \(\mathbf{A}\) and \(\mathbf{A} \mathbf{B}=\mathbf{C}\) equation. Build a \(\mathbf{B}\) matrix to compute the row sums of \(\mathbf{A}\). So the first `row sum’ would be \(1+4+7\), the sum of all elements in row 1 of \(\mathbf{A}\). \(\mathbf{C}\) will be \(\left[ \begin{smallmatrix}12\\ 15\\ 18\end{smallmatrix}\right]\), the row sums of \(\mathbf{A}\). Hint, \(\mathbf{B}\) is a column matrix (1 column).

  19. Same \(\mathbf{A}\) matrix as above but now equation \(\mathbf{B} \mathbf{A} = \mathbf{C}\). Build a \(\mathbf{B}\) matrix to compute the column sums of \(\mathbf{A}\). So the first `column sum’ would be \(1+2+3\). \(\mathbf{C}\) will be a \(1 \times 3\) matrix.

  20. Let \(\mathbf{A} \mathbf{B}=\mathbf{C}\) equation but \(\mathbf{A}=\left[ \begin{smallmatrix}2&1&1\\1&2&1\\1&1&2\end{smallmatrix}\right]\) (so A=diag(3)+1). Build a \(\mathbf{B}\) matrix such that \(\mathbf{C}=\left[ \begin{smallmatrix}3\\ 3\\ 3\end{smallmatrix}\right]\). Hint, you need to use the inverse of \(\mathbf{A}\).