To demostrate assume
\[\begin{equation} A=\begin{bmatrix} 1 & 2 \\ 3 & 4 \\ \end{bmatrix} \end{equation}\] \[\begin{equation} AA^T=\begin{bmatrix} 1 + 4 & 3 + 8 \\ 3 + 8 & 9 + 16 \\ \end{bmatrix}= \begin{bmatrix} 5 & 11 \\ 11 & 25 \\ \end{bmatrix} A^TA=\begin{bmatrix} 1 + 9 & 2 + 12 \\ 2 + 12 & 4 + 16 \\ \end{bmatrix}= \begin{bmatrix} 10 & 14 \\ 14 & 20 \\ \end{bmatrix} \end{equation}\] \[\begin{equation} AA^T <> A^TA \end{equation}\]However under condition when b = c then replace c with b
\[\begin{equation} AA^T=\begin{bmatrix} a^2 + b^2 & ab + bd \\ ba + db & b^2 + d^2 \\ \end{bmatrix} A^TA=\begin{bmatrix} a^2 + b^2 & ab + bd \\ ba + db & b^2 + d^2 \\ \end{bmatrix} \end{equation}\] \[\begin{equation} So AA^T = A^TA when A = A^T \end{equation}\]a = function(A)
{
n = dim(A)[1]
if (n==2){
L1 = diag(n)
L1[2,1] = -(L1[2,2]*A[2,1])/A[1,1]
U= L1%*%A
L=solve(L1)
return(list(L,U,L%*%U))}
else if (n==3)
{
L1 = diag(n)
L1[2,1] = -(L1[2,2]*A[2,1])/A[1,1]
L1[3,1] = -(L1[3,3]*A[3,1])/A[1,1]
A=L1%*%A
L2=diag(n)
L2[3,2] = 1
L2[3,2] = -(L2[3,3]*A[3,2])/A[2,2]
L=solve(L1)%*%solve(L2)
U=L2%*%A
return(list(L,U,L%*%U))
}
else
{
L1 = diag(n)
L1[2,1] = -(L1[2,2]*A[2,1])/A[1,1]
L1[3,1] = -(L1[3,3]*A[3,1])/A[1,1]
L1[4,1] = -(L1[4,4]*A[4,1])/A[1,1]
A= L1%*%A
L2= diag(n)
L2[3,2] = -(L2[3,3]*A[3,2])/A[2,2]
L2[4,2]=-(L2[4,4]*A[4,2])/A[2,2]
A=L2%*%A
L3=diag(n)
L3[4,3]=-(L3[4,4]*A[4,3])/A[3,3]
L=solve(L1)%*%solve(L2)%*%solve(L3)
U=L3%*%A
return(list(L,U,L%*%U))
}
}
A=matrix(c(1,2,3,4),2)
a(A)
## [[1]]
## [,1] [,2]
## [1,] 1 0
## [2,] 2 1
##
## [[2]]
## [,1] [,2]
## [1,] 1 3
## [2,] 0 -2
##
## [[3]]
## [,1] [,2]
## [1,] 1 3
## [2,] 2 4
A=matrix(c(2,2,3,4,5,6,7,8,9),3)
a(A)
## [[1]]
## [,1] [,2] [,3]
## [1,] 1.0 0 0
## [2,] 1.0 1 0
## [3,] 1.5 0 1
##
## [[2]]
## [,1] [,2] [,3]
## [1,] 2 4 7.0
## [2,] 0 1 1.0
## [3,] 0 0 -1.5
##
## [[3]]
## [,1] [,2] [,3]
## [1,] 2 4 7
## [2,] 2 5 8
## [3,] 3 6 9
A=matrix(c(2,2,3,4,5,6,7,8,9,5,7,8,8,8,4,7),4)
a(A)
## [[1]]
## [,1] [,2] [,3] [,4]
## [1,] 1.0 0.0 0.000000 0
## [2,] 1.0 1.0 0.000000 0
## [3,] 1.5 -0.5 1.000000 0
## [4,] 2.0 -2.0 2.117647 1
##
## [[2]]
## [,1] [,2] [,3] [,4]
## [1,] 2 5 9.0 8.000000
## [2,] 0 1 -4.0 0.000000
## [3,] 0 0 -8.5 -8.000000
## [4,] 0 0 0.0 7.941176
##
## [[3]]
## [,1] [,2] [,3] [,4]
## [1,] 2 5 9 8
## [2,] 2 6 5 8
## [3,] 3 7 7 4
## [4,] 4 8 8 7