rcond — Estimate reciprocal condition numbers in MATLAB and RunMat.
rc = rcond(A) estimates the reciprocal condition number of square matrix A. Interpretation and numerical behavior for singular/ill-conditioned matrices follow MATLAB semantics.
Syntax
c = rcond(A)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
A | Any | Yes | — | Input square matrix. |
Returns
| Name | Type | Description |
|---|---|---|
c | NumericScalar | Reciprocal condition number estimate. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:rcond:InvalidInput | Input shape/type is unsupported for reciprocal condition estimation. | rcond: invalid input |
RunMat:rcond:Internal | Runtime fails while computing rcond or executing fallback/upload paths. | rcond: internal runtime failure |
How rcond works
- Inputs must be square matrices (scalars count as
1 × 1). Non-square inputs trigger the MATLAB error"rcond: input must be a square matrix." - For the empty matrix (
0 × 0) the reciprocal condition number isInf. rcond(0)returns0. Non-zero scalars return1.- Logical and integer arrays are promoted to double precision before analysis.
- Complex matrices are supported; the singular values are computed in complex arithmetic.
- The implementation runs an SVD and computes
min(s) / max(s), honouring MATLAB's tolerance logic.
Does RunMat run rcond on the GPU?
When the input resides on a GPU, RunMat first invokes the active provider's rcond hook that this builtin registers. When that hook is unavailable the runtime attempts to reuse the provider's linsolve factorisations to recover the reciprocal condition number. If neither path is implemented the matrix is gathered to the host, the shared SVD-based estimator is executed, and the scalar result is uploaded back to the device so subsequent GPU work keeps residency.
GPU memory and residency
Manually calling gpuArray is rarely necessary. When matrices already live on the device, RunMat invokes the provider hook if one exists, or automatically gathers, evaluates, and re-uploads the scalar result. This preserves MATLAB compatibility while keeping the runtime efficient and ergonomic.
Examples
Reciprocal condition of the identity matrix
A = eye(3);
rc = rcond(A)Expected output:
rc = 1Detecting a nearly singular matrix
A = diag([1, 1e-8]);
rc = rcond(A)Expected output:
rc = 1e-8Reciprocal condition of a singular matrix
A = [1 2; 2 4];
rc = rcond(A)Expected output:
rc = 0Reciprocal condition for a complex matrix
A = [1+2i 0; 3i 2-1i];
rc = rcond(A)Expected output:
rc = 0.1887Handling the empty matrix
rc = rcond([])Expected output:
rc = InfEstimating conditioning on GPU data
G = gpuArray([2 0; 0 0.5]);
rc_gpu = rcond(G);
rc = gather(rc_gpu)Expected output:
rc = 0.25Using rcond with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how rcond changes the result.
Run a small rcond example, explain the result, then change one input and compare the output.
FAQ
What range of values should I expect from rcond?⌄
rcond returns a value in [0, 1]. Values near 1 indicate a well-conditioned matrix. Values near 0 indicate singular or ill-conditioned matrices.
Why does rcond return Inf for the empty matrix?⌄
The empty matrix is perfectly conditioned by convention, so the reciprocal condition number is Inf (1 / 0).
Does rcond warn me about singular systems automatically?⌄
rcond itself does not issue warnings. Use the value to decide whether the matrix is singular to working precision, similar to MATLAB workflows (if rcond(A) < eps, ...).
Is the SVD tolerance the same as MATLAB?⌄
Yes. The estimator matches MATLAB's definition by deriving the result from the singular values. The same tolerance logic is shared with pinv and rank.
Will calling rcond move my data off the GPU?⌄
Only if the active provider lacks a dedicated implementation. In that case RunMat transparently downloads the matrix, computes the estimate on the host, and re-uploads the scalar.
Related Linalg functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how rcond is executed, line by line, in Rust.
- View the source for rcond in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.