How to resolve the algorithm Cholesky decomposition step by step in the Raku programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Cholesky decomposition step by step in the Raku 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 Raku programming language

Source code in the raku programming language

sub cholesky(@A) {
    my @L = @A »×» 0;
    for ^@A -> \i {
        for 0..i -> \j {
            @L[i;j] = (i == j ?? &sqrt !! 1/@L[j;j] × * )\      # select function
                      (@A[i;j] - [+] (@L[i;*] Z× @L[j;*])[^j])  # provide value
        }
    }
    @L
}

.fmt('%3d').say for cholesky [
    [25],
    [15, 18],
    [-5,  0, 11],
];

say '';

.fmt('%6.3f').say for cholesky [
    [18, 22,  54,  42],       
    [22, 70,  86,  62],
    [54, 86, 174, 134],       
    [42, 62, 134, 106],
];


  

You may also check:How to resolve the algorithm Hello world/Text step by step in the AmigaE programming language
You may also check:How to resolve the algorithm Elementary cellular automaton step by step in the J programming language
You may also check:How to resolve the algorithm Maze generation step by step in the Rascal programming language
You may also check:How to resolve the algorithm Disarium numbers step by step in the dc programming language
You may also check:How to resolve the algorithm Abundant, deficient and perfect number classifications step by step in the Seed7 programming language