Skip to content
moxon home

Matrix

The /matrix endpoint performs mathematical operations on matrices. It supports arithmetic, scalar multiplication, transposition, and linear algebra operations on up to 20×20 matrices.

posthttps://api.moxon.dev/v5/matrix

How it works?

Determinant is computed via Gaussian elimination with partial pivoting. Matrix inverse uses Gauss-Jordan elimination on an augmented matrix. All inputs are validated: values must be finite numbers, rows must have uniform length, and the matrix must not exceed 20×20.

Try itpost/v5/matrix

Parameters

The request body must be JSON:

  • operationstringrequired

    The operation to perform (see available operations)

    • add
    • subtract
    • multiply
    • scalar
    • transpose
    • determinant
    • inverse
    • identity
  • matrixjsonrequired

    The input matrix (2D array of numbers)

  • matrix2jsonconditional

    Second matrix — required for add, subtract, multiply

  • scalarnumberconditional

    Scalar value — required for scalar, used by identity

Available Operations

OperationDescriptionRequires
addElement-wise additionmatrix2
subtractElement-wise subtractionmatrix2
multiplyMatrix multiplicationmatrix2
scalarMultiply all elements by a scalarscalar
transposeTranspose rows and columns—
determinantCompute the determinant (square matrices only)—
inverseCompute the inverse (square, non-singular matrices)—
identityGenerate an identity matrix of size scalar×scalarscalar

Response Fields

The response format depends on the operation:

Operationresult type
add, subtract, multiply, scalar, transpose, inverse, identitynumber[][]
determinantnumber

Code Examples

Error Handling

If parameters are missing or invalid, the API will return an error:

  • 400Please provide a valid operationThe operation parameter is missing or invalid. Valid values: add, subtract, multiply, scalar, transpose, determinant, inverse, identity
  • 400Matrix must be a non-empty 2D arrayThe matrix is missing or malformed
  • 400All rows must have the same lengthThe matrix rows are not uniform
  • 400Matrix values must be finite numbersThe matrix contains non-numeric values
  • 400Matrix exceeds maximum size of 20×20The matrix is larger than 20×20
  • 400Both matrices must have the same dimensionsDimension mismatch for add/subtract
  • 400Matrix dimensions incompatible for multiplicationColumn count of A ≠ row count of B
  • 400Matrix must be squareOperation requires a square matrix
  • 400Matrix is singular and cannot be invertedThe matrix has no inverse