Click or drag to resize

SpectralDecompositionDecompose Method (ReadOnlyDoubleMatrix, Boolean, DoubleMatrix)

Computes eigenvalues and eigenvectors of the specified symmetric real matrix.

Namespace:  Novacta.Analytics.Advanced
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static DoubleMatrix Decompose(
	ReadOnlyDoubleMatrix matrix,
	bool lowerTriangularPart,
	out DoubleMatrix eigenvectors
)

Parameters

matrix
Type: Novacta.AnalyticsReadOnlyDoubleMatrix
The matrix containing the lower or upper triangular part of the matrix whose spectral decomposition must be computed.
lowerTriangularPart
Type: SystemBoolean
true if matrix contains the lower triangular part of the matrix to be decomposed; false if matrix contains its upper triangular part.
eigenvectors
Type: Novacta.AnalyticsDoubleMatrix
A matrix whose columns represent the eigenvectors of the decomposed matrix.

Return Value

Type: DoubleMatrix
A diagonal matrix containing the eigenvalues of the decomposed matrix, in ascending order.
Exceptions
ExceptionCondition
ArgumentNullExceptionmatrix is null.
ArgumentExceptionmatrix is not square.
Examples

In the following example, the spectral decomposition of a matrix is computed.

Computing the Spectral decomposition of a matrix
using System;
using Novacta.Analytics.Advanced;

namespace Novacta.Analytics.CodeExamples.Advanced
{
    public class SpectralDecompositionExample0  
    {
        public void Main()
        {
            // Create a matrix containing the
            // lower triangular part of the symmetric matrix
            // to be decomposed.
            var data = new double[9] {
                2,
                2,
                0,
                0,
                0,
                0,
                1,
                0,
                5
            };
            var matrix = DoubleMatrix.Dense(3, 3, data);

            // Set the relevant triangular part.
            bool lowerTriangularPart = true;

            Console.WriteLine("Matrix to be decomposed:");
            Console.WriteLine(DoubleMatrix.Dense(3, 3, new double[9] {
                2,
                2,
                0,
                2,
                0,
                0,
                0,
                0,
                5
            }));

            // Compute the Spectral decomposition.
            var eigenvalues = SpectralDecomposition.Decompose(
                matrix,
                lowerTriangularPart,
                out DoubleMatrix eigenvectors);

            Console.WriteLine();
            Console.WriteLine("Eigenvalues:");
            Console.WriteLine(eigenvalues);
            Console.WriteLine();
            Console.WriteLine("Eigenvectors:");
            Console.WriteLine(eigenvectors);
            Console.WriteLine();
            Console.WriteLine("Matrix reconstruction:");
            var l = eigenvalues;
            var v = eigenvectors;
            Console.WriteLine(v * l * v.Transpose());
        }
    }
}

// Executing method Main() produces the following output:
// 
// Matrix to be decomposed:
// 2                2                0                
// 2                0                0                
// 0                0                5                
// 
// 
// 
// Eigenvalues:
// -1.23606798      0                0                
// 0                3.23606798       0                
// 0                0                5                
// 
// 
// 
// Eigenvectors:
// 0.525731112      -0.850650808     0                
// -0.850650808     -0.525731112     0                
// 0                0                1                
// 
// 
// 
// Matrix reconstruction:
// 2                2                0                
// 2                -1.11022302e-16  0                
// 0                0                5                
// 

See Also