ForHosting KIT · Math

Matrix addition & subtraction

Add two matrices of the same size cell by cell: for two 2 × 2 matrices with entries 1, 2, 3, 4 and 5, 6, 7, 8, the result is 6, 8, 10, 12. Subtraction works the same way. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon

Runs in your browser. Free, unlimited — your data never leaves this page.

Matrix addition and subtraction are the first binary operations most linear-algebra courses teach after writing arrays of numbers. Given two matrices of equal size, you add or subtract corresponding entries to produce a third matrix of the same shape. That simple rule underpins vector spaces, image blending, residual checks in numerical methods, and spreadsheet-style batch corrections. This capability takes two rectangular numeric matrices and an optional operation (add or subtract), validates that both sides share the same row and column counts, and returns the entrywise result with dimensions and a copy of the parsed inputs.

What entrywise matrix addition and subtraction mean

Write two matrices A and B that both have m rows and n columns. The result is always another m-by-n matrix; no new rows or columns appear, and no entries are dropped. This is fundamentally different from matrix multiplication, which mixes rows of A with columns of B and requires the inner dimensions to match in a product sense, not a full shape equality.

Entrywise work is sometimes called the Hadamard sum when you think of it next to the Hadamard product, but everyday teaching simply says add corresponding elements. Geometry-wise, each matrix is a point in R to the power of m times n, and addition is ordinary vector addition in that ambient space after you flatten the arrays. Because every entry is independent of every other, the algorithm is embarrassingly parallel and embarrassingly simple: one floating-point add or subtract per cell.

The only hard rule is dimensional agreement. If A is three by two and B is two by three, there is no standard definition of A plus B in elementary linear algebra; you must reshape, pad, or refuse.

Practical use, pricing, limits, and delivery

Use the browser tool when you want an immediate entrywise sum or difference while checking homework, preparing a lecture slide, blending two small numeric grids, or debugging residual matrices without installing a computer-algebra system. There is no language model, no external linear-algebra service, and no randomness, so the capability is safe to pin in continuous-integration checks and reproducible lesson materials. Results are fully deterministic: the same matrices and operation always yield the same result grid.

Prefer add when combining displacements, layering corrections, or summing contributions; prefer subtract when computing residuals, differences between estimates, or A minus B form in homework statements. Keep entries within ordinary floating-range magnitudes so intermediate overflow is not a concern; for classroom integers and typical engineering scales the solver is exact within double precision. Source inputs and outputs follow the same retention rules as other KIT parse items, and a failed task is never charged after validation.

For matrix products, determinants, or inverses, use a different capability; this one stays intentionally focused on equal-shape entrywise add and subtract.

Homework and tutoring verification

Students and graders confirm entrywise sums and differences for equal-size matrices, including clear failures when dimensions do not match, without a local CAS install.

Residual and correction pipelines

Scripts that form estimate-minus-truth residual grids or apply additive corrections call a deterministic matrix-add oracle instead of reimplementing shape checks in every language.

Teaching equal-shape operations

Lesson pages can show add versus subtract on the same pair so learners connect the shared dimension rule to both binary operations before they meet matrix multiplication.

What happens if the matrix dimensions do not match?

The error message names both shapes (for example 2×3 versus 3×2).

Is the matrix addition calculator free?

The browser tool runs free on your device.

Does this multiply matrices?

No. This capacity only performs entrywise addition and subtraction on equal-size matrices. Matrix products need a different capability or library.

Can I subtract one matrix from another?

Yes. Choose subtraction and each entry of the second matrix is taken away from the matching entry of the first. As with addition, both matrices need the same number of rows and columns.

How is each entry of the sum worked out?

Each cell is the sum of the two cells in the same row and column. In the 2 × 2 example, the top-left entry is 1 plus 5, which gives 6, and the bottom-right is 4 plus 8, which gives 12.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/algebra/matrix-add

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/algebra/matrix-add \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"a":[[1,2],[3,4]],"b":[[5,6],[7,8]]}'
{
  "a": [
    [
      1,
      2
    ],
    [
      3,
      4
    ]
  ],
  "b": [
    [
      5,
      6
    ],
    [
      7,
      8
    ]
  ]
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "algebra.matrix_add",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Unequal shapes, jagged rows, empty matrices, and non-numeric cells fail with invalid_input instead of inventing padding or silent broadcasting.

What entrywise matrix addition and subtraction mean

Their sum S is defined by s_ij equals a_ij plus b_ij for every row index i from zero through m minus one and every column index j from zero through n minus one. Subtraction is the same rule with a minus sign: d_ij equals a_ij minus b_ij. This tool refuses, with an explicit invalid_input message that names both shapes, so homework checkers and API clients never silently accept a mismatched pair.

How to call the calculator and read the response

Each is a non-empty array of rows, and each row is a non-empty array of finite numbers. All rows of a given matrix must share the same length so the structure is rectangular. On success the response includes result (the m-by-n outcome), rows and cols for convenience, operation as actually applied, and echo fields a and b with the parsed numeric matrices. Near-zero float dust is cleaned so goldens and demos stay stable while ordinary non-integer reals keep full double precision. Send a JSON body with required fields a and b. You may pass matrices as native JSON arrays or as JSON strings of the same nested structure. The engine rejects missing fields, empty matrices, jagged rows, NaN or Infinity cells, and non-numeric strings with invalid_input, and those failures are not charged. When both matrices parse cleanly but their dimensions differ, the request also fails with a message that states the two shapes, for example three by two versus two by three. Wire the endpoint into scripts that already speak JSON and need a stable contract rather than reimplementing shape checks in every language.

Practical use, pricing, limits, and delivery

Each successful request is one billable item at $0.002; failed validation and dimension mismatches do not consume balance.

How do I add two matrices with this API?

Send JSON with a and b as arrays of equal-length numeric rows. Operation defaults to add. The response returns result, rows, cols, and the operation applied.

Can I subtract as well as add?

Yes. Set operation to subtract (or aliases sub, minus, -) to compute a − b entry by entry. Default is add.

Read the full KIT documentation →