ASSIGNMENT 2 IS 605 FUNDAMENTALS OF COMPUTATIONAL MATHEMATICS - 2015

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

Lets use R to create a 3x3 matrix of sequence 1 to 9.

A = matrix(seq(from = 1, to = 9), 3, 3)

A
##      [,1] [,2] [,3]
## [1,]    1    4    7
## [2,]    2    5    8
## [3,]    3    6    9

We will use R to find the transpose of A

AT = t(A)

AT
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    4    5    6
## [3,]    7    8    9

Test whether the condition hold \[A^TA \neq AA^T\]. From the output its true that the product of a matrix and its transpose is not necesarily equal to the product of a transpose and its matrix multiplied in the respective order.

ATA = AT %*% A

ATA
##      [,1] [,2] [,3]
## [1,]   14   32   50
## [2,]   32   77  122
## [3,]   50  122  194
AAT = A %*% AT

AAT
##      [,1] [,2] [,3]
## [1,]   66   78   90
## [2,]   78   93  108
## [3,]   90  108  126
ATA == AAT
##       [,1]  [,2]  [,3]
## [1,] FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE
  1. For a special type of square matrix A, we get \[A^TA = AA^T\]. 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

Let us use a 3x3 matrix and multiply with the 3x3 identity matrix. We know that any matrix multiplied by its identity is equal to the identity multiplied by the same matrix.

I = matrix(c(1,0,0,
             0,1,0,
             0,0,1), 3, 3)
I
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    0    0    1
IT = t(I)
IT
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    0    0    1
ITI = IT %*% I

ITI
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    0    0    1
IIT = I %*% IT

IIT
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    0    0    1
ITI == IIT
##      [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE

The same case is applicable to any multiple of the identity matrix.

I1 = 3 * I
I1
##      [,1] [,2] [,3]
## [1,]    3    0    0
## [2,]    0    3    0
## [3,]    0    0    3
I1T = t(I1)

I1T
##      [,1] [,2] [,3]
## [1,]    3    0    0
## [2,]    0    3    0
## [3,]    0    0    3
I1TI1 = I1T %*% I1

I1TI1
##      [,1] [,2] [,3]
## [1,]    9    0    0
## [2,]    0    9    0
## [3,]    0    0    9
I1I1T = I1 %*% I1T

I1I1T
##      [,1] [,2] [,3]
## [1,]    9    0    0
## [2,]    0    9    0
## [3,]    0    0    9
I1TI1 == I1I1T
##      [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE

A final analysis would require evaluation of different entries into the diagonal of an identity matrix to confirm that when the values above and below the diagonal in a matix are all zeros with the diagonal consisting of only non zero values then \[A^TA = AA^T\]. This is comparable to row operations to obtain upper triangular and lower triangular matrix which preserve the determinant of a matrix.

B = matrix(c(5,0,0,
             0,7,0,
             0,0,9), 3, 3)
B
##      [,1] [,2] [,3]
## [1,]    5    0    0
## [2,]    0    7    0
## [3,]    0    0    9
BT = t(B)

BT
##      [,1] [,2] [,3]
## [1,]    5    0    0
## [2,]    0    7    0
## [3,]    0    0    9
B_BT = B %*% BT

B_BT
##      [,1] [,2] [,3]
## [1,]   25    0    0
## [2,]    0   49    0
## [3,]    0    0   81
BT_B = BT %*% B

BT_B
##      [,1] [,2] [,3]
## [1,]   25    0    0
## [2,]    0   49    0
## [3,]    0    0   81
BT_B == B_BT
##      [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE

We can comfortably conclude that \[AA^T = A^TA\] for identity matrix including on column transformation on the identity matrix preserving the diagonal to contain only non zero elements.

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

library(matrixcalc)
library(Matrix)

func_LU_Decomposer = function(M){
  # Condition 1. Not a 5x5 matrix or bigger.
  if (nrow(M) >=5){
    return("Matrix dimensions larger than expected")
  }
  
  # Condition 2. Not a square matrix.
  if (is.square.matrix(M) == FALSE){
    return("Not a square matrix")
  }
   
  n = nrow(M)[1] # Get the number of rows in the matix.
  L = diag(n) # create an identity matrix of same size as our matrix M.
  
  f = 0 # initialization variable.
  
  while (f <= dim(M)[1]){
    f = f + 1
    i = f
    j = f
    
  while (i <= dim(M)[1] - 1) {
    c = M[i + 1,j]/M[j,j]
    M[i+1,] = M[i+1,]-c*M[j,]
    L[i+1,j] = c
    i = 1+i
  }
  }
  return(L)
  
}

Let us test this function with an example.

Ex = matrix(c(7,8,9,1,2,3,4,5,6), 3, 3)
Ex
##      [,1] [,2] [,3]
## [1,]    7    1    4
## [2,]    8    2    5
## [3,]    9    3    6
func_LU_Decomposer(Ex)
##          [,1] [,2] [,3]
## [1,] 1.000000    0    0
## [2,] 1.142857    1    0
## [3,] 1.285714    2    1

Confirm that the function output is equal to R’s out put.

lu.decomposition(Ex)
## $L
##          [,1] [,2] [,3]
## [1,] 1.000000    0    0
## [2,] 1.142857    1    0
## [3,] 1.285714    2    1
## 
## $U
##      [,1]      [,2]          [,3]
## [1,]    7 1.0000000  4.000000e+00
## [2,]    0 0.8571429  4.285714e-01
## [3,]    0 0.0000000 -7.771561e-16

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.