Condition Number Calculator
Welcome to the condition number calculator. Need to determine whether your linear algebra problem is well-conditioned or unstable? Will incorrect measurements or poor rounding be the downfall of your matrix equation? Here, we'll show you what a matrix condition number is and how to find the condition number of any matrix, so that you can protect yourself against any errors that may creep in.
What is the condition number of a matrix?
Before we can make sense of any result our condition number calculator produces, let's first define the matrix condition number and what it represents. We usually denote the condition number of a matrix as or . We can define it mathematically as follows:
In this equation, is any matrix norm. When we want to specify which norm we used, we can use the relevant subscript in the condition number symbol, such as for the matrix 2-norm . In addition, is the matrix inverse of .
The matrix is non-invertible if its matrix determinant is zero (i.e., ). In this case, it has an infinite condition number. To still gain some insight into the matrix's conditionality, some mathematicians would redefine the condition number with the pseudoinverse as . This alternate definition would still deliver huge, near-infinite condition numbers for non-invertible matrices, thereby still honoring our initial definition.
We can interpret the condition number in multiple ways. Firstly, measures the ratio of maximum stretching to maximum shrinking in a unit vector (i.e. ) when is multiplied with it. Therefore, an equivalent definition of the condition number is:
In pure mathematics, a matrix is either invertible or not. But, as the second way of interpreting the condition number, is a measure of how invertible is. As increases, gets closer to being non-invertible.
The third and most important use of condition numbers is in linear algebra. Let's take a look at why below!
The matrix condition number in linear algebra
When we have a system of linear equations , the condition number takes on a special meaning. now becomes the rate at which the solution will change in relation to a change in . For this reason, we can call the problem's error magnification factor. Changes in are usually due to errors made in formulating the problem, such as taking erroneous measurements or making rounding errors.
So, suppose some error crept in, and the values contained in are slightly wrong. How far from the truth our newly-found solution is, depends on :
If the condition number of matrix is large, is vulnerable to errors. The error in resulting from the error in will therefore be large.
Inversely, if is small, will be well-protected against reasonable errors in , and so its error will be small.
We can restate this relation mathematically. With representing the error in and the resulting change in , we can relate the relative errors and with:
This means that 's relative error can be up to as large as 's relative error scaled by the condition number.
How to find the condition number of a matrix?
With our mathematical definition of the condition number as , it is simple to find :
Choose a matrix norm. Although the choice is problem-dependent, the matrix 2-norm is typically used.
Evaluate the inverse of . We need the matrix inverse to find the matrix condition number. If does not exist, we can declare that .
Calculate and . It's crucial to use the same norm as chosen above throughout our calculations.
Multiply the norms to find .
How to use the condition number calculator?
It's great to know how to calculate the matrix condition number, but sometimes you just need an answer immediately to save time. This is where our matrix condition number calculator comes in handy. Here's how to use it:
Select your matrix's dimensionality. We support and matrices.
Enter your matrix, row by row. Feel free to refer to the symbolic representation at the top.
Select a matrix norm, or leave it at the default selection of the matrix 2-norm.
Find at the bottom of our matrix condition number calculator.
How to find the condition number of a matrix? – An example
To drive what we've learned home, let's take a look at an example. Suppose we have the linear system with:
We can easily solve for by calculating:
Now, let's see what happens when we add a small error of to the first element of to form .
Calculating in , we get:
There's a huge difference between and ! As you might have guessed by now, it's because has a large condition number. In fact, . You can verify this result in our matrix norm calculator!
It's fascinating to note that the relationship between our relative errors and our condition number is adhered to:
, and therefore our solution's relative error does not exceed the problem's relative error magnified by 's condition number.
What is the condition number of the identity matrix?
The condition number of an identity matrix of any size is 1. Because an identity matrix leaves any vector it's multiplied with untouched, it doesn't magnify an error in
b. Therefore, it makes intuitive sense for the identity matrix to have a condition number of 1.
1 is the smallest possible matrix condition number, so the identity matrix can be seen as optimally well-conditioned.
What is the condition number of a diagonal matrix?
The condition number of a diagonal matrix D is the ratio between the largest and smallest elements on its diagonal, i.e., cond(D) = max(Dii) / min(Dii). It's important to note that this is only true when using the matrix 2-norm for computing cond(D). This is largely because D's diagonal elements are its eigenvalues.
Can the condition number of a matrix be zero?
No. If cond(A) = 0, then cond(A)×‖δb⃗‖/‖b⃗‖ = 0 and therefore ‖δx⃗‖/‖x⃗‖ ≤ 0. Therefore, a condition number of 0 would mean that the matrix removes any error, which isn't possible.
In fact, the smallest possible condition number is 1, where an error is neither magnified nor diminished.
Does scaling a matrix affect its condition number?
No. Any scaling of the matrix will be canceled out by the matrix inverse being scaled inversely. This is because (𝛾A)−1 = 𝛾−1A−1. So,
= ‖𝛾A‖ · ‖(𝛾A)−1‖
= 𝛾‖A‖ · (𝛾)−1 · ‖A−1‖
= (𝛾·𝛾−1) · (‖A‖·‖A−1‖)
= 1 · (‖A‖·‖A−1‖)
Remember, the condition number measures the ratio of maximum stretch to minimum stretch. If both the maximum and minimum were to increase by 𝛾, the ratio wouldn't change, and therefore we have cond(𝛾A) = cond(A).