Main Content

cond

Condition number for inversion

Description

example

C = cond(A) returns the 2-norm condition number for inversion, equal to the ratio of the largest singular value of A to the smallest.

example

C = cond(A,p) returns the p-norm condition number, where p can be 1, 2, Inf, or 'fro'.

Examples

collapse all

Calculate the condition number of a matrix and examine the sensitivity to the inverse calculation.

Create a 2-by-2 matrix.

A = [4.1 2.8;
     9.7 6.6];

Calculate the 2-norm condition number of A.

C = cond(A)
C = 1.6230e+03

Since the condition number of A is much larger than 1, the matrix is sensitive to the inverse calculation. Calculate the inverse of A, and then make a small change in the second row of A and calculate the inverse again.

invA = inv(A)
invA = 2×2

  -66.0000   28.0000
   97.0000  -41.0000

A2 = [4.1    2.8; 
      9.671  6.608]
A2 = 2×2

    4.1000    2.8000
    9.6710    6.6080

invA2 = inv(A2)
invA2 = 2×2

  472.0000 -200.0000
 -690.7857  292.8571

The results indicate that making a small change in A can completely change the result of the inverse calculation.

Calculate the 1-norm condition number of a matrix.

Create a 3-by-3 matrix.

A = [1 0 -2;
     3 4  6;
    -1 5  7];

Calculate the 1-norm condition number of A. The value of the 1-norm condition number for an m-by-n matrix is

κ1(A)=||A||1||A-1||1,

where the 1-norm is the maximum absolute column sum of the matrix given by

||A||1=max1jni=1m|aij|.

C = cond(A,1)
C = 18.0000

For this matrix the condition number is not too large, so the matrix is not particularly sensitive to the inverse calculation.

Input Arguments

collapse all

Input matrix. A can be either square or rectangular in size.

Data Types: single | double
Complex Number Support: Yes

Norm type, specified as one of the values shown in this table. cond computes the condition number using norm(A,p) * norm(inv(A),p) for values of p other than 2. See the norm page for additional information about these norm types.

Value of p

Norm Type

1

1-norm condition number

2

2-norm condition number

Inf

Infinity norm condition number

'fro'

Frobenius norm condition number

Example: cond(A,1) calculates the 1-norm condition number.

Output Arguments

collapse all

Condition number, returned as a scalar. Values of C near 1 indicate a well-conditioned matrix, and large values of C indicate an ill-conditioned matrix. Singular matrices have a condition number of Inf.

By convention, the condition number of an empty matrix is zero.

More About

collapse all

Condition Number for Inversion

A condition number for a matrix and computational task measures how sensitive the answer is to changes in the input data and roundoff errors in the solution process.

The condition number for inversion of a matrix measures the sensitivity of the solution of a system of linear equations to errors in the data. It gives an indication of the accuracy of the results from matrix inversion and the linear equation solution. For example, the 2-norm condition number of a square matrix is

κ(A)=AA1.

In this context, a large condition number indicates that a small change in the coefficient matrix A can lead to larger changes in the output b in the linear equations Ax = b and xA = b. The extreme case is when A is so poorly conditioned that it is singular (an infinite condition number), in which case it has no inverse and the linear equation has no unique solution.

Tips

  • rcond is a more efficient, but less reliable, method of estimating the condition of a matrix compared to cond.

Algorithms

The algorithm for cond has three pieces:

  • If p = 2, then cond uses the singular value decomposition provided by svd to find the ratio of the largest and smallest singular values.

  • If p = 1, Inf, or 'fro', then cond calculates the condition number using the appropriate norm of the input matrix and its inverse with norm(A,p) * norm(inv(A),p).

  • If the input matrix is sparse, then cond ignores any specified p value and calls condest.

Extended Capabilities

Version History

Introduced before R2006a

expand all