ComplexMatrixApply Method |
Namespace: Novacta.Analytics
Exception | Condition |
---|---|
ArgumentNullException | func is null. |
Let be a matrix, and consider its generic entry
where and
are the
number of rows and columns of , respectively.
Let the function represented by func. Then method Apply(FuncComplex, Complex) returns a matrix, say , having the same dimensions of by setting
In the following example, a new matrix is built by squaring all the entries in a given matrix.
using System; using System.Numerics; namespace Novacta.Analytics.CodeExamples { public class ComplexOutPlaceApplyExample0 { public void Main() { // Create a matrix. var data = new Complex[6] { new Complex(1, -1), new Complex(5, -5), new Complex(2, -2), new Complex(6, -6), new Complex(3, -3), new Complex(7, -7) }; var matrix = ComplexMatrix.Dense(3, 2, data, StorageOrder.RowMajor); Console.WriteLine("The data matrix:"); Console.WriteLine(matrix); // Return a matrix obtained by adding 1 to each entry // of the initial matrix. var plusOneMatrix = matrix.Apply((x) => x + 1); Console.WriteLine(); Console.WriteLine("Matrix obtained by adding 1 to each entry:"); Console.WriteLine(plusOneMatrix); // Add one using a read-only wrapper of the data matrix. ReadOnlyComplexMatrix readOnlyMatrix = matrix.AsReadOnly(); var plusOneReadOnlyMatrix = readOnlyMatrix.Apply((x) => x + 1); Console.WriteLine(); Console.WriteLine("Adding 1 to each entry of a read only matrix:"); Console.WriteLine(plusOneReadOnlyMatrix); } } } // Executing method Main() produces the following output: // // The data matrix: // ( 1, -1) ( 5, -5) // ( 2, -2) ( 6, -6) // ( 3, -3) ( 7, -7) // // // // Matrix obtained by adding 1 to each entry: // ( 2, -1) ( 6, -5) // ( 3, -2) ( 7, -6) // ( 4, -3) ( 8, -7) // // // // Adding 1 to each entry of a read only matrix: // ( 2, -1) ( 6, -5) // ( 3, -2) ( 7, -6) // ( 4, -3) ( 8, -7) //