How to resolve the algorithm Cholesky decomposition step by step in the AutoHotkey programming language
How to resolve the algorithm Cholesky decomposition step by step in the AutoHotkey programming language
Table of Contents
Problem Statement
Every symmetric, positive definite matrix A can be decomposed into a product of a unique lower triangular matrix L and its transpose:
L
{\displaystyle L}
is called the Cholesky factor of
A
{\displaystyle A}
, and can be interpreted as a generalized square root of
A
{\displaystyle A}
, as described in Cholesky decomposition. In a 3x3 example, we have to solve the following system of equations: We can see that for the diagonal elements (
l
k k
{\displaystyle l_{kk}}
) of
L
{\displaystyle L}
there is a calculation pattern: or in general: For the elements below the diagonal (
l
i k
{\displaystyle l_{ik}}
, where
i
k
{\displaystyle i>k}
) there is also a calculation pattern: which can also be expressed in a general formula: Task description The task is to implement a routine which will return a lower Cholesky factor
L
{\displaystyle L}
for every given symmetric, positive definite nxn matrix
A
{\displaystyle A}
. You should then test it on the following two examples and include your output. Example 1: Example 2:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Cholesky decomposition step by step in the AutoHotkey programming language
Source code in the autohotkey programming language
Cholesky_Decomposition(A){
L := [], n := A.Count()
L[1,1] := Sqrt(A[1,1])
loop % n {
k := A_Index
loop % n-1 {
i := A_Index+1
Sigma := 0, j := 0
while (++j <= k-1)
Sigma += L[i, j] * L[k, j]
L[i, k] := (A[i, k] - Sigma) / L[k, k]
Sigma := 0, j := 0
while (++j <= k-1)
Sigma += (L[k, j])**2
L[k, k] := Sqrt(A[k, k] - Sigma)
}
}
loop % n{
k := A_Index
loop % n
L[k, A_Index] := L[k, A_Index] ? L[k, A_Index] : 0
}
return L
}
ShowMatrix(L){
for r, obj in L{
row := ""
for c, v in obj
row .= Format("{:.3f}", v) ", "
output .= "[" trim(row, ", ") "]`n,"
}
return "[" Trim(output, "`n,") "]"
}
A := [[25, 15, -5]
, [15, 18, 0]
, [-5, 0 , 11]]
L1 := Cholesky_Decomposition(A)
A := [[18, 22, 54, 42]
, [22, 70, 86, 62]
, [54, 86, 174, 134]
, [42, 62, 134, 106]]
L2 := Cholesky_Decomposition(A)
MsgBox % Result := ShowMatrix(L1) "`n----`n" ShowMatrix(L2) "`n----"
return
You may also check:How to resolve the algorithm Undefined values step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm Filter step by step in the PHP programming language
You may also check:How to resolve the algorithm Record sound step by step in the Wren programming language
You may also check:How to resolve the algorithm Loops/Downward for step by step in the DWScript programming language
You may also check:How to resolve the algorithm Random Latin squares step by step in the D programming language