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'*RThe various matrix factorizations are computed by MATLAB implementations of the algorithms employed by LINPACK routineswhere
R
is upper triangular. The solutionX
is computed by solving two triangular systems, X = R\(R'\B) IfA
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 (seelu
). IfA
is sparse, a nonsymmetric minimum degree preordering is applied (seecolmmd
andspparms
). This results inwhere
L
is a permutation of a lower triangular matrix andU
is an upper triangular matrix. ThenX
is computed by solving two permuted triangular systems. X = U\(L\B) IfA
is not square and is full, then Householder reflections are used to compute an orthogonal-triangular factorization.where
P
is a permutation,Q
is orthogonal andR
is upper triangular (seeqr
). The least squares solutionX
is computed with X = P*(R\(Q'*B) IfA
is not square and is sparse, then the augmented matrix is formed by:The default for the residual scaling factor is
c = max(max(abs(A)))/1000
(seespparms
). The least squares solutionX
and the residualR = B-A
*X
are computed bywith minimum degree preordering and sparse Gaussian elimination with numerical pivoting.
ZGECO
, ZGEFA
and ZGESL
for square matrices and ZQRDC
and ZQRSL
for rectangular matrices. See the LINPACK Users' Guide for details.
From matrix division, if a square 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