Assignment 7

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

ASSIGNMENT-7

HRUSHI RIYAN GAJJALA

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] -0.7882054 0.6154122

1
# f. Normalize the minimizing eigenvector such that X1 + X2 = 1
min_ratios <- min_eigenvector / sum(min_eigenvector)
min_ratios

## [1] 4.561553 -3.561553


# g. Find eigenvalues
eigen_A <- eigen(A)
eigenvalues_A <- eigen_A$values
eigenvalues_A

## [1] 2.7807764 0.7192236


# h. Find eigenvectors
eigenvectors_A <- eigen_A$vectors
eigenvectors_A

## [,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] [,2] [,3]


## [1,] 3 0 1
## [,1] [,2] [,3]
## [1,] -1 4 5
## [,1] [,2] [,3]
## [1,] 1 3 -1
## [2,] 2 3 1
## [3,] -1 1 0
# a. Transpose of A and C
A_transpose <- t(A)
C_transpose <- t(C)
A_transpose

## [,1]
## [1,] 3
## [2,] 0
## [3,] 1
C_transpose

## [,1] [,2] [,3]


## [1,] 1 2 -1
## [2,] 3 3 1
## [3,] -1 1 0
# b. Inverse of C
C_inverse <- solve(C)
C_inverse

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] [,2] [,3]


## [1,] -3 12 15
## [2,] 0 0 0
## [3,] -1 4 5
C.At

## [,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

## [1] 4.658587 -1.757702 1.099115

3
# g. Eigenvectors of C
eigenvectors_C <- eigen_C$vectors
eigenvectors_C

## [,1] [,2] [,3]


## [1,] 0.62852346 0.6713753 -0.6035847
## [2,] 0.77713615 -0.4117461 0.2341098
## [3,] 0.03190081 0.6162145 0.7621536

You might also like