Skip to main content
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.

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

number[][]
required
The first input matrix, expressed as an array of row arrays. Default: [[5, 1, 6], [3, 4, 5], [6, 4, 8]].
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]].
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
string
default:"ans"
Name assigned to the computed result in the response.
string
default:"detailed"
Response verbosity: "lite", "standard", or "detailed".
boolean
default:"true"
Include background theory alongside solution steps.
string[]
default:"[\"\"]"
Format for step content: "html", "latex", or "speech".
integer | null
default:"null"
Decimal precision for rounding the result. Pass null for full precision.
boolean
default:"false"
Apply decimals rounding to intermediate step values.
boolean
default:"true"
Include normalized request parameters in the response.
boolean
default:"true"
Include curated learning resource links in the response.
Include links to related Stemfard endpoints in the response.
boolean
default:"true"
Include a description of the result object’s properties.

Example — matrix multiplication via the combined endpoint

200

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.
Adds two matrices element by element. a and b must have identical dimensions.POST /api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/add
number[][]
required
First input matrix.
number[][]
required
Second input matrix. Must have the same dimensions as a.
string
default:"ans"
Name for the result in the response.
string
default:"detailed"
Response verbosity: "lite", "standard", or "detailed".
integer | null
default:"null"
Decimal precision for the result.
Example
200
Subtracts b from a element by element. Both matrices must have identical dimensions.POST /api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/subtract
number[][]
required
First input matrix (minuend).
number[][]
required
Second input matrix (subtrahend). Must have the same dimensions as a.
string
default:"ans"
Name for the result in the response.
string
default:"detailed"
Response verbosity: "lite", "standard", or "detailed".
integer | null
default:"null"
Decimal precision for the result.
Example
200
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
number[][]
required
First input matrix.
number[][]
required
Second input matrix. Must have the same dimensions as a.
string
default:"ans"
Name for the result in the response.
string
default:"detailed"
Response verbosity: "lite", "standard", or "detailed".
integer | null
default:"null"
Decimal precision for the result.
Example
200
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
number[][]
required
Numerator matrix.
number[][]
required
Denominator matrix. Must have the same dimensions as a. No element may be zero.
string
default:"ans"
Name for the result in the response.
string
default:"detailed"
Response verbosity: "lite", "standard", or "detailed".
integer | null
default:"null"
Decimal precision for the result.
Example
200
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
number[][]
required
Base matrix.
number[][]
required
Exponent matrix. Must have the same dimensions as a.
string
default:"ans"
Name for the result in the response.
string
default:"detailed"
Response verbosity: "lite", "standard", or "detailed".
integer | null
default:"null"
Decimal precision for the result.
Example
200
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
number[][]
required
Left-hand matrix. An m × k matrix.
number[][]
required
Right-hand matrix. A k × n matrix. The number of rows must equal the number of columns in a.
string
default:"ans"
Name for the result in the response.
string
default:"detailed"
Response verbosity: "lite", "standard", or "detailed".
integer | null
default:"null"
Decimal precision for the result.
Example
200
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.