Condition number of a matrix

The condition number of a matrix is the maximum bound to which any perturbations to the input data will result in the change in output.

Linear Algebra Updated 10 Apr 2025 1 min read

Overview

  • The condition number of a matrix is defined as the product of its norm and the norm of its inverse.

    k(A) = ||A||.||A-1||

  • On a system of linear equations, the condition number gives the bound to which the solution will vary to a change in input data.
  • A smaller condition number means, a change in the input data even if it is large will result in a small amount of change in the output.
  • A larger condition number means, a change in the input data even if it is small will result in a large amount of change in the output.
  • For a singular matrix the condition number is infinity(∞)

Computing the condition number of a matrix using NumPy

  • The NumPy module linalg has the function cond() that computes the condition number of a given matrix.
  • The matrix norm to be used can be specified through the parameter p of the cond() function. When no value is specified it uses the smallest of the singular values calculated using SVD.

Example

python
# Example Python program that computes the

            # condition number of a matrix

            import numpy

# Create a square matrix

            elems     = numpy.arange(1, 18, 2)

            matrix  = elems.reshape(3, 3)

            print("Matrix:")

            print(matrix)

# Compute the condition number - uses SVD as norm

            conditionNumber =  numpy.linalg.cond(matrix)

            print("Condition number computed using smallest of singular values as norm:")

            print(conditionNumber)

# Compute the condition number using Frobenius norm

            conditionNumber =  numpy.linalg.cond(matrix, 'fro')

            print("Condition number computed using Frobenius norm:")

            print(conditionNumber)

Output

Output
Matrix:

            [[ 1  3  5]

             [ 7  9 11]

             [13 15 17]]

            Condition number computed using smallest of singular values as norm:

            2.3721000095398664e+16

            Condition number computed using Frobenius norm:

            7.0095746850180696e+16