# What is my matrix result?

Adds, subtracts, and multiplies matrices up to 6 × 6, and finds the transpose, determinant, inverse, power, rank, and trace, in exact fractions and decimals.

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

## Default answer

Example with the default inputs (Operation A × B, Matrix A [1, 2; 3, 4], Matrix B [5, 6; 7, 8]): The answer is [19, 22; 43, 50].

## Inputs

| Key | Label | Description |
| --- | --- | --- |
| op | Operation | What to work out from matrix A (and B). |
| a | Matrix A | The first matrix, 1 to 6 rows and columns. |
| b | Matrix B | The second matrix, for A + B, A − B, and A × B. |
| k | Scalar k | The number to multiply A by. |
| n | Power n | The whole number of times to multiply A by itself, from 0 to 20. |

## Outputs

| Key | Label | Description |
| --- | --- | --- |
| result | Result | The answer in exact fractions: a matrix with rows separated by semicolons, or a number. |
| decimal | Result in decimals | The same answer in decimals, each rounded half up to 10 significant figures. |
| size | Size of the result | Rows × columns of a matrix answer. |

## Method

Entry by entry for A ± B and k × A; (AB)ᵢⱼ = Σₖ Aᵢₖ Bₖⱼ; det(A) by elimination to triangular form; A⁻¹ by Gauss-Jordan on [A | I]; Aⁿ by repeated products; rank by row reduction; trace = sum of the diagonal.

## Assumptions

- Every cell is read as an exact fraction: the nearest fraction with a bottom up to 1,000,000 when it rounds to the same number (so 1/3 is 1/3), otherwise its decimal (0.1 is 1/10).
- Matrices are 1 × 1 to 6 × 6. A × B needs as many columns in A as rows in B; A + B and A − B need the same size.
- The determinant, inverse, power, and trace need a square A; A⁻¹ exists only when det(A) is not 0.

## Worked examples

1. op = mul, a = 1 or 2 or 3 or 4, b = 5 or 6 or 7 or 8 gives result = [19, 22; 43, 50], size = 2 × 2. Source: OpenStax, Precalculus 2e, §9.5, matrix multiplication (https://openstax.org/books/precalculus-2e/pages/9-5-matrices-and-matrix-operations).
2. op = mul, a = 1 or 2 or 4 or 5, b = 7 or 8 or 9 or 10 gives result = [58, 64; 139, 154], size = 2 × 2.
3. op = add, a = 1 or 2 or 3 or 4, b = 0.5 or -1 or 0.333333 or 0 gives result = [3/2, 1; 10/3, 4], decimal = [1.5, 1; 3.333333333, 4].
4. op = sub, a = 1 or 2 or 3 or 4, b = 5 or 6 or 7 or 8 gives result = [-4, -4; -4, -4], decimal = [-4, -4; -4, -4].
5. op = det, a = 2 or -3 or 2 or 0 gives result = 49, decimal = 49.
6. op = inverse, a = 4 or 7 or 2 or 6 gives result = [3/5, -7/10; -1/5, 2/5], decimal = [0.6, -0.7; -0.2, 0.4].
7. op = power, a = 1 or 1 or 1 or 0, n = 10 gives result = [89, 55; 55, 34].
8. op = rank, a = 1 or 2 or 2 or 4 gives result = 2.
9. op = trace, a = 1 or 2 or 3 or 4 gives result = 5.
10. op = transpose, a = 1 or 2 or 4 or 5 gives result = [1, 4; 2, 5; 3, 6], size = 3 × 2.
11. op = scalar, a = 1 or -2 or 0.1 or 3, k = 0.5 gives result = [1/2, -1; 1/20, 3/2].

## 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 and add. For A = [1, 2; 3, 4] and B = [5, 6; 7, 8], the top-left entry is 1 × 5 + 2 × 7 = 19, and A × B = [19, 22; 43, 50].

### When can two matrices be multiplied?

A × B needs as many columns in A as rows in B. A 2 × 3 matrix times a 3 × 2 matrix gives a 2 × 2 answer. A × B and B × A are usually different, and one of them may not exist at all.

### When can two matrices be added?

Only when they are the same size. Add (or subtract) the entries in the same place: [1, 2; 3, 4] + [5, 6; 7, 8] = [6, 8; 10, 12].

### Which matrices have an inverse?

Only square matrices whose determinant is not 0. For a 2 × 2 matrix [a, b; c, d], the inverse is 1/(ad − bc) × [d, −b; −c, a]. When ad − bc = 0, the matrix is singular and has no inverse.

### What are the rank and the trace?

The rank is the number of independent rows (or columns): [1, 2; 2, 4] has rank 1, because the second row is twice the first. The trace is the sum of the diagonal entries of a square matrix: 1 + 4 = 5 for [1, 2; 3, 4].

### Can I type fractions and decimals?

Yes. Type 1/3 or 0.25 in a cell. The calculator reads 1/3 as exactly one third and 0.1 as exactly one tenth, and works in exact fractions, so the answer has no rounding error. Decimals are shown next to the fractions.

### What does Aⁿ mean?

A multiplied by itself n times, for a square A. A⁰ is the identity matrix I. For example, [1, 1; 1, 0]¹⁰ = [89, 55; 55, 34], which holds Fibonacci numbers.

## Sources

- Gilbert Strang, Introduction to Linear Algebra, 5th edition (2016), §2.4 Rules for Matrix Operations, §2.5 Inverse Matrices, §5.1 The Properties of Determinants.
- OpenStax, Precalculus 2e, §9.5 Matrices and Matrix Operations and §9.7 Solving Systems with Inverses. https://openstax.org/books/precalculus-2e/pages/9-5-matrices-and-matrix-operations
