Click or drag to resize

ComplexMatrixMultiply Method (ComplexMatrix, ComplexMatrix)

Determines the product of two matrices.

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

Parameters

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

Return Value

Type: ComplexMatrix
The result of multiplying left by right.
Exceptions
ExceptionCondition
ArgumentNullExceptionleft is null.
-or-
right is null.
ArgumentException Both left and right are not scalar matrices, and the number of columns of left is not equal to the number of rows of right.
Remarks

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

LaTeX equation

Analogously, 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 operates as follows.

  • If left is scalar, then the method returns a matrix having the same dimensions of right, whose generic entry is:

    LaTeX equation

  • If right is scalar, then the method returns a matrix having the same dimensions of left, whose generic entry is:

    LaTeX equation

  • If neither left nor right is scalar, then the method returns a matrix whose generic entry is

    LaTeX equation

    provided that the number of columns of left agrees with the number of rows of right; otherwise, an exception is thrown.

Examples

In the following example, some matrices are multiplied.

C#
using System;
using System.Numerics;

namespace Novacta.Analytics.CodeExamples
{
    public class ComplexMultiplicationExample0  
    {
        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.
            data = new Complex[4] {
                new Complex(10, -10), new Complex(50, -50),
                new Complex(20, -20), new Complex(60, -60)
            };
            var right = ComplexMatrix.Dense(2, 2, data, StorageOrder.RowMajor);
            Console.WriteLine("right =");
            Console.WriteLine(right);

            // Multiply 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 Multiply.
            result = ComplexMatrix.Multiply(left, right);

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

            // Both operators and alternative methods are overloaded to 
            // support read-only matrix arguments.
            // Compute the product 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 =
// (               10,              -10) (               50,              -50) 
// (               20,              -20) (               60,              -60) 
// 
// 
// 
// left * right =
// (                0,             -220) (                0,             -700) 
// (                0,             -280) (                0,             -920) 
// (                0,             -340) (                0,            -1140) 
// 
// 
// 
// ComplexMatrix.Multiply(left, right) returns
// 
// (                0,             -220) (                0,             -700) 
// (                0,             -280) (                0,             -920) 
// (                0,             -340) (                0,            -1140) 
// 
// 
// 
// readOnlyLeft * right =
// (                0,             -220) (                0,             -700) 
// (                0,             -280) (                0,             -920) 
// (                0,             -340) (                0,            -1140) 
// 

See Also