# What is the matrix multiplication?

Multiplies an m × n matrix A by an n × p matrix B in exact decimal arithmetic: each entry of A × B is a row of A times a column of B, with the working.

- Page: https://www.acalculator.org/math/matrix-multiplication-calculator
- JSON spec: https://www.acalculator.org/math/matrix-multiplication-calculator.json
- Version: b3320fec28d7

## Default answer

Example with the default inputs (Matrix A [1, 2, 3; 4, 5, 6], Matrix B [7, 8; 9, 10; 11, 12]): A × B = [58, 64; 139, 154].

## Inputs

| Key | Label | Description |
| --- | --- | --- |
| a | Matrix A | The first matrix, 1 to 6 rows and columns. |
| b | Matrix B | The second matrix. It needs as many rows as A has columns. |

## Outputs

| Key | Label | Description |
| --- | --- | --- |
| product | A × B | The product matrix, exact, rows separated by semicolons. |
| size | Size of A × B | Rows × columns of the product: rows of A by columns of B. |
| steps | Working | Each entry as a row of A times a column of B, for the first 16 entries. |

## Method

The entry in row i, column j of A × B is row i of A times column j of B: cᵢⱼ = Σₖ aᵢₖbₖⱼ.

## Assumptions

- A has m rows and n columns, and B has n rows and p columns, so A × B has m rows and p columns (1 to 6 each). Otherwise there is no product.
- Every entry is read exactly as typed, so the product is exact: 0.1 × 0.2 is 0.02.
- The order matters: A × B and B × A are usually different.

## Worked examples

1. a = 1 or 2 or 4 or 5, b = 7 or 8 or 9 or 10 gives product = [58, 64; 139, 154], size = 2 × 2. Source: hand calculation in content.mdx: 1×7 + 2×9 + 3×11 = 58, …, 4×8 + 5×10 + 6×12 = 154.
2. a = 1 or 2 or 3 or 4, b = 5 or 6 or 7 or 8 gives product = [19, 22; 43, 50], steps = c11 = 1×5 + 2×7 = 19; c12 = 1×6 + 2×8 = 22; c21 = 3×5 + 4×7 = 43; c22 = 3×6 + 4×8 = 50. Source: hand calculation in content.mdx: the row-times-column rule, DLMF equation 1.2.34.
3. a = 5 or 6 or 7 or 8, b = 1 or 2 or 3 or 4 gives product = [23, 34; 31, 46]. Source: hand calculation in content.mdx: B × A differs from A × B (5×1 + 6×3 = 23).
4. a = 1 or 2 or undefined, b = 4 or undefined or 5 or undefined gives product = [32], size = 1 × 1. Source: hand calculation in content.mdx: a row times a column is the dot product, 1×4 + 2×5 + 3×6 = 32.
5. a = 0.1 or 0.2 or 0.3 or 0.4, b = 0.5 or 0 or 0 or 0.5 gives product = [0.05, 0.1; 0.15, 0.2]. Source: hand calculation in content.mdx: B is 0.5 × I, so A × B halves every entry of A; decimals are exact.

## FAQ

### How do I multiply two matrices?

Each entry of A × B is a row of A times a column of B: multiply the pairs of numbers and add. The entry in row 1, column 1 of [1, 2; 3, 4] × [5, 6; 7, 8] is 1 × 5 + 2 × 7 = 19. Repeat for every row of A and every column of B.

### When can two matrices be multiplied?

When A has as many columns as B has rows. A 2 × 3 matrix times a 3 × 2 matrix works and gives a 2 × 2 matrix. A 2 × 3 matrix times a 2 × 3 matrix does not, because a row of 3 numbers cannot pair with a column of 2.

### What size is the product?

Rows of A by columns of B. An m × n matrix times an n × p matrix is m × p. A 1 × 3 row times a 3 × 1 column is a single number (1 × 1); a 3 × 1 column times a 1 × 3 row is a 3 × 3 matrix.

### Is A × B the same as B × A?

Usually not. [1, 2; 3, 4] × [5, 6; 7, 8] = [19, 22; 43, 50], but [5, 6; 7, 8] × [1, 2; 3, 4] = [23, 34; 31, 46]. Often only one of the two products exists at all.

### What is the difference between matrix multiplication and the dot product?

Each entry of a matrix product is a dot product of a row and a column. Multiplying a 1 × n row by an n × 1 column gives just that one dot product: [1, 2, 3] × [4; 5; 6] = 32.

### Why is the answer exact?

Each number is read exactly as typed, so decimals like 0.1 do not pick up binary rounding error. Ordinary floating-point arithmetic gives 0.1 × 0.2 = 0.020000000000000004; this calculator gives 0.02.

## Sources

- NIST Digital Library of Mathematical Functions, §1.2(v) Matrices, Vectors, Scalar Products, and Norms, equation 1.2.34 (the row times column rule; an m × n matrix times an m′ × n′ matrix is defined only when n = m′; multiplication is not necessarily commutative). https://dlmf.nist.gov/1.2
