Click or drag to resize

DoubleMatrixDiagonal Method (DoubleMatrix)

Creates a square DoubleMatrix instance having the specified data on its main diagonal and zero otherwise.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static DoubleMatrix Diagonal(
	DoubleMatrix mainDiagonal
)

Parameters

mainDiagonal
Type: Novacta.AnalyticsDoubleMatrix
The data to be inserted in the main diagonal of the matrix.

Return Value

Type: DoubleMatrix
The diagonal matrix having the specified main diagonal data.
Exceptions
ExceptionCondition
ArgumentNullExceptionmainDiagonal is null.
Remarks

Parameter mainDiagonal is a matrix storing the main diagonal data. Both NumberOfRows and NumberOfColumns of the created diagonal matrix will be equal to the Count of mainDiagonal. Note that mainDiagonal can have any size: if it is not a vector, its entries will be inserted in the main diagonal of the created diagonal matrix assuming ColumnMajor ordering.

Examples

In the following example, a diagonal matrix is created.

Creation of a diagonal matrix
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class DiagonalExample0  
    {
        public void Main()
        {
            // Create the main diagonal data.
            var data = new double[6] {
               1,  2,  3,  4,  5,  6
            };

            // Create a matrix storing the main diagonal data.
            // Note that such matrix can have any size: if it is not
            // a vector, its entries will be inserted in the main
            // diagonal of the diagonal matrix assuming ColMajor ordering.
            var mainDiagonal = DoubleMatrix.Dense(
                2, 3, data);

            Console.WriteLine("The matrix storing main diagonal data:");
            Console.WriteLine(mainDiagonal);

            Console.WriteLine();

            // Create the diagonal matrix.
            var diagonalMatrix = DoubleMatrix.Diagonal(
                mainDiagonal);
            Console.WriteLine("The diagonal matrix:");
            Console.WriteLine(diagonalMatrix);
        }
    }
}

// Executing method Main() produces the following output:
// 
// The matrix storing main diagonal data:
// 1                3                5                
// 2                4                6                
// 
// 
// 
// The diagonal matrix:
// 1                0                0                0                0                0                
// 0                2                0                0                0                0                
// 0                0                3                0                0                0                
// 0                0                0                4                0                0                
// 0                0                0                0                5                0                
// 0                0                0                0                0                6                
// 

See Also