| 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
Ris upper triangular. The solutionXis computed by solving two triangular systems, X = R\(R'\B) IfAis 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). IfAis sparse, a nonsymmetric minimum degree preordering is applied (seecolmmdandspparms). This results inwhere
Lis a permutation of a lower triangular matrix andUis an upper triangular matrix. ThenXis computed by solving two permuted triangular systems. X = U\(L\B) IfAis not square and is full, then Householder reflections are used to compute an orthogonal-triangular factorization.where
Pis a permutation,Qis orthogonal andRis upper triangular (seeqr). The least squares solutionXis computed with X = P*(R\(Q'*B) IfAis 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 solutionXand the residualR = B-A*Xare 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 NaNs or Infs 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 = xxx
From 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