# Matrix solve linear

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

Solve the small square linear system A x = b for x using Gaussian elimination.

**Use when you need to: solve linear system · solve Ax=b · linear equation solver.**

## Supported

- solve linear system
- solve Ax=b
- linear equation solver

## Not supported

- non-square or rank-deficient (singular) systems
- systems larger than 12x12
- least-squares solutions for overdetermined systems

## Behavior

- Input a is a square NxN coefficient matrix of finite JSON numbers, N from 1 to 12. Input b is a length-N finite JSON number vector. Magnitudes are bounded to at most 1000000.
- Computed via Gaussian elimination with partial (largest-magnitude) pivoting and back substitution, 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 system is rejected as singular or numerically singular (no unique solution).
- The result is the unique solution vector x such that a * x approximately equals b; 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

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

## Output

- `result` (array of number, required)

## Limits

- max dim: 12
- max abs value: 1000000

## Example

Request input:

```json
{
  "a": [
    [
      2,
      1
    ],
    [
      1,
      3
    ]
  ],
  "b": [
    3,
    5
  ]
}
```

Response:

```json
{
  "result": {
    "result": [
      0.8,
      1.4
    ]
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "matrix-solve-linear",
  "version": "1.0.0",
  "input": {
    "a": [
      [
        2,
        1
      ],
      [
        1,
        3
      ]
    ],
    "b": [
      3,
      5
    ]
  }
}
```

### HTTP (no key)

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

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

### CLI

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

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

## Related tools

- [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 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.
