Problem Set 1

1. Show that \(A^TA \neq AA^T\) in general. (Proof and demonstration.)

Let \[\mathbf{A} = \left[\begin{array} {rr} a & b \\ c & d \end{array}\right]\]

Let \[\mathbf{A^t} = \left[\begin{array} {rr} w & x \\ y & z \end{array}\right]\]

\(A^TA\) = \[\mathbf{A^tA} = \left[\begin{array} {rr} wa + xc & wb + xd \\ ya + zc & yb + zd \end{array}\right]\]

\(AA^T\) = \[\mathbf{AA^t} = \left[\begin{array} {rr} aw + by & ax + bz \\ cw + dy & cx + dz \end{array}\right]\]

We can see that the products of the two different equations are not equal.
Now, I will test this idea through R
A <- matrix(c(1, 2, 3, 4), ncol = 2)
t <- 2

ATA <- A^t %*% A
AAT <- A %*% A^t

identical(ATA, AAT)
## [1] FALSE

2. For a special type of square matrix A, we get \(A^T A = AA^T\) . Under what conditions could this be true?

With symmetrical matrices this is true.
A <- matrix(c(1, 2, 1, 2, 1, 2, 1, 2, 1), nrow = 3, byrow = T)
A
##      [,1] [,2] [,3]
## [1,]    1    2    1
## [2,]    2    1    2
## [3,]    1    2    1
#transpose A
t(A)
##      [,1] [,2] [,3]
## [1,]    1    2    1
## [2,]    2    1    2
## [3,]    1    2    1
#Write equations for $A^T A = AA^T$
ATA <- t(A) %*% A
AAT <- A %*% t(A)

AAT == ATA
##      [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE

2. Problem Set 2

I’m going to try to build a function using the example from this exercise I found online (https://ocw.mit.edu/courses/mathematics/18-06sc-linear-algebra-fall-2011/ax-b-and-the-four-subspaces/factorization-into-a-lu/MIT18_06SCF11_Ses1.4sol.pdf)

I’m also going to use help that I found on this

A <- matrix (c(1, 2, 2, 3, 4, 0, 0, 0, 1), ncol = 3, byrow = F)
A
##      [,1] [,2] [,3]
## [1,]    1    3    0
## [2,]    2    4    0
## [3,]    2    0    1
function_lu <- function(A){
  L <- diag(x = 1, ncol = ncol(A), nrow = nrow(A))
  U <- A
    
  m21 <- -A[2,1] / A[1,1]
  L1 <- matrix(c(1,0,0,m21,1,0,0,0,1), nrow=3, byrow = T)
  
  A2 <- L %*% A
  
  m31 <- -A[3,1] / A[1,1]
  L2 <- matrix(c(1,0,0,0,1,0,m31,0,1), nrow=3, byrow = T)
  
  A3 <- L2 %*% A2
  
  m32 <- -A[3,2] / A[2,2]
  L3 <- matrix(c(1,0,0,0,1,0,0,m32,1), nrow = 3, byrow = T)
  
  
  L <- solve (L1) %*% solve (L2) %*% solve (L3)
  
  A <- L %*% U  
  
  print (A)
  print (L)
  print (U)
  
  (L %*% U == A)
}

function_lu(A)
##      [,1] [,2] [,3]
## [1,]    1    3    0
## [2,]    4   10    0
## [3,]    4    6    1
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    2    1    0
## [3,]    2    0    1
##      [,1] [,2] [,3]
## [1,]    1    3    0
## [2,]    2    4    0
## [3,]    2    0    1
##      [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE
I had a lot of trouble with this equation. It wouldn’t run until I definited L & U and I’m not sure why. I also think that this will only work on a 3x3 matrix. I need a lot more practice in writing loops.