Matrix Operations

  • In this note, “matrices” means 2-D numeric arrays, including scalars and vectors.

MATLAB has two flavors of Matlab Arithmetic Operations: matrix operations and Matlab Array Operations.

Matrix operations are the matrix manipulations of Linear Algebra, as opposed to the element-by-element computations of Matlab Array Operations.

Operators

The basic unary and binary numeric matrix operations all have an operator form:

OperatorEquivalent FunctionDescriptionArguments
+plusadditionbinary, compatible arrays
-minussubtractionbinary, compatible arrays
*mtimesmultiplicationbinary, matrices
/mrdivideright divisionbinary, matrices
\mldivideleft divisionbinary, matrices
^mpowerpowersbinary, matrices
'ctransposecomplex conjugate transposeunary, matrices
.'transposenon-conjugate transposeunary, matrices

Notes

  • In the table above, “compatible arrays” means the operands may be N-D arrays as long as they satisfy Matlab Compatible Array Sizes
  • “matrices” refers to ordinary matrix arithmetic and scalar arithmetic
    • For example, A * B requires the column count of A to equal the row count of B
    • Or c * B, A * c where c is a scalar
  • Notice that every operation requiring matrix operands maps to a function name beginning with m, indicating “matrix operation”
  • Addition + and subtraction - coincide with their array-operation counterparts
  • Multiplication *, when one operand is a scalar, behaves like .*
  • Right division B / A is
    • Equivalent to B * inv(A) using the inverse function inv
    • When A is a scalar, this reduces to ./
    • In particular, A may be non-square; in that case the operation is equivalent to using the pseudo-inverse pinv: B * pinv(A)
  • Left division A \ B is
    • Equivalent to inv(A) * B
    • When A is a scalar, this reduces to .\
    • In particular, A may be non-square; in that case the operation is equivalent to pinv(A) * B
  • Power requires at least one operand to be a scalar (denoted below by lowercase letters)
    • a ^ B is
      • Equivalent to the matrix exponential function expm: expm(log(a) * B)
      • ++Caution++
        • The power operator computes , where and are the matrices of eigenvectors (as columns) and eigenvalues (on the diagonal) of , so that
        • This algorithm requires ‘s eigenvectors to be linearly independent so that is invertible
        • The function expm instead uses , which has no such requirement on
        • Therefore ^ may give a result different from expm; in particular, ^ may raise an error
    • A ^ a is
    • a ^ b is equivalent to a .^ b
  • The transpose .' is the only matrix operator that contains a dot . yet is not an array operation