# Matrix inverse

`matrix-inverse` · version 1.0.0 · Vectors & matrices · free, no key needed

Compute the inverse of a small square finite-number matrix.

**Use when you need to: matrix inverse · invert a square matrix.**

## Supported

- matrix inverse
- invert a square matrix

## Not supported

- non-square matrices
- matrices larger than 12x12
- pseudo-inverse of a singular or non-square matrix

## Behavior

- Input matrix is a square NxN array of finite JSON numbers, N from 1 to 12, magnitude bounded to at most 1000000.
- Computed via Gauss-Jordan elimination with partial (largest-magnitude) pivoting in IEEE-754 double precision.
- Optional input tolerance (default 1e-9, range 0 to 1) is the minimum acceptable pivot magnitude; if every remaining candidate pivot in a column is at or below tolerance, the matrix is rejected as singular or numerically singular.
- Results for small integer-valued invertible matrices are typically exact; floating-point rounding can appear for larger or ill-conditioned matrices.
- A result entry of -0 is normalized to 0.
- Every result entry is checked to be a finite number before it is returned; a very small nonzero pivot (below tolerance-rejection but large enough to be accepted) can otherwise amplify through elimination to overflow, which is rejected as invalid input rather than silently serialized as null.

## Input

- `matrix` (array of array of number, required): min items 1; max items 12
- `tolerance` (number, optional): min 0; max 1

## Output

- `result` (array of array of number, required)

## Limits

- max dim: 12
- max abs value: 1000000

## Example

Request input:

```json
{
  "matrix": [
    [
      2,
      0
    ],
    [
      0,
      4
    ]
  ]
}
```

Response:

```json
{
  "result": {
    "result": [
      [
        0.5,
        0
      ],
      [
        0,
        0.25
      ]
    ]
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "matrix-inverse",
  "version": "1.0.0",
  "input": {
    "matrix": [
      [
        2,
        0
      ],
      [
        0,
        4
      ]
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/matrix-inverse/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"matrix":[[2,0],[0,4]]}'
```

The machine-readable contract is at [/v1/tools/matrix-inverse/versions/1.0.0](/v1/tools/matrix-inverse/versions/1.0.0).

### CLI

```sh
node cli.mjs run matrix-inverse 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Matrix determinant](/tools/matrix-determinant): Compute the determinant of a small square finite-number matrix.
- [Matrix scale](/tools/matrix-scale): Multiply every entry of a finite-number matrix by a scalar.
- [Matrix vector multiply](/tools/matrix-vector-multiply): Multiply an MxN finite-number matrix by a length-N finite-number vector, producing a length-M vector.
- [Matrix add](/tools/matrix-add): Add two equal-shape finite-number matrices elementwise.
- [Matrix hadamard](/tools/matrix-hadamard): Multiply two equal-shape finite-number matrices elementwise (Hadamard product).
- [Matrix identity](/tools/matrix-identity): Construct the NxN identity matrix for a given size.
