How to resolve the algorithm Cholesky decomposition step by step in the ZX Spectrum Basic programming language

Published on 12 May 2024 09:40 PM

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

Source code in the zx programming language

10 LET d=2000: GO SUB 1000: GO SUB 4000: GO SUB 5000
20 LET d=3000: GO SUB 1000: GO SUB 4000: GO SUB 5000
30 STOP 
1000 RESTORE d
1010 READ a,b
1020 DIM m(a,b)
1040 FOR i=1 TO a
1050 FOR j=1 TO b
1060 READ m(i,j)
1070 NEXT j
1080 NEXT i
1090 RETURN 
2000 DATA 3,3,25,15,-5,15,18,0,-5,0,11
3000 DATA 4,4,18,22,54,42,22,70,86,62,54,86,174,134,42,62,134,106
4000 REM Cholesky decomposition
4005 DIM l(a,b)
4010 FOR i=1 TO a
4020 FOR j=1 TO i
4030 LET s=0
4050 FOR k=1 TO j-1
4060 LET s=s+l(i,k)*l(j,k)
4070 NEXT k
4080 IF i=j THEN LET l(i,j)=SQR (m(i,i)-s): GO TO 4100
4090 LET l(i,j)=(m(i,j)-s)/l(j,j)
4100 NEXT j
4110 NEXT i
4120 RETURN 
5000 REM Print
5010 FOR r=1 TO a
5020 FOR c=1 TO b
5030 PRINT l(r,c);" ";
5040 NEXT c
5050 PRINT 
5060 NEXT r
5070 RETURN

  

You may also check:How to resolve the algorithm Man or boy test step by step in the Scheme programming language
You may also check:How to resolve the algorithm Arena storage pool step by step in the Erlang programming language
You may also check:How to resolve the algorithm Parallel brute force step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bubble sort step by step in the Raku programming language
You may also check:How to resolve the algorithm Function composition step by step in the Ruby programming language