Week 6: Doing Math P2

Hi everyone!

This week we learned more mathematical operations to use in matrices. A new function I learned is diag() which represents the number you choose in the top left to bottom right diagonal spots of the matrix. Similar to a data frame, you can select cells in a matrix using square brackets []. I utilized this to define numbers for spots in the matrix.

1. Consider A=matrix(c(2,0,1,3), ncol=2) and B=matrix(c(5,2,4,-1), ncol=2).
a) Find A + B
b) Find A - B











2. Using the diag() function to build a matrix of size 4 with the following values in the diagonal 4,1,2,3.






3. Generate the following matrix:

## [,1] [,2] [,3] [,4] [,5]
## [1,] 3 1 1 1 1
## [2,] 2 3 0 0 0
## [3,] 2 0 3 0 0
## [4,] 2 0 0 3 0
## [5,] 2 0 0 0 3
Hint: You can use the command diag() to build it.











Check this out in GitHub!
- Ramya's POV

Comments