Assignment 6
Assignment 6: Matrix Operations and Construction In this assignment, I practiced creating and manipulating matrices in R. The goal was to strengthen my understanding of how R handles matrix operations such as addition, subtraction, diagonal construction, and combining blocks of matrices to form structured arrays. R Code 🔹 Task 1: Matrix Addition & Subtraction # Task 1: define A and B A <- matrix(c(2, 0, 1, 3), ncol = 2) B <- matrix(c(5, 2, 4, -1), ncol = 2) # Addition A_plus_B <- A + B print("A + B:") print(A_plus_B) # Subtraction A_minus_B <- A - B print("A - B:") print(A_minus_B) 🔹 Task 2: Create a Diagonal Matrix # Task 2: Create a Diagonal Matrix D <- diag(c(4, 1, 2, 3)) print("Diagonal Matrix D:") print(D) 🔹 Task 3: Construct a Custom 5×5 Matrix # Task 3: Construct a Custom 5x5 Matrix # Step 1: create the first row row1 <- c(3, 1, 1, 1, 1) # Step 2: create the remaining rows: # - first column all 2’s (rows 2–5) # - diagonal...