cond
result = cond(A)
Input: A · Output: result
What it is
The 2-norm condition number of A (an r×c Mat or CMat) — the ratio of its largest to smallest singular value.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = cond(A) | A number, Mat, or CMatnot documented yet | result scalar, Num, or matrix | Returns a scalar Num, +inf for a singular matrix rather than an error (conditioning is routinely measured on matrices that turn out to be singular, and infinity *is* the answer there). Roughly how many digits a solve can lose, so 1e12 on a double means about four digits survive. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
A = [4.0, 1.0; 1.0, 3.0]
print("diag={diag(A)} trace={trace(A)} cond={cond(A)}")
b = [1.0, 2.0]
r = nnls(A, b)
print("nnls x={r.x} residual={r.residual}")
output
diag=[4, 3] trace=7 cond=1.938749 nnls x=[0.090909, 0.636364] residual=4.965068e-16
from core-math
A = [4, 1, 1, 3] as matrix(2, 2)
print("cond(A) = {round(cond(A), 3)}")
angles = linspace(0, 2 * pi, 200)
unit_x = cos(angles)
unit_y = sin(angles)
out_x = zeros(200)
out_y = zeros(200)
for i in 0 to 199
v = A * [unit_x[i], unit_y[i]]
out_x[i] = v[0]
out_y[i] = v[1]
end for
plot(unit_x, unit_y, color = "#94a3b8", label = "unit circle")
plot(out_x, out_y, color = "#4169e1", width = 2, label = "A applied to it")
legend()
title("what a 2x2 matrix does to a circle")
output
cond(A) = 1.939 · plot: figure 2 (200 points) · plot: figure 3 (200 points)
from core-math
How it works
cond(A) — the 2-norm condition number, the ratio of the largest singular value to the smallest. Infinite for a singular matrix rather than an error: conditioning is routinely *measured* on matrices that turn out to be singular, and that is the answer, not a failure.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.