Click or drag to resize

ComplexMatrixAddition Operator (ComplexMatrix, Complex)

Determines the addition of a matrix to a scalar.

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

Parameters

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

Return Value

Type: ComplexMatrix
The result of adding left to right.
Exceptions
ExceptionCondition
ArgumentNullExceptionleft is null.
Remarks

Let LaTeX equation and LaTeX equation be the left number of rows and columns, respectively, and consider its generic entry

LaTeX equation

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

LaTeX equation

Examples

In the following example, a matrix is added to a scalar.

C#
using System;
using System.Numerics;

namespace Novacta.Analytics.CodeExamples
{
    public class ComplexAdditionExample1  
    {
        public void Main()
        {
            // Create the left 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 left = ComplexMatrix.Dense(3, 2, data, StorageOrder.RowMajor);
            Console.WriteLine("left =");
            Console.WriteLine(left);

            // Create the right operand.
            Complex right = new(7, -7);
            Console.WriteLine("right =");
            Console.WriteLine(right);

            // Compute the sum of left and 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 Add.
            result = ComplexMatrix.Add(left, right);

            Console.WriteLine();
            Console.WriteLine("ComplexMatrix.Add(left, right) returns");
            Console.WriteLine();
            Console.WriteLine(result);

            // Both operators and alternative methods are overloaded to 
            // support read-only matrix arguments.
            // Compute the sum using a read-only wrapper of left.
            ReadOnlyComplexMatrix readOnlyLeft = left.AsReadOnly();
            result = readOnlyLeft + right;

            Console.WriteLine();
            Console.WriteLine("readOnlyLeft + right =");
            Console.WriteLine(result);
        }
    }
}

// Executing method Main() produces the following output:
// 
// left =
// (                1,               -1) (                5,               -5) 
// (                2,               -2) (                6,               -6) 
// (                3,               -3) (                7,               -7) 
// 
// 
// right =
// (7, -7)
// 
// left + right =
// (                8,               -8) (               12,              -12) 
// (                9,               -9) (               13,              -13) 
// (               10,              -10) (               14,              -14) 
// 
// 
// 
// ComplexMatrix.Add(left, right) returns
// 
// (                8,               -8) (               12,              -12) 
// (                9,               -9) (               13,              -13) 
// (               10,              -10) (               14,              -14) 
// 
// 
// 
// readOnlyLeft + right =
// (                8,               -8) (               12,              -12) 
// (                9,               -9) (               13,              -13) 
// (               10,              -10) (               14,              -14) 
// 

See Also