Question Problem Set 1

  1. Show that ATA /= AAT in general. (Proof and demonstration.)

  2. 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

Answer Problem Set 1

Let’s say we have a matrix A with m rows and n columns.

\[A_{mxn}=\left[\begin{array} {rrr} a_{1,1} & a_{1,2} & a_{1,n} \\ a_{2,1} & a_{2,2} & a_{2,n} \\ a_{m,1} & a_{m,2} & a_{m,n} \end{array}\right] \]

Transpose of the matrix A would be;

\[A_{nxm}^T=\left[\begin{array} {rrr} a_{1,1} & a_{2,1} & a_{m,1} \\ a_{1,2} & a_{2,1} & a_{m,2} \\ a_{1,n} & a_{2,n} & a_{m,n} \end{array}\right] \] Let’s call the matrix A multiplied by matrix transpose A equals to B;

\[A_{mxn}*A_{nxm}^T=B_{mxm}\] Let’s call the matrix transpose A multipled by matrix A equals to C;

\[A_{nxm}^T*A_{mxn}=C_{nxn}\]

\[m \neq n\]

Hence;

\[A^T*A \neq A*A^T\]

Demonstration with an example;

\[\mathbf{A} = \left[\begin{array} {rrr} 2 & 4 & 3 & 3 \\ 3 & 2 & 1 & 2\\ 4 & 5 & 3 & 1\\ \end{array}\right] \]

\[\mathbf{A^T} = \left[\begin{array} {rrr} 2 & 3 & 4 \\ 4 & 2 & 5 \\ 3 & 1 & 3 \\ 3 & 2 & 1 \\ \end{array}\right] \]

# creating matrix A in r for demonstration
A = matrix(c(2,4,3,3,3,2,1,2,4,5,3,1), nrow=3, byrow=TRUE)
A
##      [,1] [,2] [,3] [,4]
## [1,]    2    4    3    3
## [2,]    3    2    1    2
## [3,]    4    5    3    1
# getting transpose of A
t(A)
##      [,1] [,2] [,3]
## [1,]    2    3    4
## [2,]    4    2    5
## [3,]    3    1    3
## [4,]    3    2    1
# multiply A transpose and A 
B= t(A)%*%A
B
##      [,1] [,2] [,3] [,4]
## [1,]   29   34   21   16
## [2,]   34   45   29   21
## [3,]   21   29   19   14
## [4,]   16   21   14   14
# multiply A and A transpose
C=A%*%t(A)
C
##      [,1] [,2] [,3]
## [1,]   38   23   40
## [2,]   23   18   27
## [3,]   40   27   51

\[A^T*A \neq A*A^T\] (2)

If A matrix has n rows and n columns

\[A_{nxn}\]

and if;

\[A=A^T\]

this is called a symetric matrix and therefore;

\[A^T*A = A*A^T\]

For example:

\[\mathbf{A} = \left[\begin{array} {rrr} 1 & 2 & 3 \\ 2 & 3 & 4 \\ 3 & 4 & 5 \\ \end{array}\right] \]

\[\mathbf{A^T} = \left[\begin{array} {rrr} 1 & 2 & 3 \\ 2 & 3 & 4 \\ 3 & 4 & 5 \\ \end{array}\right] \] \[A=A^T\]

Question 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.

Answer Problem Set 2

A is a square matrix;

\[A_{nxn}\] \[A=L*U\]

L is lower triangular matrix U is upper triangular matrix The goal is find the Upper triangular matrix and multipliers and map the opposites to get the lower triangular matrix.

# testing to see if i can create the upper triangular form U

A <- matrix(c(1,4,-3,-2,8,5,3,4,7), nrow=3, byrow = TRUE)
A
##      [,1] [,2] [,3]
## [1,]    1    4   -3
## [2,]   -2    8    5
## [3,]    3    4    7
#obtain U here

A[2,] <- A[1,]*2 + A[2,]

A[3,] <- A[1,]*(-3)+A[3,]

A[3,] <- A[2,]*0.5+A[3,]

U <- A
U
##      [,1] [,2] [,3]
## [1,]    1    4 -3.0
## [2,]    0   16 -1.0
## [3,]    0    0 15.5
# building L here
L = diag(x = 1, ncol = ncol(A), nrow = nrow(A))
L[2,1]=-2
L[3,1]= 3
L[3,2]= 15.5
L
##      [,1] [,2] [,3]
## [1,]    1  0.0    0
## [2,]   -2  1.0    0
## [3,]    3 15.5    1
# based on the test creating function

factor_matrix <- function(A){
  

L <- diag(x = 1, ncol = ncol(A), nrow = nrow(A))

multiply_1 <- A[2,1] / A[1,1]
multiply_2 <- A[3,1] / A[1,1]
multiply_3 <- A[3,2] / A[2,2]

L <- matrix(c(1,0,0,multiply_1,1,0,multiply_2,multiply_3,1), nrow = 3, byrow = TRUE)


multiply <- A[2,1] / A[1,1] * A[1,]
A[2,]=A[2,]-multiply
multiply <- A[3,1] / A[1,1] * A[1,]
A[3,]=A[3,]-multiply
multiply <- A[3,2] / A[2,2] * A[2,]
A[3,]=A[3,]-multiply

U <- A

print('factors for matrix A (L and U) are')
print(U)
print(L)
}

A <- matrix(c(1,4,-3,-2,8,5,3,4,7), nrow=3, byrow = TRUE)
factor_matrix(A)
## [1] "factors for matrix A (L and U) are"
##      [,1] [,2] [,3]
## [1,]    1    4 -3.0
## [2,]    0   16 -1.0
## [3,]    0    0 15.5
##      [,1] [,2] [,3]
## [1,]    1  0.0    0
## [2,]   -2  1.0    0
## [3,]    3  0.5    1