Posts

Showing posts from October, 2025

Assignment #6: Matrix Operations and Construction

Image
  1.)  A <- matrix(c(2, 0, 1, 3), ncol = 2) and B <- matrix(c(5, 2, 4, -1), ncol = 2) , ncol = 2 to tell r to create a matrix with 2 columns and fill the numbers in with "c()". A + B adds the numbers in that same spot,  for example the first numbers 1,1 is 2 and 5 = 7 because you are adding. A - B subtracts the numbers in that same spot, for example the first numbers 1,1 is 2 and 5 = -3 because you are subtracting. D <- diag(c(4, 1, 2, 3,)) creates a diagonal matrix where numbers go from top left to bottom right. So its telling R to create a matrix and put 4, 1, 2, 3 in a diagonal.  E <- cbind(c(3, 2, 2, 2, 2), diag(3, 5, 5)[,2:5]) this code tells R to create a diagonal with 3's in a 5x5 with diag(3, 5, 5) and [,2:5] is getting rid of the first column and keeping columns 2 through 5. What cbind does it combine the custom column which is (3, 2, 2, 2, 2) in front of the 2-5 columns we kept.