Module 6 Assignment

 










First, two small matrices are created and used to practice matrix addition and subtraction. These operations combine values based on their position in the matrix. Addition adds corresponding elements, while subtraction finds the difference between elements in the same row and column positions. This demonstrates how matrix arithmetic works element by element. Since we are creating a matrices using the matrix() function, R will fill the matrices by column. The matrices will look like this: 







By combining all the corresponding numbers to each column by adding, you will get the value of what it equals to in each spot. Matrix addition adds corresponding positions:

2 + 5 = 7

1 + 4 = 5

0 + 2 = 2

3 + (-1) = 2




Here we are doing the same thing to the matrix. Only this time we are subtracting the values in each box. Matrix subtraction subtracts corresponding elements:

2 - 5 = -3

1 - 4 = -3

0 - 2 = -2

3 - (-1) = 4





Next, the assignment uses the diag() function to build a diagonal matrix. A diagonal matrix places values along the main diagonal (from top left to bottom right) while all other entries are zero. This step shows how R can quickly generate structured matrices without manually entering every value. By using the diag() function, it places the provided values on the main diagonal and fills all other positions with 0. 







Finally, a larger matrix is constructed by starting with a diagonal matrix and then modifying specific rows and columns. The diagonal values are set first, and then indexing is used to fill the first row and first column with new values. This demonstrates how matrices can be built efficiently and customized by targeting exact positions. Using the diag(3,5) system, it creates a 5 x 5 matrix with 3s on the diagonal. The first row (except the first element) was filled with 1s. The first column (except the first element) was filled with 2s. With everything together, is build the entire matrix step by step.

Summary:

This assignment focused on practicing the basic matrix operations in R. The goal is to understand how matrices are created, manipulated, and customized using built-in functions and indexing. Overall, the assignment demonstrates three key ideas:

  • how matrix arithmetic works,

  • how to create structured matrices using built-in functions,

  • how to modify specific parts of a matrix using indexing.

These skills are foundational for working with data, performing mathematical computations, and understanding matrix-based operations used in statistics, data analysis, and programming.


GutHub: nbrown022/r-programming-assignments: Naomi Brown

Comments

Popular posts from this blog

Module 5

Module 3 Assignment

Assignment #10: Building Your Own R Package