Cholesky() public method

public Cholesky ( ) : Cholesky
return Cholesky
Beispiel #1
0
        /// <summary>
        /// Run example
        /// </summary>
        /// <seealso cref="http://en.wikipedia.org/wiki/Cholesky_decomposition">Cholesky decomposition</seealso>
        public void Run()
        {
            // Format matrix output to console
            var formatProvider = (CultureInfo)CultureInfo.InvariantCulture.Clone();
            formatProvider.TextInfo.ListSeparator = " ";

            // Create square, symmetric, positive definite matrix
            var matrix = new DenseMatrix(new[,] { { 2.0, 1.0 }, { 1.0, 2.0 } });
            Console.WriteLine(@"Initial square, symmetric, positive definite matrix");
            Console.WriteLine(matrix.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Perform Cholesky decomposition
            var cholesky = matrix.Cholesky();
            Console.WriteLine(@"Perform Cholesky decomposition");

            // 1. Lower triangular form of the Cholesky matrix
            Console.WriteLine(@"1. Lower triangular form of the Cholesky matrix");
            Console.WriteLine(cholesky.Factor.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 2. Reconstruct initial matrix: A = L * LT
            var reconstruct = cholesky.Factor * cholesky.Factor.Transpose();
            Console.WriteLine(@"2. Reconstruct initial matrix: A = L*LT");
            Console.WriteLine(reconstruct.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 3. Get determinant of the matrix
            Console.WriteLine(@"3. Determinant of the matrix");
            Console.WriteLine(cholesky.Determinant);
            Console.WriteLine();

            // 4. Get log determinant of the matrix
            Console.WriteLine(@"4. Log determinant of the matrix");
            Console.WriteLine(cholesky.DeterminantLn);
            Console.WriteLine();
        }
Beispiel #2
0
 public void CholeskyFailsWithNonSquareMatrix()
 {
     var matrix = new DenseMatrix(3, 2);
     Assert.That(() => matrix.Cholesky(), Throws.ArgumentException);
 }