Matrix
Declarations
Section titled “Declarations”Matrix Constructor
Section titled “Matrix Constructor”new Matrix(r, c, arr: (number|Complex)[]):new Matrix(m : Matrix):new Matrix(arr : (number|Complex)[]):
matrix()matrix2(a0, a1, b0, b1): Creates a 2×2 matrixmatrix3(a0, a1, a2, b0, b1, b2, c0, c1, c2): Creates a 3×3 matrixmatrix4(a0, a1, a2, a3, b0, b1, b2, b3, c0, c1, c2, c3, d0, d1, d2, d3): Creates a 4×4 matrix
Static Factory Methods
Section titled “Static Factory Methods”Matrix.zeros(r, c): Creates anr × cmatrix filled with zeros.Matrix.ones(r, c): Creates anr × cmatrix filled with ones.Matrix.eye(r, c): Creates anr × cidentity matrix (ones on the diagonal, zeros elsewhere).
Ifr !== 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)
Indexing
Section titled “Indexing”.at(r, c): Returns the element at rowrand columnc[Symbol.iterator]:
Reshape
Section titled “Reshape”.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).
Arithmetic
Section titled “Arithmetic”.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).
Modifiers
Section titled “Modifiers”.toPrecision(n).toComplex(n): Casts a real-valued matrix to a complex-valued matrix with0imaginary 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.
Getters
Section titled “Getters”| 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 |
Checkers
Section titled “Checkers”| 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). |