A: (1)

Consider a matrix A with i rows and j columns,

\(A_{(i,j)} = \left[\begin{array}{cc}a_{1,1} & a_{1,2} & a_{1,3} & ..... & a_{1,j} \\a_{2,1} & a_{2,2} & a_{2,3} & ..... & a_{2,j} \\a_{3,1} & a_{3,2} & a_{3,3} & ..... & a_{3,j} \\. & . & . & ..... & .\\. & . & . & ..... & .\\. & . & . & ..... & .\\a_{i,1} & a_{i,2} & a_{i,3} & ..... & a_{i,j}\end{array}\right]\)

Lets say values, \(i \ne j\) and so on ….

\(A_{(j,i)}^{T}\) will result in j rows and i columns.

Transpose of A, \(A^T = \left[\begin{array}{cc}a_{1,1} & a_{2,1} & a_{3,1} & ..... & a_{i,1} \\a_{1,2} & a_{2,2} & a_{3,2} & ..... & a_{i,2} \\a_{1,3} & a_{2,3} & a_{3,3} & ..... & a_{i,3} \\. & . & . & ..... & .\\. & . & . & ..... & .\\. & . & . & ..... & .\\a_{1,j} & a_{2,j} & a_{3,j} & ..... & a_{j,i}\end{array}\right]\)

\(A_{(i,j)}A_{(j,i)}^{T}\) will result in matrix of i rows and i columns, \(AA_{(i,i)}^{T}\)

\(A_{(j,i)}^{T}A_{(i,j)}\) will result in matrix of j rows and j columns, \(A^{T}A_{(j,j)}\)

Hence, \(A_{(i,j)}A_{(j,i)}^{T} \ne A_{(j,i)}^{T}A_{(i,j)}\)

\(AA_{(i,i)}^{T} \ne A^{T}A_{(j,j)}\)

Example: Consider 4 X 5 matrix

\(A = \left[\begin{array}{cc}1 & 1 & 1 & 1 & 3 \\3 & 2 & 1 & 2 & 4 \\2 & 1 & 0 & 2 & 1 \\1 & 1 & 1 & 1 & 3\end{array}\right]\)

#4 X 5 matrix
A = matrix(c(1,3,2,1, 1,2,1,1, 1,1,0,1, 1,2,2,1, 3,4,1,3), nrow=4, ncol=5)


A
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1    1    1    1    3
## [2,]    3    2    1    2    4
## [3,]    2    1    0    2    1
## [4,]    1    1    1    1    3
#transpose of matrix A, generates 5 X 4
tA = t(A)

tA
##      [,1] [,2] [,3] [,4]
## [1,]    1    3    2    1
## [2,]    1    2    1    1
## [3,]    1    1    0    1
## [4,]    1    2    2    1
## [5,]    3    4    1    3
#generates 4 X 4 matrix
A%*%tA
##      [,1] [,2] [,3] [,4]
## [1,]   13   20    8   13
## [2,]   20   34   16   20
## [3,]    8   16   10    8
## [4,]   13   20    8   13
#generates 5 X 5 matrix
tA%*%A
##      [,1] [,2] [,3] [,4] [,5]
## [1,]   15   10    5   12   20
## [2,]   10    7    4    8   15
## [3,]    5    4    3    4   10
## [4,]   12    8    4   10   16
## [5,]   20   15   10   16   35

Outputs are different matrices with different values.

A: (2)

When a matrix is symmetrical square matrix or identity matrix then \(A_{(i,j)}A_{(j,i)}^{T} = A_{(j,i)}^{T}A_{(i,j)}\)

#4 X 4 matrix 
A = matrix(c(9,1,3,6, 1,11,7,6, 3,7,4,1, 6,6,1,10), nrow=4, ncol=4)

A
##      [,1] [,2] [,3] [,4]
## [1,]    9    1    3    6
## [2,]    1   11    7    6
## [3,]    3    7    4    1
## [4,]    6    6    1   10
#transpose of matrix A
#it is similar to A
tA = t(A)

tA
##      [,1] [,2] [,3] [,4]
## [1,]    9    1    3    6
## [2,]    1   11    7    6
## [3,]    3    7    4    1
## [4,]    6    6    1   10
#matrix multiplication
A%*%tA
##      [,1] [,2] [,3] [,4]
## [1,]  127   77   52  123
## [2,]   77  207  114  139
## [3,]   52  114   75   74
## [4,]  123  139   74  173
tA%*%A
##      [,1] [,2] [,3] [,4]
## [1,]  127   77   52  123
## [2,]   77  207  114  139
## [3,]   52  114   75   74
## [4,]  123  139   74  173

Symmetric Square Matrix is one exception to the rule, where (i = j),

\(A_{(i,j)}A_{(j,i)}^{T} = A_{(j,i)}^{T}A_{(i,j)}\) = \(AA_{(i,i)}^{T} = A^{T}A_{(j,j)}\)

