Skip to content
Ubiquev1.0.4
functionissingular
issingular(
x: unknown,
relativeTolerance?: number
): boolean

Checks if a matrix is singular (non-invertible).

Returns true if the input is a singular matrix. Uses row-equilibrated LU pivots, with default relative tolerance n * Number.EPSILON. This numerical test is invariant to row scaling; it is not a condition-number estimate.

Examples

Singular square matrix

import { assertEquals, assertThrows } from "jsr:@std/assert";

assertEquals(issingular([[2, 6], [1, 3]]), true);

Invertible matrix with a zero diagonal entry

import { assertEquals, assertThrows } from "jsr:@std/assert";

assertEquals(issingular([[0, 6], [1, 3]]), false);

Not a matrix (single number input)

import { assertEquals, assertThrows } from "jsr:@std/assert";

assertThrows(() => { issingular(5) }, Error, 'input must be a matrix');

Non-square matrix

import { assertEquals, assertThrows } from "jsr:@std/assert";

assertThrows(() => { issingular([[1, 2, 3], [4, 5, 6]]) }, Error, 'input must be a square matrix');

Parameters

x: unknown

The matrix to check.

optional
relativeTolerance: number

Return Type

boolean

Returns true if the matrix is singular, otherwise false.

Throws

Throws an error if the input is not a matrix or not a square matrix.