Click or drag to resize

DoubleMatrixMultiply Operator (Double, DoubleMatrix)

Determines the multiplication of a scalar by a matrix.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static DoubleMatrix operator *(
	double left,
	DoubleMatrix right
)

Parameters

left
Type: SystemDouble
The left operand.
right
Type: Novacta.AnalyticsDoubleMatrix
The right operand.

Return Value

Type: DoubleMatrix
The result of multiplying right by 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 scalar is multiplied by a matrix.

C#
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class MultiplicationExample2  
    {
        public void Main()
        {
            // Create the left operand.
            double left = 10.0;
            Console.WriteLine("left =");
            Console.WriteLine(left);
            Console.WriteLine();

            // Create the right operand.
            var data = new double[6] {
                0,  20,  40,
               10,  30,  50,
            };
            var right = DoubleMatrix.Dense(2, 3, 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 = DoubleMatrix.Multiply(left, right);

            Console.WriteLine();
            Console.WriteLine("DoubleMatrix.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 right.
            ReadOnlyDoubleMatrix readOnlyRight = right.AsReadOnly();
            result = left * readOnlyRight;

            Console.WriteLine();
            Console.WriteLine("left * readOnlyRight =");
            Console.WriteLine(result);
        }
    }
}

// Executing method Main() produces the following output:
// 
// left =
// 10
// 
// right =
// 0                20               40               
// 10               30               50               
// 
// 
// 
// left * right =
// 0                200              400              
// 100              300              500              
// 
// 
// 
// DoubleMatrix.Multiply(left, right) returns
// 
// 0                200              400              
// 100              300              500              
// 
// 
// 
// left * readOnlyRight =
// 0                200              400              
// 100              300              500              
// 

See Also