Nomor 3.1

x <- matrix(c(5, 1, 3))
y <- matrix(c(-1, 3, 1))

# Grafik Vektor
library(plotly)
plot_ly() %>%
  add_markers(x = c(0, x[1]), y = c(0, x[2]), z = c(0, x[3]), type = "scatter3d", mode = "lines", line = list(color = "blue", width = 5)) %>%
  add_markers(x = c(0, y[1]), y = c(0, y[2]), z = c(0, y[3]), type = "scatter3d", mode = "lines", line = list(color = "red", width = 5)) %>%
  layout(scene = list(xaxis = list(title = "X"),
                      yaxis = list(title = "Y"),
                      zaxis = list(title = "Z")))
length_x <- as.numeric(sqrt(t(x)%*%x))
length_x
## [1] 5.91608
length_y <- as.numeric(sqrt(t(y)%*%y))
length_y
## [1] 3.316625
dot.prod <- as.numeric(t(x)%*%y)

cos_xy <- dot.prod/(length_x*length_y)
cos_xy
## [1] 0.05096472
sudut_xy <- acos(cos_xy)*(180/pi)
sudut_xy
## [1] 87.07867
proyeksi <- (dot.prod/(length_x)^2)*x
round(proyeksi, 3)
##       [,1]
## [1,] 0.143
## [2,] 0.029
## [3,] 0.086
# Vektor Deviasi
dx <- matrix(c(2, -2, 0))
dy <- matrix(c(-2, 2, 0))
plot_ly() %>%
  add_markers(x = c(0, dx[1]), y = c(0, dx[2]), z = c(0, dx[3]), type = "scatter3d", mode = "lines", line = list(color = "blue", width = 5)) %>%
  add_markers(x = c(0, dy[1]), y = c(0, dy[2]), z = c(0, dy[3]), type = "scatter3d", mode = "lines", line = list(color = "red", width = 5)) %>%
  layout(scene = list(xaxis = list(title = "X"),
                      yaxis = list(title = "Y"),
                      zaxis = list(title = "Z")))

Nomor 3.4

# Buat matriks A dan B
A <- matrix(c(1, 2, 3, 4), nrow = 2, ncol = 2)
B <- matrix(c(5, 6, 7, 8), nrow = 2, ncol = 2)

# Inverse dari A dan B
A_inv <- solve(A)
B_inv <- solve(B)

# Transpose dari A dan inverse dari transpose A
A_t <- t(A)
A_inv_t <- solve(A_t)

# Verifikasi (a)
# Apakah (A^(-1))'= (A')^(-1)?
all.equal(t(A_inv), A_inv_t)
## [1] TRUE
# Verifikasi (b)
# Apakah (AB)^(-1) = B^(-1)A^(-1)?
AB_inv <- solve(A %*% B)
BA_inv <- B_inv %*% A_inv

all.equal(AB_inv, BA_inv)
## [1] TRUE