Matrix: Product
Set matrix: X is a matrix with n rows and p columns, denoted as n x p. Y is a matrix with p x m.
C is constant number.
- Addition and subtraction of matrix
> (X<-matrix(c(1,3,0,2,0,20), ncol=2))
[,1] [,2]
[1,] 1 2
[2,] 3 0
[3,] 0 20
> (Y<-matrix(c(6,10,0,0,0,2), ncol=2))
[,1] [,2]
[1,] 6 0
[2,] 10 0
[3,] 0 2
> X+Y
[,1] [,2]
[1,] 7 2
[2,] 13 0
[3,] 0 22
> X-Y
[,1] [,2]
[1,] -5 2
[2,] -7 0
[3,] 0 18
|
- product of a constant number with a matrix
example:
R code:
> (X<-matrix(c(1,2,4,5), ncol=2))
[,1] [,2]
[1,] 1 4
[2,] 2 5
> 2*X
[,1] [,2]
[1,] 2 8
[2,] 4 10
- product of matrix, XnxpYpxm=Znxm
R code
> (X<-matrix(c(1,3,0,2,0,2), ncol=2))
[,1] [,2]
[1,] 1 2
[2,] 3 0
[3,] 0 2
> (Y<-matrix(c(2,0,4,1), ncol=2))
[,1] [,2]
[1,] 2 4
[2,] 0 1
> X%*%Y
[,1] [,2]
[1,] 2 6
[2,] 6 12
[3,] 0 2
- product of identity matrix with a matrix: IX=XI=X
I is a diagonal matrix whose diagonal entries are all ones. R code
> X
[,1] [,2]
[1,] 1 2
[2,] 3 0
[3,] 0 2
> (I=diag(1,3))
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 1 0
[3,] 0 0 1
> I%*%X
[,1] [,2]
[1,] 1 2
[2,] 3 0
[3,] 0 2
> (I=diag(1,2))
[,1] [,2]
[1,] 1 0
[2,] 0 1
> X%*%I
[,1] [,2]
[1,] 1 2
[2,] 3 0
[3,] 0 2
|
No comments:
Post a Comment