Doing Math in R Part 2
1. Finding the sum and difference of these two matrices. A = matrix(c(2,0,1,3), ncol=2) and B = matrix(c(5,2,4,-1), ncol=2) a) Find A + B First, assign the matrices to a value, then assign a new value to represent the sum of both matrices. Run that value to get the new matrix of A + B. A <- matrix(c(2,0,1,3), ncol=2) B <- matrix(c(5,2,4,-1), ncol=2) AB_sum <- A + B AB_sum Result: [,1] [,2] [1,] 7 5 [2,] 2 2 b) Find A - B First, assign the matrices to a value, then assign a new value to represent the difference between the two matrices. Run that value to get the new matrix of A - B. A <- matrix(c(2,0,1,3), ncol=2) B <- matrix(c(5,2,4,-1), ncol=2) AB_dif <- A - B AB_dif Result: [,1] [,2] [1,] -3 -3 [2,] -2 4 2. Using the diag() function to build a matrix of size 4 with the follo...