Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

mtimes - Matrix multiplication

Syntax

C = A*B

Description

C = A*B is the linear algebraic product of the matrices A and B. If A is an m-by-p and B is a p-by-n matrix, the i,j entry of C is defined by

The product C is an m-by-n matrix. For nonscalar A and B, the number of columns of A must equal the number of rows of B. You can multiply a scalar by a matrix of any size.

The preceding definition says that C(i,j) is the inner product of the ith row of A with the jth column of B. You can write this definition using the MATLAB colon operator as

C(i,j) = A(i,:)*B(:,j)

where A(i,:) is the ith row of A and B(:,j) is the jth row of B.

Examples

Example 1

If A is a row vector and B is a column vector with the same number of elements as A, A*B is simply the inner product of A and B. For example,

A = [5 3 2 6]

A =

     5     3     2     6
B = [-4 9 0 1]'

B =

    -4
     9
     0
     1
A*B

ans =

    13

Example 2

A = [1 3 5; 2 4 7]

A =

     1     3     5
     2     4     7
B = [-5 8 11; 3 9 21;4 0 8]

B =

    -5     8    11
     3     9    21
     4     0     8

The product of A and B is

C = A*B

C =

    24    35   114
    30    52   162

Note that the second row of A is

A(2,:)

ans =

     2     4     7

while the third column of B is

B(:,3)

ans =

    11
    21
     8

The inner product of A(2,:) and B(:,3) is

A(2,:)*B(:,3)

ans =

   162

which is the same as C(2,3).

Algorithm

mtimes uses the following Basic Linear Algebra Subroutines (BLAS):

For inputs of type single, mtimes using corresponding routines that begin with "S" instead of "D".

See Also

Arithmetic Operators

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2010- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS