Assignment 7
Assignment 7
Assignment 7
2024-10-15
# Question - 1
# Define matrix A and vector X
A <- matrix(c(1.5, 1.0, 1.0, 2.0), nrow=2, ncol=2, byrow=TRUE)
X <- matrix(c(0.2, 0.5), nrow=2, ncol=1, byrow=TRUE)
A;X
## [,1] [,2]
## [1,] 1.5 1
## [2,] 1.0 2
## [,1]
## [1,] 0.2
## [2,] 0.5
# a. Find determinant of A
det_A <- det(A)
det_A
## [1] 2
# b. Find inverse of A
inv_A <- solve(A)
inv_A
## [,1] [,2]
## [1,] 1.0 -0.50
## [2,] -0.5 0.75
# c. Find trace of A
trace_A <- sum(diag(A))
trace_A
## [1] 3.5
# d. Find the quadratic form X'AX
quadratic_form <- t(X) %*% A %*% X
quadratic_form
## [,1]
## [1,] 0.76
# e. Find X1 and X2 ratios that will minimize X'AX
eigen_A <- eigen(A)
min_eigenvector <- eigen_A$vectors[, which.min(eigen_A$values)]
min_eigenvector
1
# f. Normalize the minimizing eigenvector such that X1 + X2 = 1
min_ratios <- min_eigenvector / sum(min_eigenvector)
min_ratios
## [,1] [,2]
## [1,] 0.6154122 -0.7882054
## [2,] 0.7882054 0.6154122
# Question - 2
# Define matrix A matrix B and matrix C
A <- matrix(c(3, 0, 1), nrow=1, ncol=3, byrow=TRUE)
B <- matrix(c(-1, 4, 5), nrow=1, ncol=3, byrow=TRUE)
C <- matrix(c(1, 3, -1, 2, 3, 1, -1, 1, 0), nrow=3, ncol=3, byrow=TRUE)
A;B;C
## [,1]
## [1,] 3
## [2,] 0
## [3,] 1
C_transpose
2
## [,1] [,2] [,3]
## [1,] 0.1111111 0.1111111 -0.6666667
## [2,] 0.1111111 0.1111111 0.3333333
## [3,] -0.5555556 0.4444444 0.3333333
# c. Find A.B', A'.B, C.A', and B.C.A'
A.Bt <- A %*% t(B)
At.B <- t(A) %*% B
C.At <- C %*% t(A)
B.C.At <- B %*% C %*% t(A)
A.Bt
## [,1]
## [1,] 2
At.B
## [,1]
## [1,] 2
## [2,] 7
## [3,] -3
B.C.At
## [,1]
## [1,] 11
# d. Trace of C
trace_C <- sum(diag(C))
trace_C
## [1] 4
# e. Find a vector orthogonal to A
A <- c(3, 0, 1)
# A.D = 0; 3x + z = 0
# Choose an x and solve for z = -3x
# For simplicity let us take x = 1
x <- 1
y <- 0
z <- -3 * x
D <- c(x, y, z)
D
## [1] 1 0 -3
# f. Eigenvalues of C
eigen_C <- eigen(C)
eigenvalues_C <- eigen_C$values
eigenvalues_C
3
# g. Eigenvectors of C
eigenvectors_C <- eigen_C$vectors
eigenvectors_C