scalar, Vector, and Matrix multiplication - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Mathematics : Linear Algebra : LinearAlgebra Package : Modular Subpackage : LinearAlgebra/Modular/Multiply

LinearAlgebra[Modular][Multiply] - scalar, Vector, and Matrix multiplication

Calling Sequence

Multiply(m, A, B, order, 'sparse')

Multiply(m, A, B, C, 'sparse')

Parameters

m

-

modulus

A

-

scalar, Matrix, or Vector including subspec

B

-

Matrix or Vector, including subspec

order

-

(optional) ordering of output object; C_order or Fortran_order

sparse

-

(optional) controls behavior of operation

C

-

output Matrix or Vector, including subspec

Description

• 

The Multiply function performs the operation A*B placing the output in a new object, or in C, depending on calling sequence. All Matrices or Vectors must have the same datatype. Multiply can perform Matrix-Matrix, Matrix-Vector, Vector-Matrix, scalar-Matrix, Vector-Vector, or scalar-Vector multiplication with output as a scalar,Vector or Matrix. The output depends on the input specification.

  

The first calling sequence returns a scalar or new mod m Matrix or Vector for the result with the specified ordering order, or the ordering of the input objects A and B.

  

Note: If A and B are both Matrices or Vectors and have a different ordering, order must be specified.

  

The remaining calling sequence places the output of the computation into C, returning NULL.

• 

Scalar multiplication can be performed by setting A to a scalar value in the range 1..m1, and specifying B as a mod m Matrix or Vector. In this case, C can be specified as the same Matrix or Vector as B as long as the operation is performed with direct overlap. For example, if B and C are the same Matrix, the operation involving the entry Bi,j must have the result going to Ci,j.

  

If the optional keyword, 'sparse', is specified, it only applies to scalar multiplication if the multiplier is not 1 or m1 and the datatype is a hardware datatype. It indicates that the algorithm checks for zero entries before performing multiplications. This typically provides an efficiency gain when matrices have 10% or more entries in B equal to zero. This is not implemented for the integer datatype, as it typically provides very little gain for that case.

  

Note: If sparse does not apply but it has been specified, the option is ignored.

• 

For multiplication of two mod m Matrices or Vectors, the number of columns in A must be equal to the number of rows in B, and the result has dimensions equal to rowsAxcolsB.

  

For example, if A is a row Vector, and B is a column Vector, the result is a zero dimensional value representing the dot product of A and B. In this case, the output of the first calling sequence is a scalar value. For the second calling sequence, the entry in C into which this value is placed is determined by the sub-Matrix or sub-Vector specification for C.

  

Alternatively, if A is a column Vector, and B is a row Vector, the result is a Matrix which represents the outer product of A and B.

• 

The Multiply function allows the use of sub-Matrix and sub-Vector specifications for both input and output Vectors/Matrices. For example, the function can be used to multiply a row of a Matrix to the transpose of a row in another Matrix, placing the result in a specified entry of a third Matrix.

• 

Note: For scalar multiplication, B and C are allowed direct overlap. If both A and B are mod m Matrices or Vectors and if either overlap with C, the behavior of Multiply is undefined.

• 

This command is part of the LinearAlgebra[Modular] package, so it can be used in the form Multiply(..) only after executing the command with(LinearAlgebra[Modular]).  However, it can always be used in the form LinearAlgebra[Modular][Multiply](..).

Examples

withLinearAlgebra[Modular]:

A:=Mod13,Vectorrow4,i→rand,integer[]

A:=100812

(1)

B:=Mod13,Vectorcolumn4,i→rand,integer[]

B:=26011

(2)

The inner product.

Multiply13,A,B

9

(3)

The outer product.

Multiply13,B,A

703118097000060102

(4)

The inner product into existing Matrix.

C:=Create13,2,2,integer[]

C:=0000

(5)

Multiply13,A,B,C,1,2:

C

0900

(6)

Matrix-Vector multiplication.

A:=Mod13,Matrix3,4,i,j→rand,integer[]

A:=92117411121189411

(7)

Multiply13,A,B

309

(8)

Vector-Matrix multiplication.

B:=Mod13,Vectorrow3,i→rand,integer[]

B:=1035

(9)

Multiply13,B,A

127102

(10)

Scalar multiplication of A into A.

Multiply13,2,A,A:

A

5491891193589

(11)

Multiplication of the third row of A to the transpose of A, with result being placed in a specified location of a new Matrix.

C:=Create13,2,6,integer[]

C:=000000000000

(12)

Multiply13,A,3,A,'transpose',C,2,2..4:

C

00000001241000

(13)

See Also

LinearAlgebra/Details, LinearAlgebra[Modular], LinearAlgebra[Modular][Create], LinearAlgebra[Modular][Mod], LinearAlgebra[Modular][subspec], Vector


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam