1. Problem set 1

Question 1 Show that \(A^T A \neq AA^T\) in general

Demonstration

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

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

mat_A <- matrix(c(1,4,7,2,5,8,3,6,9),ncol=3)
mat_A_T <- t(mat_A)

mat_A_dot_At <- mat_A%*%mat_A_T
At_dot_mat_A <- mat_A_T%*%mat_A
##Print the matrices out and test their equality
mat_A_dot_At==At_dot_mat_A
##       [,1]  [,2]  [,3]
## [1,] FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE

\[\mathbf{(A*A^t} = \left[\begin{array} {rrr}14&32&50\\32&77&122\\50&122&194\end{array}\right])\neq\mathbf{(A^t*A} = \left[\begin{array} {rrr}66&78&90\\78&93&108\\90&108&126\end{array}\right])\]

Proof for general case

  • In any case where a matrix is not a square, it is impossible for the dot products to be equivalent as the resulting matrix of a dot product is equivalent to the outer dimensions of each matrix
  • Let M= # rows
  • Let N= # columns
  • let A= matrix
  • let B= resulting matrix of my dot product \[ if... m\neq n\] \[Amn*Anm== Bmm\] \[Anm*Amn==Bnn\] \[therefore\:\:\:Bmm \neq Bnn\]

Question 2

  • If the transpose of matrix A is equivalent to matrix A, or
  • if A equals the inverse of \(A^t\), then the equation will also be satisfied as operation order does that matter when a matrix is multiplied by its inverse and the result will always be the identity matrix \[if A=A^{t^{-1}}\] \[A*A^t=A^t*A\]

Problem set 2

Build functions

  • swap_zero
    • For each step along the Gaussian elimination if the pivot column is 0 it swaps for non zero
  • build_lower_upper
    • Takes in a matrix and its size and builds upper and lower decomposition
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
swap_zero <- function(A,N,x){
##inputs    A- Matrix 
##          N- Row I want to swap with original row 
##          x-oriignal row
orig_row <- A[x,]
A[x,] <- A[N,]
A[N,] <- orig_row
return(A)}


build_lower_upper <- function(A,size){
##inputs A- Matrix
##       size- length input matrix
N=1
L <- diag(size)
### check for row swaps
for (my_col in 1:(dim(A)[1]-1)){
   ifelse(A[my_col,my_col]!=0,A,
       ifelse(A[my_col+1,my_col]!=0,A <- swap_zero(A,N+1,my_col) ,
              ifelse(A[my_col+2,my_col]!=0, A <- swap_zero(A,N+2,my_col),
                      ifelse(A[my_col+3,my_col]!=0, A <- swap_zero(A,N+3,my_col),"error"))))
## make 0's
    for (mat_val in (my_col+1):dim(A)[1]){ 
        if (A[mat_val,my_col]==0){
        L[mat_val,1]==0
    }else {original_row<- A[mat_val,my_col]
        constant <-  A[mat_val,my_col]/A[my_col,my_col]
        A[mat_val,] <- (-A[mat_val,my_col]/A[my_col,my_col])*A[my_col,]+A[mat_val,]
        L[mat_val,my_col] <- constant 
}
 }
}
return(list(lower=L,upper=A))
}

Test functions on some matrices

  • 4x4 matrix taken from 4x4
  • 3x3 matrix taken from minute6
bb <- matrix(c(2,1,-6,4,-4,-9,-4,3,5),ncol=3)
three_three <- build_lower_upper(bb,3)

cc <-  matrix(c(1,2,0,0,5,12,4,0,0,5,13,6,0,0,5,11),ncol=4)
four_four <- build_lower_upper(cc,4)
four_four
## $lower
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    0
## [2,]    2    1    0    0
## [3,]    0    2    1    0
## [4,]    0    0    2    1
## 
## $upper
##      [,1] [,2] [,3] [,4]
## [1,]    1    5    0    0
## [2,]    0    2    5    0
## [3,]    0    0    3    5
## [4,]    0    0    0    1
four_four$lower%*%four_four$upper==cc
##      [,1] [,2] [,3] [,4]
## [1,] TRUE TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE TRUE
## [4,] TRUE TRUE TRUE TRUE
three_three$lower%*%three_three$upper==bb
##      [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE