ComplexMatrixDivide Method (Complex, ComplexMatrix) |
Namespace: Novacta.Analytics
Exception | Condition |
---|---|
ArgumentNullException | right is null. |
Let and
be the right
number of rows and columns, respectively, and let its generic entry given by
The method returns a matrix having
the same dimensions of right, whose generic
entry is:
In the following example, a scalar is divided by a matrix.
using System; using System.Numerics; namespace Novacta.Analytics.CodeExamples { public class ComplexDivisionExample2 { public void Main() { // Create the left operand. Complex left = new(2, -2); Console.WriteLine("left ="); Console.WriteLine(left); Console.WriteLine(); // Create the right operand. 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 right = ComplexMatrix.Dense(3, 2, data, StorageOrder.RowMajor); Console.WriteLine("right ="); Console.WriteLine(right); // Divide left by right. var result = left / right; Console.WriteLine(); Console.WriteLine("left / right ="); Console.WriteLine(result); // In .NET languages that do not support overloaded operators, // you can use the alternative methods named Divide. result = ComplexMatrix.Divide(left, right); Console.WriteLine(); Console.WriteLine("ComplexMatrix.Divide(left, right) returns"); Console.WriteLine(); Console.WriteLine(result); // Both operators and alternative methods are overloaded to // support read-only matrix arguments. // Compute the division using a read-only wrapper of right. ReadOnlyComplexMatrix readOnlyRight = right.AsReadOnly(); result = left / readOnlyRight; Console.WriteLine(); Console.WriteLine("left / readOnlyRight ="); Console.WriteLine(result); } } } // Executing method Main() produces the following output: // // left = // (2, -2) // // right = // ( 1, -1) ( 5, -5) // ( 2, -2) ( 6, -6) // ( 3, -3) ( 7, -7) // // // // left / right = // ( 2, -0) ( 0.4, -0) // ( 1, -0) ( 0.333333333, -0) // ( 0.666666667, -0) ( 0.285714286, -0) // // // // ComplexMatrix.Divide(left, right) returns // // ( 2, -0) ( 0.4, -0) // ( 1, -0) ( 0.333333333, -0) // ( 0.666666667, -0) ( 0.285714286, -0) // // // // left / readOnlyRight = // ( 2, -0) ( 0.4, -0) // ( 1, -0) ( 0.333333333, -0) // ( 0.666666667, -0) ( 0.285714286, -0) //