> ## Documentation Index
> Fetch the complete documentation index at: https://docsa.stemfard.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Stemfard matrix arithmetic API endpoints reference

> Reference for the 7 Stemfard matrix arithmetic endpoints: add, subtract, element-wise multiply, divide, power, matmul, and the combined endpoint.

The matrix arithmetic endpoints let you perform basic arithmetic operations on matrices. There are seven endpoints in this group: a combined endpoint that accepts an `operation` parameter, and six individual endpoints — one per operation. All endpoints accept two input matrices `a` and `b` (or `a` and a scalar for element-wise operations) and the full set of [common request parameters](/api-reference/overview#common-request-parameters).

***

## Combined endpoint

Use this endpoint to run any arithmetic operation in a single request by setting the `operation` field.

**`POST /api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic`**

### Parameters

<ParamField body="a" type="number[][]" required>
  The first input matrix, expressed as an array of row arrays. Default: `[[5, 1, 6], [3, 4, 5], [6, 4, 8]]`.
</ParamField>

<ParamField body="b" type="number[][] | number" required>
  The second input matrix or scalar. For element-wise operations, `b` must have the same dimensions as `a`. For `matmul`, the number of columns in `a` must equal the number of rows in `b`. Default: `[[-4, -2, 6], [4, 7, -3], [7, -3, 5]]`.
</ParamField>

<ParamField body="operation" type="string" required>
  The arithmetic operation to perform. Accepted values:

  * `"all"` — run all operations and return all results
  * `"add"` — element-wise addition
  * `"subtract"` — element-wise subtraction
  * `"multiply-ew"` — element-wise (Hadamard) multiplication
  * `"divide-ew"` — element-wise division
  * `"raise-ew"` — element-wise power (each element of `a` raised to the corresponding element of `b`)
  * `"matmul"` — standard matrix multiplication
</ParamField>

<ParamField body="result_name" type="string" default="ans">
  Name assigned to the computed result in the response.
</ParamField>

<ParamField body="api_level" type="string" default="detailed">
  Response verbosity: `"lite"`, `"standard"`, or `"detailed"`.
</ParamField>

<ParamField body="steps_bg" type="boolean" default="true">
  Include background theory alongside solution steps.
</ParamField>

<ParamField body="steps_output_formats" type="string[]" default="[&#x22;&#x22;]">
  Format for step content: `"html"`, `"latex"`, or `"speech"`.
</ParamField>

<ParamField body="decimals" type="integer | null" default="null">
  Decimal precision for rounding the result. Pass `null` for full precision.
</ParamField>

<ParamField body="apply_decimals_in_steps" type="boolean" default="false">
  Apply `decimals` rounding to intermediate step values.
</ParamField>

<ParamField body="request_params" type="boolean" default="true">
  Include normalized request parameters in the response.
</ParamField>

<ParamField body="learning_pathways" type="boolean" default="true">
  Include curated learning resource links in the response.
</ParamField>

<ParamField body="related" type="boolean" default="true">
  Include links to related Stemfard endpoints in the response.
</ParamField>

<ParamField body="properties" type="boolean" default="true">
  Include a description of the result object's properties.
</ParamField>

### Example — matrix multiplication via the combined endpoint

<CodeGroup>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic \
    --header 'Authorization: Bearer <your-api-key>' \
    --header 'Content-Type: application/json' \
    --data '{
      "a": [[2, 7, 3], [4, -1, 6], [5, 8, 3]],
      "b": [[1, 0], [0, 1], [2, 3]],
      "operation": "matmul",
      "result_name": "product",
      "api_level": "standard"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer <your-api-key>',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        a: [[2, 7, 3], [4, -1, 6], [5, 8, 3]],
        b: [[1, 0], [0, 1], [2, 3]],
        operation: 'matmul',
        result_name: 'product',
        api_level: 'standard',
      }),
    }
  );
  const data = await response.json();
  ```

  ```python Python theme={null}
  import requests

  data = requests.post(
      'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic',
      headers={
          'Authorization': 'Bearer <your-api-key>',
          'Content-Type': 'application/json',
      },
      json={
          'a': [[2, 7, 3], [4, -1, 6], [5, 8, 3]],
          'b': [[1, 0], [0, 1], [2, 3]],
          'operation': 'matmul',
          'result_name': 'product',
          'api_level': 'standard',
      },
  ).json()
  ```
</CodeGroup>

```json 200 theme={null}
{
  "product": [[8, 16], [16, 17], [11, 17]],
  "operation": "matmul"
}
```

***

## Individual operation endpoints

Each operation has its own focused endpoint. These endpoints do not accept an `operation` field — the operation is determined by the path. All accept `a`, `b`, and the common parameters.

<AccordionGroup>
  <Accordion title="POST .../matrix-arithmetic/add — element-wise addition">
    Adds two matrices element by element. `a` and `b` must have identical dimensions.

    **`POST /api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/add`**

    <ParamField body="a" type="number[][]" required>
      First input matrix.
    </ParamField>

    <ParamField body="b" type="number[][]" required>
      Second input matrix. Must have the same dimensions as `a`.
    </ParamField>

    <ParamField body="result_name" type="string" default="ans">
      Name for the result in the response.
    </ParamField>

    <ParamField body="api_level" type="string" default="detailed">
      Response verbosity: `"lite"`, `"standard"`, or `"detailed"`.
    </ParamField>

    <ParamField body="decimals" type="integer | null" default="null">
      Decimal precision for the result.
    </ParamField>

    **Example**

    <CodeGroup>
      ```bash cURL theme={null}
      curl --request POST \
        --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/add \
        --header 'Authorization: Bearer <your-api-key>' \
        --header 'Content-Type: application/json' \
        --data '{
          "a": [[1, 2, 3], [4, 5, 6]],
          "b": [[7, 8, 9], [10, 11, 12]],
          "result_name": "sum",
          "api_level": "standard"
        }'
      ```

      ```python Python theme={null}
      import requests

      data = requests.post(
          'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/add',
          headers={'Authorization': 'Bearer <your-api-key>', 'Content-Type': 'application/json'},
          json={
              'a': [[1, 2, 3], [4, 5, 6]],
              'b': [[7, 8, 9], [10, 11, 12]],
              'result_name': 'sum',
              'api_level': 'standard',
          },
      ).json()
      ```
    </CodeGroup>

    ```json 200 theme={null}
    {
      "sum": [[8, 10, 12], [14, 16, 18]]
    }
    ```
  </Accordion>

  <Accordion title="POST .../matrix-arithmetic/subtract — element-wise subtraction">
    Subtracts `b` from `a` element by element. Both matrices must have identical dimensions.

    **`POST /api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/subtract`**

    <ParamField body="a" type="number[][]" required>
      First input matrix (minuend).
    </ParamField>

    <ParamField body="b" type="number[][]" required>
      Second input matrix (subtrahend). Must have the same dimensions as `a`.
    </ParamField>

    <ParamField body="result_name" type="string" default="ans">
      Name for the result in the response.
    </ParamField>

    <ParamField body="api_level" type="string" default="detailed">
      Response verbosity: `"lite"`, `"standard"`, or `"detailed"`.
    </ParamField>

    <ParamField body="decimals" type="integer | null" default="null">
      Decimal precision for the result.
    </ParamField>

    **Example**

    <CodeGroup>
      ```bash cURL theme={null}
      curl --request POST \
        --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/subtract \
        --header 'Authorization: Bearer <your-api-key>' \
        --header 'Content-Type: application/json' \
        --data '{
          "a": [[10, 20], [30, 40]],
          "b": [[1, 5], [10, 15]],
          "result_name": "difference",
          "api_level": "lite"
        }'
      ```

      ```python Python theme={null}
      import requests

      data = requests.post(
          'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/subtract',
          headers={'Authorization': 'Bearer <your-api-key>', 'Content-Type': 'application/json'},
          json={
              'a': [[10, 20], [30, 40]],
              'b': [[1, 5], [10, 15]],
              'result_name': 'difference',
              'api_level': 'lite',
          },
      ).json()
      ```
    </CodeGroup>

    ```json 200 theme={null}
    {
      "difference": [[9, 15], [20, 25]]
    }
    ```
  </Accordion>

  <Accordion title="POST .../matrix-arithmetic/multiply-ew — element-wise multiplication">
    Computes the Hadamard (element-wise) product of `a` and `b`. Each element at position `(i, j)` in the result equals `a[i][j] × b[i][j]`. Both matrices must have identical dimensions.

    **`POST /api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/multiply-ew`**

    <ParamField body="a" type="number[][]" required>
      First input matrix.
    </ParamField>

    <ParamField body="b" type="number[][]" required>
      Second input matrix. Must have the same dimensions as `a`.
    </ParamField>

    <ParamField body="result_name" type="string" default="ans">
      Name for the result in the response.
    </ParamField>

    <ParamField body="api_level" type="string" default="detailed">
      Response verbosity: `"lite"`, `"standard"`, or `"detailed"`.
    </ParamField>

    <ParamField body="decimals" type="integer | null" default="null">
      Decimal precision for the result.
    </ParamField>

    **Example**

    <CodeGroup>
      ```bash cURL theme={null}
      curl --request POST \
        --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/multiply-ew \
        --header 'Authorization: Bearer <your-api-key>' \
        --header 'Content-Type: application/json' \
        --data '{
          "a": [[1, 2], [3, 4]],
          "b": [[5, 6], [7, 8]],
          "result_name": "hadamard",
          "api_level": "lite"
        }'
      ```

      ```python Python theme={null}
      import requests

      data = requests.post(
          'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/multiply-ew',
          headers={'Authorization': 'Bearer <your-api-key>', 'Content-Type': 'application/json'},
          json={
              'a': [[1, 2], [3, 4]],
              'b': [[5, 6], [7, 8]],
              'result_name': 'hadamard',
              'api_level': 'lite',
          },
      ).json()
      ```
    </CodeGroup>

    ```json 200 theme={null}
    {
      "hadamard": [[5, 12], [21, 32]]
    }
    ```
  </Accordion>

  <Accordion title="POST .../matrix-arithmetic/divide-ew — element-wise division">
    Divides each element of `a` by the corresponding element of `b`. Both matrices must have identical dimensions. Division by zero in `b` will produce an error.

    **`POST /api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/divide-ew`**

    <ParamField body="a" type="number[][]" required>
      Numerator matrix.
    </ParamField>

    <ParamField body="b" type="number[][]" required>
      Denominator matrix. Must have the same dimensions as `a`. No element may be zero.
    </ParamField>

    <ParamField body="result_name" type="string" default="ans">
      Name for the result in the response.
    </ParamField>

    <ParamField body="api_level" type="string" default="detailed">
      Response verbosity: `"lite"`, `"standard"`, or `"detailed"`.
    </ParamField>

    <ParamField body="decimals" type="integer | null" default="null">
      Decimal precision for the result.
    </ParamField>

    **Example**

    <CodeGroup>
      ```bash cURL theme={null}
      curl --request POST \
        --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/divide-ew \
        --header 'Authorization: Bearer <your-api-key>' \
        --header 'Content-Type: application/json' \
        --data '{
          "a": [[10, 20], [30, 40]],
          "b": [[2, 4], [5, 8]],
          "result_name": "quotient",
          "api_level": "lite",
          "decimals": 2
        }'
      ```

      ```python Python theme={null}
      import requests

      data = requests.post(
          'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/divide-ew',
          headers={'Authorization': 'Bearer <your-api-key>', 'Content-Type': 'application/json'},
          json={
              'a': [[10, 20], [30, 40]],
              'b': [[2, 4], [5, 8]],
              'result_name': 'quotient',
              'api_level': 'lite',
              'decimals': 2,
          },
      ).json()
      ```
    </CodeGroup>

    ```json 200 theme={null}
    {
      "quotient": [[5.0, 5.0], [6.0, 5.0]]
    }
    ```
  </Accordion>

  <Accordion title="POST .../matrix-arithmetic/raise-ew — element-wise power">
    Raises each element of `a` to the power of the corresponding element of `b`. The result at position `(i, j)` equals `a[i][j] ^ b[i][j]`. Both matrices must have identical dimensions.

    **`POST /api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/raise-ew`**

    <ParamField body="a" type="number[][]" required>
      Base matrix.
    </ParamField>

    <ParamField body="b" type="number[][]" required>
      Exponent matrix. Must have the same dimensions as `a`.
    </ParamField>

    <ParamField body="result_name" type="string" default="ans">
      Name for the result in the response.
    </ParamField>

    <ParamField body="api_level" type="string" default="detailed">
      Response verbosity: `"lite"`, `"standard"`, or `"detailed"`.
    </ParamField>

    <ParamField body="decimals" type="integer | null" default="null">
      Decimal precision for the result.
    </ParamField>

    **Example**

    <CodeGroup>
      ```bash cURL theme={null}
      curl --request POST \
        --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/raise-ew \
        --header 'Authorization: Bearer <your-api-key>' \
        --header 'Content-Type: application/json' \
        --data '{
          "a": [[2, 3], [4, 5]],
          "b": [[3, 2], [2, 3]],
          "result_name": "power",
          "api_level": "lite"
        }'
      ```

      ```python Python theme={null}
      import requests

      data = requests.post(
          'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/raise-ew',
          headers={'Authorization': 'Bearer <your-api-key>', 'Content-Type': 'application/json'},
          json={
              'a': [[2, 3], [4, 5]],
              'b': [[3, 2], [2, 3]],
              'result_name': 'power',
              'api_level': 'lite',
          },
      ).json()
      ```
    </CodeGroup>

    ```json 200 theme={null}
    {
      "power": [[8, 9], [16, 125]]
    }
    ```
  </Accordion>

  <Accordion title="POST .../matrix-arithmetic/matmul — matrix multiplication">
    Performs standard matrix multiplication (dot product). The number of columns in `a` must equal the number of rows in `b`. If `a` is `m × k` and `b` is `k × n`, the result is `m × n`.

    **`POST /api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/matmul`**

    <ParamField body="a" type="number[][]" required>
      Left-hand matrix. An `m × k` matrix.
    </ParamField>

    <ParamField body="b" type="number[][]" required>
      Right-hand matrix. A `k × n` matrix. The number of rows must equal the number of columns in `a`.
    </ParamField>

    <ParamField body="result_name" type="string" default="ans">
      Name for the result in the response.
    </ParamField>

    <ParamField body="api_level" type="string" default="detailed">
      Response verbosity: `"lite"`, `"standard"`, or `"detailed"`.
    </ParamField>

    <ParamField body="decimals" type="integer | null" default="null">
      Decimal precision for the result.
    </ParamField>

    **Example**

    <CodeGroup>
      ```bash cURL theme={null}
      curl --request POST \
        --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/matmul \
        --header 'Authorization: Bearer <your-api-key>' \
        --header 'Content-Type: application/json' \
        --data '{
          "a": [[2, 7, 3], [4, -1, 6], [5, 8, 3]],
          "b": [[1, 0], [0, 1], [2, 3]],
          "result_name": "product",
          "api_level": "standard"
        }'
      ```

      ```javascript JavaScript theme={null}
      const response = await fetch(
        'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/matmul',
        {
          method: 'POST',
          headers: {
            'Authorization': 'Bearer <your-api-key>',
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
            a: [[2, 7, 3], [4, -1, 6], [5, 8, 3]],
            b: [[1, 0], [0, 1], [2, 3]],
            result_name: 'product',
            api_level: 'standard',
          }),
        }
      );
      const data = await response.json();
      ```

      ```python Python theme={null}
      import requests

      data = requests.post(
          'https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/matmul',
          headers={'Authorization': 'Bearer <your-api-key>', 'Content-Type': 'application/json'},
          json={
              'a': [[2, 7, 3], [4, -1, 6], [5, 8, 3]],
              'b': [[1, 0], [0, 1], [2, 3]],
              'result_name': 'product',
              'api_level': 'standard',
          },
      ).json()
      ```
    </CodeGroup>

    ```json 200 theme={null}
    {
      "product": [[8, 16], [16, 17], [11, 17]]
    }
    ```

    <Note>
      Matrix multiplication is not commutative — `a × b` is not equal to `b × a` in general. Make sure you pass the matrices in the correct order for your use case.
    </Note>
  </Accordion>
</AccordionGroup>
