Click or drag to resize

ComplexMatrixDiagonal Method (ReadOnlyComplexMatrix)

Creates a square ComplexMatrix 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 ComplexMatrix Diagonal(
	ReadOnlyComplexMatrix mainDiagonal
)

Parameters

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

Return Value

Type: ComplexMatrix
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;
using System.Numerics;

namespace Novacta.Analytics.CodeExamples
{
    public class ComplexDiagonalExample0  
    {
        public void Main()
        {
            // Create the main diagonal data.
            var data = new Complex[2] {
                new Complex(1, -1),
                new Complex(2, -2)
            };

            // 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 = ComplexMatrix.Dense(
                2, 1, data);

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

            Console.WriteLine();

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

// Executing method Main() produces the following output:
// 
// The matrix storing main diagonal data:
// (                1,               -1) 
// (                2,               -2) 
// 
// 
// 
// The diagonal matrix:
// (                1,               -1) (                0,                0) 
// (                0,                0) (                2,               -2) 
// 

See Also