- Problem set 1
- Show that \(A^TA\neq AA^T\) in
general. (Proof and demonstration.)
# Create a basic 3 x 3 matrix called matrixA
matrixA <- matrix(c(6,1,4,3,2,7,8,8,1),nrow=3,ncol=3,byrow=TRUE)
# Transpose matrixA.
TmatrixA <- t(matrixA)
matrixA
## [,1] [,2] [,3]
## [1,] 6 1 4
## [2,] 3 2 7
## [3,] 8 8 1
TmatrixA
## [,1] [,2] [,3]
## [1,] 6 3 8
## [2,] 1 2 8
## [3,] 4 7 1
#calculate $A^TA\neq AA^T$
ATA <- TmatrixA %*% matrixA
ATA
## [,1] [,2] [,3]
## [1,] 109 76 53
## [2,] 76 69 26
## [3,] 53 26 66
AAT <- matrixA %*% TmatrixA
AAT
## [,1] [,2] [,3]
## [1,] 53 48 60
## [2,] 48 62 47
## [3,] 60 47 129
#Show that $A^TA\neq AA^T$ in general
AAT == ATA
## [,1] [,2] [,3]
## [1,] FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE
- For a special type of square matrix A, we get AT A = AAT . Under
what conditions could this be true? (Hint: The Identity matrix I is an
example of such a matrix). Please typeset your response using LaTeX mode
in RStudio. If you do it in paper, please either scan or take a picture
of the work and submit it. Please ensure that your image is legible and
that your submissions are named using your first initial, last name,
assignment and problem set within the assignment. E.g.
LFulton_Assignment2_PS1.png
a <- AAT
a
## [,1] [,2] [,3]
## [1,] 53 48 60
## [2,] 48 62 47
## [3,] 60 47 129
Transa <- t(a)
Transa
## [,1] [,2] [,3]
## [1,] 53 48 60
## [2,] 48 62 47
## [3,] 60 47 129
## Matrix multiple a by the transpose!
aaT <- a %*% Transa
aaT
## [,1] [,2] [,3]
## [1,] 8713 8340 13176
## [2,] 8340 8357 11857
## [3,] 13176 11857 22450
## Matrix multiply the transpose by a
aTa <- Transa %*% a
aTa
## [,1] [,2] [,3]
## [1,] 8713 8340 13176
## [2,] 8340 8357 11857
## [3,] 13176 11857 22450
## Verify that aaT == aTa
aaT == aTa
## [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE
- Problem set 2 Matrix factorization is a very important problem.
There are supercomputers built just to do matrix factorizations. Every
second you are on an airplane, matrices are being factorized. Radars
that track flights use a technique called Kalman filtering. At the heart
of Kalman Filtering is a Matrix Factorization operation. Kalman Filters
are solving linear systems of equations when they track your flight
using radars. Write an R function to factorize a square matrix A into LU
or LDU, whichever you prefer. Please submit your response in an R
Markdown document using our class naming convention, E.g.
LFulton_Assignment2_PS2.png You don’t have to worry about permuting rows
of A and you can assume that A is less than 5x5, if you need to
hard-code any variables in your code. If you doing the entire assignment
in R, then please submit only one markdown document for both the
problems.
Factorize_A_LU <- function(matrixA) {
U <- matrixA
dimens <- dim(matrixA)[1]
L <- diag(dimens)
if (dimens==1) {
return(list(L,U))
}
for(i in 2:dimens) {
for(j in 1:(i-1)) {
multiplier <- -U[i,j] / U[j,j]
U[i, ] <- multiplier * U[j, ] + U[i, ]
L[i,j] <- -multiplier
}
}
return(list(L,U))
}
#using the matrixFactorization_LU
A <- matrix(c(2,3,8,12), nrow=2, byrow=TRUE)
LU <- Factorize_A_LU(A)
L<-LU[[1]]
U<-LU[[2]]
print('Matrix A:')
## [1] "Matrix A:"
print(A)
## [,1] [,2]
## [1,] 2 3
## [2,] 8 12
print('The L matrix is:')
## [1] "The L matrix is:"
print(L)
## [,1] [,2]
## [1,] 1 0
## [2,] 4 1
print('The U matrix is:')
## [1] "The U matrix is:"
print(U)
## [,1] [,2]
## [1,] 2 3
## [2,] 0 0