Cholesky Decomposition : Matrix Decomposition | C # 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
using System ; class GFG { static void Cholesky_Decomposition ( int [ , ] matrix , int n ) { int [ , ] lower = new int [ n , n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j <= i ; j ++ ) { int sum = 0 ; if ( j == i ) { for ( int k = 0 ; k < j ; k ++ ) sum += ( int ) Math . Pow ( lower [ j , k ] , 2 ) ; lower [ j , j ] = ( int ) Math . Sqrt ( matrix [ j , j ] - sum ) ; } else { for ( int k = 0 ; k < j ; k ++ ) sum += ( lower [ i , k ] * lower [ j , k ] ) ; lower [ i , j ] = ( matrix [ i , j ] - sum ) / lower [ j , j ] ; } } } Console . WriteLine ( " ▁ Lower ▁ Triangular TABSYMBOL ▁ Transpose " ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) Console . Write ( lower [ i , j ] + " TABSYMBOL " ) ; Console . Write ( " " ) ; for ( int j = 0 ; j < n ; j ++ ) Console . Write ( lower [ j , i ] + " TABSYMBOL " ) ; Console . WriteLine ( ) ; } } static int Main ( ) { int n = 3 ; int [ , ] matrix = { { 4 , 12 , - 16 } , { 12 , 37 , - 43 } , { - 16 , - 43 , 98 } } ; Cholesky_Decomposition ( matrix , n ) ; return 0 ; } }