ComplexMatrixVec Method (IndexCollection) |
Namespace: Novacta.Analytics
Exception | Condition |
---|---|
ArgumentNullException | linearIndexes is null. |
ArgumentOutOfRangeException | linearIndexes contains an index which is greater than or equal to the Count of this instance. |
Let be a matrix, and consider its generic entry
where and
are the
number of rows and columns of , respectively.
A linear index completely
identifies an entry,
assuming that entries are linearly ordered following the
ColumnMajor
data order. This means that entry has linear
index equal to , and matrix entries can be enumerated as
follows:
where is the Count of the matrix.
Let the collection of
indexes represented by linearIndexes.
This method, when called on a ComplexMatrix instance
representing matrix , returns a new
ComplexMatrix instance that
represents a column vector, say ,
such that:
In the following example, some matrix entries are vectorized.
using System; using System.Numerics; namespace Novacta.Analytics.CodeExamples { public class ComplexVecExample1 { public void Main() { // Create a matrix. var data = new Complex[4] { new Complex(1, -1), new Complex(5, -5), new Complex(2, -2), new Complex(6, -6) }; var matrix = ComplexMatrix.Dense(2, 2, data, StorageOrder.RowMajor); Console.WriteLine("Initial data matrix:"); Console.WriteLine(matrix); // Get the linear indexes of elements on // the main diagonal. var mainDiagonalIndexes = IndexCollection.Sequence(0, 3, 3); // Get the vectorization of the matrix main diagonal. var mainDiagonal = matrix.Vec(mainDiagonalIndexes); Console.WriteLine(); Console.WriteLine("Vectorized main diagonal:"); Console.WriteLine(mainDiagonal); // Entries can also be vectorized using a read-only wrapper of the matrix. ReadOnlyComplexMatrix readOnlyMatrix = matrix.AsReadOnly(); Console.WriteLine(); Console.WriteLine("Vectorized main diagonal of a read-only data matrix:"); Console.WriteLine(readOnlyMatrix.Vec(mainDiagonalIndexes)); } } } // Executing method Main() produces the following output: // // Initial data matrix: // ( 1, -1) ( 5, -5) // ( 2, -2) ( 6, -6) // // // // Vectorized main diagonal: // ( 1, -1) // ( 6, -6) // // // // Vectorized main diagonal of a read-only data matrix: // ( 1, -1) // ( 6, -6) //