Lesson 11 of 15

Condition Number

Condition Number

The condition number κ(A)\kappa(A) measures how sensitive a linear system Ax=bAx = b is to small perturbations:

κ(A)=λmaxλmin(for symmetric positive definite matrices)\kappa(A) = \frac{\lambda_{\max}}{\lambda_{\min}} \quad (\text{for symmetric positive definite matrices})

A large condition number means the system is ill-conditioned: tiny errors in bb can cause enormous errors in xx.

2×2 Eigenvalues via Trace and Determinant

For a 2×2 symmetric matrix, eigenvalues are:

λ=tr±tr24det2\lambda = \frac{\text{tr} \pm \sqrt{\text{tr}^2 - 4 \cdot \det}}{2}

where tr=A00+A11\text{tr} = A_{00} + A_{11} and det=A00A11A01A10\det = A_{00} A_{11} - A_{01} A_{10}.

Interpretation

κ(A)\kappa(A)Meaning
1\approx 1Well-conditioned; safe to solve
106\approx 10^6Lose about 6 digits of precision
1016\approx 10^{16}Essentially singular on 64-bit floats

Examples

A=(3113):  tr=6, det=8, λ=6±22=4,2      κ=2.0A = \begin{pmatrix}3&1\\1&3\end{pmatrix}: \; \text{tr}=6,\ \det=8,\ \lambda = \tfrac{6\pm2}{2} = 4, 2 \;\ \Rightarrow \;\ \kappa = 2.0

B=(2112):  tr=4, det=3, λ=3,1      κ=3.0B = \begin{pmatrix}2&1\\1&2\end{pmatrix}: \; \text{tr}=4,\ \det=3,\ \lambda = 3, 1 \;\ \Rightarrow \;\ \kappa = 3.0

C=I:  λ=1,1      κ=1.0C = I: \; \lambda = 1, 1 \;\ \Rightarrow \;\ \kappa = 1.0

Your Task

Implement condition_number_2x2(A) that computes κ=λmax/λmin\kappa = \lambda_{\max} / \lambda_{\min} for a 2×2 symmetric positive definite matrix using the trace-determinant formula.

Python runtime loading...
Loading...
Click "Run" to execute your code.