Click or drag to resize

ComplexMatrixSubtract Method (Complex, ComplexMatrix)

Determines the subtraction of a matrix from a scalar.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static ComplexMatrix Subtract(
	Complex left,
	ComplexMatrix right
)

Parameters

left
Type: System.NumericsComplex
The left operand.
right
Type: Novacta.AnalyticsComplexMatrix
The right operand.

Return Value

Type: ComplexMatrix
The result of subtracting right from left.
Exceptions
ExceptionCondition
ArgumentNullExceptionright is null.
Remarks

Let LaTeX equation and LaTeX equation be the right number of rows and columns, respectively, and let its generic entry given by

LaTeX equation

The method returns a matrix having the same dimensions of right, whose generic entry is:

LaTeX equation

Examples

In the following example, a matrix is subtracted from a scalar.

C#
using System;
using System.Numerics;

namespace Novacta.Analytics.CodeExamples
{
    public class ComplexSubtractionExample2  
    {
        public void Main()
        {
            // Create the left operand.
            Complex left = new(8, -8);
            Console.WriteLine("left =");
            Console.WriteLine(left);
            Console.WriteLine();

            // Create the right operand.
            var data = new Complex[8] {
                new Complex(1, -1), new Complex(5, -5),
                new Complex(2, -2), new Complex(6, -6),
                new Complex(3, -3), new Complex(7, -7),
                new Complex(4, -4), new Complex(8, -8)
            };
            var right = ComplexMatrix.Dense(4, 2, data, StorageOrder.RowMajor);
            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 = ComplexMatrix.Subtract(left, right);

            Console.WriteLine();
            Console.WriteLine("ComplexMatrix.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 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 =
// (8, -8)
// 
// right =
// (                1,               -1) (                5,               -5) 
// (                2,               -2) (                6,               -6) 
// (                3,               -3) (                7,               -7) 
// (                4,               -4) (                8,               -8) 
// 
// 
// 
// left - right =
// (                7,               -7) (                3,               -3) 
// (                6,               -6) (                2,               -2) 
// (                5,               -5) (                1,               -1) 
// (                4,               -4) (                0,                0) 
// 
// 
// 
// ComplexMatrix.Subtract(left, right) returns
// 
// (                7,               -7) (                3,               -3) 
// (                6,               -6) (                2,               -2) 
// (                5,               -5) (                1,               -1) 
// (                4,               -4) (                0,                0) 
// 
// 
// 
// left - readOnlyRight =
// (                7,               -7) (                3,               -3) 
// (                6,               -6) (                2,               -2) 
// (                5,               -5) (                1,               -1) 
// (                4,               -4) (                0,                0) 
// 

See Also