Addition and Subtraction
x<-c(1,4,5,1,2,1)
y<-c(2,3,-2,1,2,2)
matrix1 <- matrix(x,3,2)
matrix2 <- matrix(y,3,2)
matrix1+matrix2
## [,1] [,2]
## [1,] 3 2
## [2,] 7 4
## [3,] 3 3
matrix1-matrix2
## [,1] [,2]
## [1,] -1 0
## [2,] 1 0
## [3,] 7 -1
Multiplication & Division
Z <-c(3, 9, 8, 4, 2, 6)
V <-c(5, 2, 5, 9, 3, 4)
matrix3 <- matrix(Z,2,3)
matrix4 <- matrix(V, 2,3)
matrix3*matrix4
## [,1] [,2] [,3]
## [1,] 15 40 6
## [2,] 18 36 24
matrix3/matrix4
## [,1] [,2] [,3]
## [1,] 0.6 1.6000000 0.6666667
## [2,] 4.5 0.4444444 1.5000000