Home/Tools/matrix_inverse

Matrix inverse

Inverse of a square matrix; entries may be numbers or expressions.

Endpoint: POST /api/v1/matrix_inverse

When to use

Inverse of a square non-singular matrix.

Input schema

Validated server-side with Zod. The same schema feeds OpenAPI and the MCP tool list.

{
  "type": "object",
  "properties": {
    "matrix": {
      "type": "array",
      "items": {
        "type": "array",
        "items": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "number"
            }
          ]
        },
        "minItems": 1
      },
      "minItems": 1,
      "description": "Row-major matrix; entries may be numbers or expression strings"
    }
  },
  "required": [
    "matrix"
  ],
  "additionalProperties": false
}

Response shape

All tools return { ok: true, result } on success and { ok: false, error } on failure. The result object contains:

FieldTypeDescription
matrixstring[][]Inverse matrix, row-major.

Example

Request

{
  "matrix": [
    [
      1,
      2
    ],
    [
      3,
      4
    ]
  ]
}

Response

{
  "ok": true,
  "result": {
    "matrix": [
      [
        "-2",
        "1"
      ],
      [
        "3/2",
        "-1/2"
      ]
    ]
  }
}

curl

curl -X POST https://tools.aieo.se/api/v1/matrix_inverse \
  -H 'Content-Type: application/json' \
  -d '{"matrix":[[1,2],[3,4]]}'

MCP call (JSON-RPC)

MCP clients call this tool as tools/call against /api/mcp:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "matrix_inverse",
    "arguments": {
      "matrix": [
        [
          1,
          2
        ],
        [
          3,
          4
        ]
      ]
    }
  }
}

Common errors

  • Matrix is singular (det = 0).
    Nerdamer throws `Matrix is not invertible`.
    {
      "matrix": [
        [
          1,
          2
        ],
        [
          2,
          4
        ]
      ]
    }
  • A required field is missing or has the wrong type.
    Zod validation error, e.g. `Required` or `Expected string, received number`.
  • Nerdamer cannot parse the expression (unbalanced parens, unknown function, stray characters).
    `Unexpected token …` or `… is not a valid expression`.