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:
# Example Python program that computes the # Create a square matrix # Compute the condition number - uses SVD as norm # Compute the condition number using Frobenius norm
|
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 |