Cholesky Decomposition : Matrix Decomposition | PHP program to decompose a matrix using Cholesky Decomposition ; Decomposing a matrix into Lower Triangular ; summation for diagonals ; Evaluating L ( i , j ) using L ( j , j ) ; Displaying Lower Triangular and its Transpose ; Lower Triangular ; Transpose of Lower Triangular ; Driver Code
< ? php $ MAX = 100 ; function Cholesky_Decomposition ( $ matrix , $ n ) { $ lower ; for ( $ i = 0 ; $ i <= $ n ; $ i ++ ) for ( $ j = 0 ; $ j <= $ n ; $ j ++ ) $ lower [ $ i ] [ $ j ] = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { for ( $ j = 0 ; $ j <= $ i ; $ j ++ ) { $ sum = 0 ; if ( $ j == $ i ) { for ( $ k = 0 ; $ k < $ j ; $ k ++ ) $ sum += pow ( $ lower [ $ j ] [ $ k ] , 2 ) ; $ lower [ $ j ] [ $ j ] = sqrt ( $ matrix [ $ j ] [ $ j ] - $ sum ) ; } else { for ( $ k = 0 ; $ k < $ j ; $ k ++ ) $ sum += ( $ lower [ $ i ] [ $ k ] * $ lower [ $ j ] [ $ k ] ) ; $ lower [ $ i ] [ $ j ] = ( $ matrix [ $ i ] [ $ j ] - $ sum ) / $ lower [ $ j ] [ $ j ] ; } } } echo " TABSYMBOL Lower ▁ Triangular " . str_pad ( " Transpose " , 30 , " ▁ " , STR_PAD_BOTH ) . " STRNEWLINE " ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { for ( $ j = 0 ; $ j < $ n ; $ j ++ ) echo str_pad ( $ lower [ $ i ] [ $ j ] , 6 , " ▁ " , STR_PAD_BOTH ) . " TABSYMBOL " ; echo " TABSYMBOL " ; for ( $ j = 0 ; $ j < $ n ; $ j ++ ) echo str_pad ( $ lower [ $ j ] [ $ i ] , 6 , " ▁ " , STR_PAD_BOTH ) . " TABSYMBOL " ; echo " STRNEWLINE " ; } } $ n = 3 ; $ matrix = array ( array ( 4 , 12 , -16 ) , array ( 12 , 37 , -43 ) , array ( -16 , -43 , 98 ) ) ; Cholesky_Decomposition ( $ matrix , $ n ) ; ? >