Skip to content

Matrix

  • new Matrix(r, c, arr: (number|Complex)[]) :
  • new Matrix(m : Matrix) :
  • new Matrix(arr : (number|Complex)[]) :
  • Matrix.zeros(r, c) : Creates an r × c matrix filled with zeros.
  • Matrix.ones(r, c) : Creates an r × c matrix filled with ones.
  • Matrix.eye(r, c) : Creates an r × c identity matrix (ones on the diagonal, zeros elsewhere).
    If r !== c, creates a rectangular diagonal matrix.
  • Matrix.nums(num : number|complex, r, c) : Creates an r × c matrix filled with the specified value num, which can be a real or complex number.
  • Matrix.random.int(min, max)
  • Matrix.random.float(min, max)
  • .at(r, c) : Returns the element at row r and column c
  • [Symbol.iterator] :
  • .reshape(r, c) : Reshapes the matrix to (r × c) without changing the total number of elements.
  • .reshape(r0, c0, r1, c1) :
  • .hstack(...matrices: Matrix[]) : Horizontally stacks matrices by columns (same number of rows required).
  • .vstack(...matrices: Matrix[]) : Vertically stacks matrices by rows (same number of columns required).
  • .hqueue(...matrices: Matrix[]) : Appends matrices horizontally, preserving row order (row-wise concatenation).
  • .vqueue(...matrices: Matrix[]) : Appends matrices vertically, preserving column order (column-wise concatenation).
  • .add(...m: (Matrix | number)[]) : Element-wise addition with one or more matrices or scalars.
  • .sub(...m: (Matrix | number)[]) : Element-wise subtraction with one or more matrices or scalars.
  • .mul(...m: (Matrix | number)[]) : Element-wise multiplication with one or more matrices or scalars.
  • .div(...m: (Matrix | number)[]) : Element-wise division with one or more matrices or scalars.
  • .modulo(...m: (Matrix | number)[]) : Element-wise modulo operation with one or more matrices or scalars.
  • .dot(m: Matrix) : Matrix multiplication (linear algebra dot product).
  • .toPrecision(n)
  • .toComplex(n) : Casts a real-valued matrix to a complex-valued matrix with 0 imaginary components
  • .map(Imin, Imax, Fmin, Fmax) : Linearly maps matrix values from the input range [Imin, Imax] to the output range [Fmin, Fmax].
  • .lerp(min, max) : Applies linear interpolation to scale matrix values into the range [min, max].
  • .norm(min, max) : Normalizes matrix values to the range [min, max].
  • .clamp(min, max) : Clamps matrix values so that all elements lie within the range [min, max].
  • .shuffle() : Randomly shuffles the elements of the matrix (element-wise), preserving its shape.
  • .shuffleRows() : Randomly shuffles the rows of the matrix, keeping the order of elements within each row intact.
  • .shuffleCols() : Randomly shuffles the columns of the matrix, keeping the order of elements within each column intact.
Getter Description Type
.size Returns the total number of elements in the matrix (rows × cols). number
.shape Returns the shape of the matrix as [rows, cols]. [number, number]
.det Returns the determinant of the matrix (only for square matrices). number | Matrix
.inv Returns the inverse of the matrix (only if invertible). Matrix
.T Returns the transpose of the matrix. Matrix
Checker Description
.isMatrix()
.haComplex()
.isSquare() Checks whether the matrix has the same number of rows and columns.
.isSym() Checks whether the matrix is symmetric (A = Aᵀ).
.isAntiSym() Checks whether the matrix is antisymmetric (A = -Aᵀ).
.isDiag() Checks whether the matrix is diagonal (non-zero elements only on the main diagonal).
.isOrtho() Checks whether the matrix is orthogonal (A · Aᵀ = I).
.isIdemp() Checks whether the matrix is idempotent (A² = A).
.isUpperTri() Checks whether the matrix is upper triangular (zeros below the main diagonal).
.isLowerTri() Checks whether the matrix is lower triangular (zeros above the main diagonal).