Soal 1
Membuat matriks M
M <-matrix(c(5,7,5,4,2,9,7,5,3,3,4,2,8,1,0,3),4,4, byrow=TRUE)
print(M)
## [,1] [,2] [,3] [,4]
## [1,] 5 7 5 4
## [2,] 2 9 7 5
## [3,] 3 3 4 2
## [4,] 8 1 0 3
a <- M * M
print(a)
## [,1] [,2] [,3] [,4]
## [1,] 25 49 25 16
## [2,] 4 81 49 25
## [3,] 9 9 16 4
## [4,] 64 1 0 9
b <- M%*%M
print(b)
## [,1] [,2] [,3] [,4]
## [1,] 86 117 94 77
## [2,] 89 121 101 82
## [3,] 49 62 52 41
## [4,] 66 68 47 46
c <- (solve(M))
print(c)
## [,1] [,2] [,3] [,4]
## [1,] 0.2954545 -2.50000e-01 0.06818182 -0.02272727
## [2,] 0.6590909 -2.50000e-01 -0.38636364 -0.20454545
## [3,] -0.2121212 2.92164e-17 0.51515152 -0.06060606
## [4,] -1.0075758 7.50000e-01 -0.05303030 0.46212121
d <- t(M)
print(d)
## [,1] [,2] [,3] [,4]
## [1,] 5 2 3 8
## [2,] 7 9 3 1
## [3,] 5 7 4 0
## [4,] 4 5 2 3
e <- d%*%M
print(e)
## [,1] [,2] [,3] [,4]
## [1,] 102 70 51 60
## [2,] 70 140 110 82
## [3,] 51 110 90 63
## [4,] 60 82 63 54
Soal No.2
Membuat matriks a dan B
a1 <- matrix(c(1,4,5,6),1)
B <- matrix(c(1,2,4,4,1,2,3,4), 2,4, byrow=TRUE)
cat("Matriks a1 \n")
## Matriks a1
print(a1)
## [,1] [,2] [,3] [,4]
## [1,] 1 4 5 6
cat("Matriks B \n")
## Matriks B
print(B)
## [,1] [,2] [,3] [,4]
## [1,] 1 2 4 4
## [2,] 1 2 3 4
M1 <- matrix(c(M[2,2], M[2,4],M[2,1],M[4,2]),2, byrow=TRUE)
print(M1)
## [,1] [,2]
## [1,] 9 5
## [2,] 2 1
M2 <- matrix(c(M[1,2],M[1,4],M[1,4],M[4,4]),2, byrow=TRUE)
print(M2)
## [,1] [,2]
## [1,] 7 4
## [2,] 4 3
M3 <-rbind(M, as.vector(a1))
print(M3)
## [,1] [,2] [,3] [,4]
## [1,] 5 7 5 4
## [2,] 2 9 7 5
## [3,] 3 3 4 2
## [4,] 8 1 0 3
## [5,] 1 4 5 6
M4 <-cbind(t(B), M)
print(M4)
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] 1 1 5 7 5 4
## [2,] 2 2 2 9 7 5
## [3,] 4 3 3 3 4 2
## [4,] 4 4 8 1 0 3
Pertanyaan 3 Setelah Anda mempelajari materi sesi ini, buatlah 2 contoh Program R serta lampirkan hasil output R tsb.
M_identitas <- round(M%*% solve(M), 10)
print(M_identitas)
## [,1] [,2] [,3] [,4]
## [1,] 1 0 0 0
## [2,] 0 1 0 0
## [3,] 0 0 1 0
## [4,] 0 0 0 1
Identitas <- diag(4)
print(Identitas)
## [,1] [,2] [,3] [,4]
## [1,] 1 0 0 0
## [2,] 0 1 0 0
## [3,] 0 0 1 0
## [4,] 0 0 0 1