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:
| Operator | Equivalent Function | Description | Arguments |
|---|---|---|---|
+ | plus | addition | binary, compatible arrays |
- | minus | subtraction | binary, compatible arrays |
* | mtimes | multiplication | binary, matrices |
/ | mrdivide | right division | binary, matrices |
\ | mldivide | left division | binary, matrices |
^ | mpower | powers | binary, matrices |
' | ctranspose | complex conjugate transpose | unary, matrices |
.' | transpose | non-conjugate transpose | unary, 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 * Brequires the column count of A to equal the row count of B - Or
c * B,A * cwhere c is a scalar
- For example,
- 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 / Ais- Equivalent to
B * inv(A)using the inverse functioninv - 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)
- Equivalent to
- Left division
A \ Bis- 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
- Equivalent to
- Power requires at least one operand to be a scalar (denoted below by lowercase letters)
a ^ Bis- 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
expminstead uses , which has no such requirement on - Therefore
^may give a result different fromexpm; in particular,^may raise an error
- Equivalent to the matrix exponential function
A ^ aisa ^ bis equivalent toa .^ b
- The transpose
.'is the only matrix operator that contains a dot.yet is not an array operation