C10 (LA, chapter M, pg 172)
Perform the following calculations on the matrices and scalars below:
\[\mathbf{A} = \left[\begin{array} {rrr} 1 & 4 & -3 \\ 6 & 3 & 0 \end{array}\right] \]
\[\mathbf{B} = \left[\begin{array} {rrr} 3 & 2 & 1 \\ -2 & 6 & 5 \end{array}\right] \]
\[\mathbf{C} = \left[\begin{array} {rrr} 2 & 4 \\ 4 & 0 \\ -2 & 2 \end{array}\right] \]
\[\alpha = 4\]
\[\beta = \frac{1}{2}\]
# Create matrices and set scalars
A <- matrix(c(1, 4, -3, 6, 3, 0), nrow = 2, ncol = 3, byrow = TRUE)
B <- matrix(c(3, 2, 1, -2, 6, 5), nrow = 2, ncol = 3, byrow = TRUE)
C <- matrix(c(2, 4, 4, 0, -2, 2), nrow = 3, ncol = 2, byrow = TRUE)
alpha = 4
beta = .5
A + B
## [,1] [,2] [,3]
## [1,] 4 6 -2
## [2,] 4 9 5
A + C
## Error in A + C: non-conformable arrays
The matrices cannot be summed as their dimension are different.
t(B) + C
## [,1] [,2]
## [1,] 5 2
## [2,] 6 6
## [3,] -1 7
A + t(B)
## Error in A + t(B): non-conformable arrays
The matrices cannot be summed as their dimension are different.
beta * C
## [,1] [,2]
## [1,] 1 2
## [2,] 2 0
## [3,] -1 1
4 * A - 3 * B
## [,1] [,2] [,3]
## [1,] -5 10 -15
## [2,] 30 -6 -15
t(A) + alpha * C
## [,1] [,2]
## [1,] 9 22
## [2,] 20 3
## [3,] -11 8
A + B - t(C)
## [,1] [,2] [,3]
## [1,] 2 2 0
## [2,] 0 9 3
4 * A + 2 * B - 5 * t(C)
## [,1] [,2] [,3]
## [1,] 0 0 0
## [2,] 0 24 0