$\mathbf{ A+B=B+A}$ | komutatif |
$\mathbf{A+0=0+A}$ | identitas |
$\mathbf{A+(-A)=0}$ | invers |
$\mathbf{ A+(B+C)=(A+B)+C }$ | assosatif |
$\mathbf{ (A+B)^T = A^T + B^T }$ | distributif transpus |
>x<-seq(1,10,1) >xmat<-matrix(x,2,5) >ymat<-matrix(x,5,2) >xmat [,1] [,2] [,3] [,4] [,5] [1,] 1 3 5 7 9 [2,] 2 4 6 8 10 > ymat [,1] [,2] [1,] 1 6 [2,] 2 7 [3,] 3 8 [4,] 4 9 [5,] 5 10
>data(cars) >x<-as.matrix(cars) >dim(x) [1] 50 2 >amat<-x%*%t(x) >bmat<-t(x)%*%x >dim(amat) [1] 50 50 >dim(bmat) [1] 2 2
>matrix(0,2,3) [,1] [,2] [,3] [1,] 0 0 0 [2,] 0 0 0 >matrix(1,2,3) [,1] [,2] [,3] [1,] 1 1 1 [2,] 1 1 1 >
> diag(1,3) [,1] [,2] [,3] [1,] 1 0 0 [2,] 0 1 0 [3,] 0 0 1 > diag(2,3) [,1] [,2] [,3] [1,] 2 0 0 [2,] 0 2 0 [3,] 0 0 2 >diag(c(1,2,3,4,5)) [,1] [,2] [,3] [,4] [,5] [1,] 1 0 0 0 0 [2,] 0 2 0 0 0 [3,] 0 0 3 0 0 [4,] 0 0 0 4 0 [5,] 0 0 0 0 5Sebaliknya jika diag()dilakukan pada matrik bujur sangkar, maka fungsi ini akan mengekstrak diagonal matriks tersebut.
> diag(bmat) speed dist 13228 124903
» xmat%*%ymat [,1] [,2] [1,] 95 220 [2,] 110 260 >det(xmat%*%ymat) [1] 500 > solve(xmat%*%ymat) [,1] [,2] [1,] 0.52 -0.44 [2,] -0.22 0.19 » det(ymat%*%xmat) [1] 0 » solve(ymat%*%xmat) #tes walau kita tahu det=0.s Error in ... system is exactly singular