det — Compute determinants of square matrices in MATLAB and RunMat.
det(A) returns the determinant of real or complex square matrix A. Scalar and empty-matrix cases (det([]) = 1) follow MATLAB and RunMat conventions.
Syntax
d = det(A)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
A | Any | Yes | — | Input matrix. |
Returns
| Name | Type | Description |
|---|---|---|
d | NumericScalar | Determinant of A. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:det:InvalidInput | Input shape/type or numeric domain is unsupported for determinant evaluation. | det: invalid input |
RunMat:det:Internal | Runtime fails while evaluating determinant or device fallback paths. | det: internal runtime failure |
RunMat:det:TooManyOutputs | More than one output is requested. | det: too many output arguments |
How det works
- Inputs must be 2-D square matrices. RunMat rejects non-square or higher-rank inputs with the MATLAB error
"det: input must be a square matrix." - Determinants are computed from an LU factorization with partial pivoting, ensuring numerical behavior that mirrors MATLAB. Singular matrices return
0(within floating-point round-off). - MATLAB documents single and double matrices. Integer and logical matrices are separately gated RunMat-only extensions; integer values must be exactly representable as double rather than silently rounded.
- Single input produces a single result. Complex input retains complex result storage and its single/double class.
- The determinant of the empty matrix (
[]) is1.
Does RunMat run det on the GPU?
RunMat resolves the provider from the input handle rather than a global provider. Floating matrices use its lu hook when possible; typed integer, logical, complex, and unsupported-provider cases gather explicitly. Re-uploaded results must match the input owner/device and the computed shape, storage, and precision or they are freed and rejected.
GPU memory and residency
You usually do NOT need to call gpuArray yourself in RunMat. Floating storage uses the owning provider's lu hook when available. Explicit fallback paths gather through that owner and restore real or complex scalar results to the same device while preserving single/double precision.
Examples
Determinant Of A 2x2 Matrix
A = [4 -2; 1 3];
d = det(A)Expected output:
d = 14Checking Zero Determinant For Singular Matrix
B = [1 2; 2 4];
d = det(B)Expected output:
d = 0Determinant Of A Complex Matrix
C = [1+2i 0; 3i 4-1i];
d = det(C)Expected output:
d = 6 + 7iDeterminant Equals Product Of Diagonal For Triangular Matrix
U = [3 2 1; 0 5 -1; 0 0 2];
d = det(U)Expected output:
d = 30Determinant Of An Empty Matrix
d = det([])Expected output:
d = 1Using det With gpuArray Data
G = gpuArray([2 0 0; 0 3 0; 1 0 4]);
d_gpu = det(G); % stays on the GPU when a provider is active
d = gather(d_gpu)Expected output:
d = 24Using det with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how det changes the result.
Run a small det example, explain the result, then change one input and compare the output.
FAQ
Why does det require square matrices?⌄
The determinant is only defined for square matrices. RunMat mirrors MATLAB by rejecting non-square inputs with "det: input must be a square matrix."
What is det([])?⌄
The determinant of the empty matrix ([]) is 1, matching MATLAB's convention for the product of an empty diagonal.
Does det warn for nearly singular matrices?⌄
No. RunMat returns the floating-point result of the LU-based determinant. Very small magnitudes indicate near singularity, just as in MATLAB.
How does det handle complex matrices?⌄
Complex matrices are factorized in complex arithmetic. The result is complex; if the imaginary part happens to be zero, it is still reported through the complex number interface.
Will the result stay on the GPU?⌄
Yes, when a GPU provider is active RunMat re-uploads the scalar determinant so that subsequent GPU code continues to operate on device-resident data. Providers without LU support fall back to the CPU path and return a host scalar.
Can det overflow or underflow?⌄
Large determinants can overflow or underflow double precision just as in MATLAB. RunMat does not rescale the matrix; if you require scaling, consider log(det(A)) via lu or chol.
Do logical inputs work?⌄
Logical matrices are a named RunMat-only extension. Strict MATLAB compatibility mode rejects them before data access.
Is the determinant computed exactly?⌄
No. The LU factorization works in floating-point, so the result is subject to round-off. The behavior matches MATLAB's det.
Related Linalg functions
Structure
bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how det is executed, line by line, in Rust.
- View the source for det 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.