mtimes

Matrix multiplication, the * operator.

Category: Mathematics > Linear Algebra

Syntax

C = A*B

Matrix product of A and B.

C = mtimes(A, B)

Function form of A*B.

Description

The inner dimensions must agree, otherwise an error about incorrect dimensions is raised. A row times a column gives a scalar; a column times a row gives a matrix (the outer product). The product is not commutative: A*B and B*A generally differ.

The element-by-element product is .* (times). If either operand is a scalar, * scales every element.

Input arguments

A
Matrix with as many columns as B has rows (or a scalar).
B
Matrix or scalar.

Output arguments

C
Matrix with size(A,1) rows and size(B,2) columns; C(i,j) is the dot product of row i of A with column j of B.

Example

Matrix, inner and outer products

[1 2; 3 4] * [1; 1]
[1 2 3] * [1; 2; 3]
[1; 2] * [3 4]
Output
ans = 2×1

     3
     7
ans = 14
ans = 2×2

     3     4
     6     8

See also

times mldivide mpower dot kron