# Matrix rank

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

Compute the numerical rank of a finite-number matrix (square or rectangular).

**Use when you need to: matrix rank · row rank · numerical rank.**

## Supported

- matrix rank
- row rank
- numerical rank

## Not supported

- exact symbolic rank over the rationals
- nullspace basis computation

## Behavior

- Input matrix is a rectangular MxN array of finite JSON numbers, M and N each from 1 to 20, magnitude bounded to at most 1000000.
- Computed via Gaussian elimination with partial (largest-magnitude) pivoting in IEEE-754 double precision, counting the number of pivot columns found.
- Optional input tolerance (default 1e-9, range 0 to 1) is the minimum pivot magnitude treated as nonzero; smaller candidate pivots are treated as zero for rank purposes.
- The result is an integer between 0 and min(M, N) inclusive.

## Input

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

## Output

- `result` (integer, required)

## Limits

- max rows: 20
- max cols: 20
- max abs value: 1000000

## Example

Request input:

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

Response:

```json
{
  "result": {
    "result": 1
  }
}
```

## How to call it

### MCP

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

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

### HTTP (no key)

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

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

### CLI

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

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

## Related tools

- [Vector outer product](/tools/vector-outer-product): Compute the outer product of two finite-number vectors, producing a matrix.
- [Matrix add](/tools/matrix-add): Add two equal-shape finite-number matrices elementwise.
- [Matrix determinant](/tools/matrix-determinant): Compute the determinant of a small square finite-number matrix.
- [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.
- [Matrix inverse](/tools/matrix-inverse): Compute the inverse of a small square finite-number matrix.
