# Matrix vector multiply

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

Multiply an MxN finite-number matrix by a length-N finite-number vector, producing a length-M vector.

**Use when you need to: matrix-vector multiplication · apply a matrix to a vector · linear transformation.**

## Supported

- matrix-vector multiplication
- apply a matrix to a vector
- linear transformation

## Not supported

- vector-matrix multiplication on the left (transpose the matrix first)
- mismatched dimensions

## Behavior

- Input matrix is an MxN matrix of finite JSON numbers (M, N from 1 to 20). Input vector has exactly N finite JSON number entries.
- Each entry magnitude is bounded to at most 1000000.
- The result is the length-M vector result[r] = sum over c of matrix[r][c] * vector[c], accumulated left-to-right in IEEE-754 double precision.
- A result entry of -0 is normalized to 0.

## Input

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

## Output

- `result` (array of number, required)

## Limits

- max matrix dim: 20
- max vector dim: 64
- max abs value: 1000000

## Example

Request input:

```json
{
  "matrix": [
    [
      1,
      2
    ],
    [
      3,
      4
    ]
  ],
  "vector": [
    5,
    6
  ]
}
```

Response:

```json
{
  "result": {
    "result": [
      17,
      39
    ]
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "matrix-vector-multiply",
  "version": "1.0.0",
  "input": {
    "matrix": [
      [
        1,
        2
      ],
      [
        3,
        4
      ]
    ],
    "vector": [
      5,
      6
    ]
  }
}
```

### HTTP (no key)

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

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

### CLI

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

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

## Related tools

- [Vector scale](/tools/vector-scale): Multiply every entry of a finite-number vector by a scalar.
- [Matrix multiply](/tools/matrix-multiply): Multiply an MxK finite-number matrix by a KxN finite-number matrix, producing an MxN matrix.
- [Matrix scale](/tools/matrix-scale): Multiply every entry of a finite-number matrix by a scalar.
- [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 inverse](/tools/matrix-inverse): Compute the inverse of a small square finite-number matrix.
