MATLAB Functions | Help Desk |
Arithmetic Operators + - * / \ ^ '
Matrix and array arithmeticA+B A-B A*B A.*B A/B A./B A\B A.\B A^B A.^B A' A.'MATLAB has two different types of arithmetic operations. Matrix arithmetic operations are defined by the rules of linear algebra. Array arithmetic operations are carried out element-by-element. The period character (.) distinguishes the array operations from the matrix operations. However, since the matrix and array operations are the same for addition and subtraction, the character pairs
.+
and .-
are not used.format
rat
.X = A\B
and X = B/A
depends upon the structure of the coefficient matrix A
.
A
is a triangular matrix, or a permutation of a triangular matrix, then X
can be computed quickly by a permuted backsubstitution algorithm. The check for triangularity is done for full matrices by testing for zero elements and for sparse matrices by accessing the sparse data structure. Most nontriangular matrices are detected almost immediately, so this check requires a negligible amount of time.
A
is symmetric, or Hermitian, and has positive diagonal elements, then a Cholesky factorization is attempted (see chol
). If A
is sparse, a symmetric minimum degree preordering is applied (see symmmd
and spparms
). If A
is found to be positive definite, the Cholesky factorization attempt is successful and requires less than half the time of a general factorization. Nonpositive definite matrices are usually detected almost immediately, so this check also requires little time. If successful, the Cholesky factorization is
A = R'*R
where R
is upper triangular. The solution X
is computed by solving two triangular systems,
X = R\(R'\B)
A
is square, but not a permutation of a triangular matrix, or is not Hermitian with positive elements, or the Cholesky factorization fails, then a general triangular factorization is computed by Gaussian elimination with partial pivoting (see lu
). If A
is sparse, a nonsymmetric minimum degree preordering is applied (see colmmd
and spparms
). This results in
A = L*U
where L
is a permutation of a lower triangular matrix and U
is an upper triangular matrix. Then X
is computed by solving two permuted triangular systems.
X = U\(L\B)
A
is not square and is full, then Householder reflections are used to compute an orthogonal-triangular factorization.
A*P = Q*R
where P
is a permutation, Q
is orthogonal and R
is upper triangular (see qr
). The least squares solution X
is computed with
X = P*(R\(Q'*B)
A
is not square and is sparse, then the augmented matrix is formed by:
S = [c*I A; A' 0]
The default for the residual scaling factor is c = max(max(abs(A)))/1000
(see spparms
). The least squares solution X
and the residual R = B-A
*X
are computed by
S * [R/c; X] = [B; 0]
with minimum degree preordering and sparse Gaussian elimination with numerical pivoting.
The various matrix factorizations are computed by MATLAB implementations of the algorithms employed by LINPACK routines ZGECO
, ZGEFA
and ZGESL
for square matrices and ZQRDC
and ZQRSL
for rectangular matrices. See the LINPACK Users' Guide for details.
A
is singular:
Matrix is singular to working precision.From element-wise division, if the divisor has zero elements:
Divide by zero.On machines without IEEE arithmetic, like the VAX, the above two operations generate the error messages shown. On machines with IEEE arithmetic, only warning messages are generated. The matrix division returns a matrix with each element set to
Inf
; the element-wise division produces NaN
s or Inf
s where appropriate.
If the inverse was found, but is not reliable:
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = xxxFrom matrix division, if a nonsquare
A
is rank deficient:
Warning: Rank deficient, rank = xxx tol = xxx
det
Matrix determinant
inv
Matrix inverse
lu
LU matrix factorization
orth
Range space of a matrix
qr
Orthogonal-triangular decomposition
rref
Reduced row echelon form