ReadOnlyDoubleMatrixSubtraction Operator (ReadOnlyDoubleMatrix, Double) |
Namespace: Novacta.Analytics
Exception | Condition |
---|---|
ArgumentNullException | left is null. |
Let and
be the left
number of rows and columns, respectively, and consider its generic entry
The method returns a matrix
having the same dimensions of left, whose generic
entry is:
In the following example, a scalar is subtracted from a matrix.
using System; namespace Novacta.Analytics.CodeExamples { public class SubtractionExample1 { public void Main() { // Create the left operand. var data = new double[6] { 0, 2, 4, 1, 3, 5, }; var left = DoubleMatrix.Dense(2, 3, data, StorageOrder.RowMajor); Console.WriteLine("left ="); Console.WriteLine(left); // Create the right operand. double right = 10.0; Console.WriteLine("right ="); Console.WriteLine(right); // Subtract right from left. 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 Subtract. result = DoubleMatrix.Subtract(left, right); Console.WriteLine(); Console.WriteLine("DoubleMatrix.Subtract(left, right) returns"); Console.WriteLine(); Console.WriteLine(result); // Both operators and alternative methods are overloaded to // support read-only matrix arguments. // Compute the subtraction using a read-only wrapper of left. ReadOnlyDoubleMatrix readOnlyLeft = left.AsReadOnly(); result = readOnlyLeft - right; Console.WriteLine(); Console.WriteLine("readOnlyLeft - right ="); Console.WriteLine(result); } } } // Executing method Main() produces the following output: // // left = // 0 2 4 // 1 3 5 // // // right = // 10 // // left - right = // -10 -8 -6 // -9 -7 -5 // // // // DoubleMatrix.Subtract(left, right) returns // // -10 -8 -6 // -9 -7 -5 // // // // readOnlyLeft - right = // -10 -8 -6 // -9 -7 -5 //