Similarly, for identity matrix

#4 X 4 identity matrix 
A = diag(4)

A
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    0
## [2,]    0    1    0    0
## [3,]    0    0    1    0
## [4,]    0    0    0    1
#transpose of matrix A
#it is similar to A
tA = t(A)

tA
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    0
## [2,]    0    1    0    0
## [3,]    0    0    1    0
## [4,]    0    0    0    1
#matrix multiplication
A%*%tA
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    0
## [2,]    0    1    0    0
## [3,]    0    0    1    0
## [4,]    0    0    0    1
tA%*%A
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    0
## [2,]    0    1    0    0
## [3,]    0    0    1    0
## [4,]    0    0    0    1

Identity matrix is another exception to the rule, where (i = j),

\(A_{(i,j)}A_{(j,i)}^{T} = A_{(j,i)}^{T}A_{(i,j)}\) = \(AA_{(i,i)}^{T} = A^{T}A_{(j,j)}\)

A:

Following function accepts a 5 X 5 square matrix and diagonal value to create identity matrix. It returns two matrices lower(L) and upper(U) decomposition.

Function is coded based on https://www.youtube.com/watch?v=UlWcofkUDDU.

lud_function <- function(a,dia){
  #initiate identity matrix
  l = diag(dia)
  u = a
  
  #check if a[1,1] equal zero move it following row
  for (i in 1:nrow(u)){
    if (u[1,1] == 0){
      if (i+1 <= nrow(u)){
        swap = u[i+1,]
        u[i+1,] = u[1,]
        u[1,] = swap
        if (u[1,1] != 0){
          break
        }        
      }
    }
  }
  
  #Loop through every column and every row.
  #While working with column number 1 row number should be 2 (row > column)
  #For the first row, leave values as is
  #For the second row make first value zero
  #For the third row make first and second column values zero
  #Basically, we are doing row reduction echelon form, converting numbers on the lower side of diagonal to zero.
  #And saving factor value on lower side of identity matrix.
  
  k = 0
  #read columns
  for (j in 1:ncol(a)){
    k = k + 1
    #read rows
    for (i in 1:nrow(u)){
      #if row > column and value for the row is not equal to zero
      if (i > j){
        if (u[i,j] != 0){
          #initiate the sign of the factor
          s = -1
          if (u[i,j] < 0){
            if (u[k,j] < 0){
              #when both numbers are negative keep sign positive
              s = 1
            }
          }
          #calculate the factor
          f = s *  u[i,j]/u[k,j]
          #multiply upper row with the factor and sign
          swap1 = s * (u[k,] * u[i,j])/u[k,j]
          #get current row
          swap2 = u[i,]
          #add modified upper row to current row.
          #this should make row,column value to zero when addition is performed
          u[i,] = swap1 + swap2
          #record the factor
          l[i,j] = -1*f
        } 
      }
    }
  }
  return(list(l=l,u=u))
}

#get matrix
#a = matrix(c(1,-2,3, 4,8,4, -3,5,7), nrow=3, ncol=3)
#l = diag(3)
#a = matrix(c(1,2,0,0, 5,12,4,0, 0,5,13,6, 0,0,5,11), nrow=4, ncol=4)
#l = diag(4)

a = matrix(c(2,6,6,4,2, 3,1,3,2,1, 4,3,1,4,2, 1,1,2,7,4, 3,2,5,8,2), nrow=5, ncol=5)
m = lud_function(a,5)
#Lower matrix
m$l
##      [,1]  [,2]       [,3]     [,4] [,5]
## [1,]    1  0.00  0.0000000 0.000000    0
## [2,]    3  1.00  0.0000000 0.000000    0
## [3,]    3 -0.75  1.0000000 0.000000    0
## [4,]    2 -0.50 -0.4788732 1.000000    0
## [5,]    1 -0.25 -0.2394366 0.678392    1
#Upper matrix
m$u
##      [,1]       [,2]       [,3]          [,4]       [,5]
## [1,]    2   3.000000   4.000000  1.000000e+00  3.0000000
## [2,]    0  -8.000000  -9.000000 -2.000000e+00 -7.0000000
## [3,]    0 -12.000000 -17.750000 -2.500000e+00 -9.2500000
## [4,]    0 -13.746479 -17.000000  2.802817e+00 -5.9295775
## [5,]    0   2.452261   3.032663 -2.220446e-16 -0.9422111

Matrix multipication results in original matrix

#original matrix
a
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    2    3    4    1    3
## [2,]    6    1    3    1    2
## [3,]    6    3    1    2    5
## [4,]    4    2    4    7    8
## [5,]    2    1    2    4    2
#multipication of L and U
m$l%*%m$u
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    2    3    4    1    3
## [2,]    6    1    3    1    2
## [3,]    6    3    1    2    5
## [4,]    4    2    4    7    8
## [5,]    2    1    2    4    2

Both outputs match.