PROBLEM SET 1:

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

Load the Packages

library(matrixcalc)
library(matlib)
## 
## Attaching package: 'matlib'
## The following object is masked from 'package:matrixcalc':
## 
##     vec

Creating a 3 X 3 Matrix

A = matrix(c(1, 1, 2, 3, 2, 2, 1, 1, 1), nrow = 3)
A
##      [,1] [,2] [,3]
## [1,]    1    3    1
## [2,]    1    2    1
## [3,]    2    2    1

Finding the determinant of A to check: if det(A) != 0 then inverse exists

det(A)
## [1] 1

Finding the tranpose of A

AT <- t(A)

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

Mutiplying A AI

A %*% AT
##      [,1] [,2] [,3]
## [1,]   11    8    9
## [2,]    8    6    7
## [3,]    9    7    9

Mutiplying AI A

AT %*% A
##      [,1] [,2] [,3]
## [1,]    6    9    4
## [2,]    9   17    7
## [3,]    4    7    3

Checking for proof and it proves that (A X AI != AI X A)

(A %*% AT == AT %*% A)
##       [,1]  [,2]  [,3]
## [1,] FALSE FALSE FALSE
## [2,] FALSE FALSE  TRUE
## [3,] FALSE  TRUE FALSE

(2) For a special type of square matrix A, we get AT A = AAT. Under what conditionscould this be true? (Hint: The Identity matrix I is an example of such a matrix).

Creating an identity matrix for checking the case of a special square matrix

I <- diag(3)

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

Cretaing transpose of A

A <- I
AT <- t(A)
AT
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    0    0    1
AT %*% A 
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    0    0    1
A %*% AT
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    0    0    1

For a special type of square matrix called Identity Matrix, we get AT A = A AT

(A %*% AT == AT %*% A)
##      [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE

PROBLEM SET 2:

A = matrix(c(1, 4, 3, 1,3, 5, 1, -1, 3), nrow = 3)
A
##      [,1] [,2] [,3]
## [1,]    1    1    1
## [2,]    4    3   -1
## [3,]    3    5    3

In order to eliminate the 2 in the 2nd row, we can set up the following elimination matrix E21:

E21 = matrix(c(1,-4,0,0,1,0,0,0,1),nrow=3)
E21
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]   -4    1    0
## [3,]    0    0    1
E21 %*% A
##      [,1] [,2] [,3]
## [1,]    1    1    1
## [2,]    0   -1   -5
## [3,]    3    5    3

To eliminate 3 in row 3, we can choose E32 to be:

E31 = matrix(c(1,0,-3,0,1,0,0,0,1),nrow=3)
E31
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]   -3    0    1
E31 %*% E21 %*% A
##      [,1] [,2] [,3]
## [1,]    1    1    1
## [2,]    0   -1   -5
## [3,]    0    2    0

Notice that the pivot in row two, a22 = −1. This leads us to choose the following elimination matrix E32:

E32 = matrix(c(1,0,0,0,1,2,0,0,1),nrow=3)
E32
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    0    2    1

This gives us the U matrix

U <- E32 %*% E31 %*% E21 %*% A
U
##      [,1] [,2] [,3]
## [1,]    1    1    1
## [2,]    0   -1   -5
## [3,]    0    0  -10

We can compute L as the inverse of the product of the elimination matrices.

L = INV(E32 × E31 × E21)

inv(E32)
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    0   -2    1
inv(E31)
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    3    0    1
inv(E21)
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    4    1    0
## [3,]    0    0    1

We can also use the solve function in R to get the inverse of the matrices

L <- solve(E21) %*% solve(E31) %*% solve(E32)

L
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    4    1    0
## [3,]    3   -2    1

Finally, we will solve for proof that A = LU

L %*% U
##      [,1] [,2] [,3]
## [1,]    1    1    1
## [2,]    4    3   -1
## [3,]    3    5    3

This proves that A = LU

(L %*% U == A)
##      [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE