1.7 Problems
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.
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.
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).
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.
Build a \(4 \times 3\) matrix that is all 1s except a 2 in the (2,3) element (2nd row, 3rd column).
Take the transpose of the above.
Build a \(4 \times 4\) diagonal matrix with 1 through 4 on the diagonal.
Build a \(5 \times 5\) identity matrix.
Replace the diagonal in the above matrix with 2 (the number 2).
Build a matrix with 2 on the diagonal and 1s on the offdiagonals.
Take the inverse of the above.
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.Replace the diagonal of this matrix with the word “cat.”
Build a \(4 \times 3\) matrix with all 1s. Multiply by a \(3 \times 4\) matrix with all 2s.
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.
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}\).
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.
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).
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.
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}\).