acalculator

What is my matrix result?

Type matrix A (and B), pick an operation, and the matrix calculator shows the answer as exact fractions and as decimals, up to 6 × 6.

Your numbers

Matrix A
Matrix B
Result
[19, 22; 43, 50]

The answer is [19, 22; 43, 50].

Result in decimals
[19, 22; 43, 50]
Size of the result
2 × 2

Result: [19, 22; 43, 50]. The answer is [19, 22; 43, 50].

How to calculate

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

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].

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.

  • 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.

Machine-readable copies: Markdown, JSON.

Worked examples

Each example is checked against the calculator on every build.

  1. Operation A × B, Matrix A 1, 2; 3, 4, Matrix B 5, 6; 7, 8 gives Result [19, 22; 43, 50], Size of the result 2 × 2.Source: OpenStax, Precalculus 2e, §9.5, matrix multiplication (https://openstax.org/books/precalculus-2e/pages/9-5-matrices-and-matrix-operations)
  2. Operation A × B, Matrix A 1, 2, 3; 4, 5, 6, Matrix B 7, 8; 9, 10; 11, 12 gives Result [58, 64; 139, 154], Size of the result 2 × 2.
  3. Operation A + B, Matrix A 1, 2; 3, 4, Matrix B 0.5, -1; 0.333333, 0 gives Result [3/2, 1; 10/3, 4], Result in decimals [1.5, 1; 3.333333333, 4].
  4. Operation A − B, Matrix A 1, 2; 3, 4, Matrix B 5, 6; 7, 8 gives Result [-4, -4; -4, -4], Result in decimals [-4, -4; -4, -4].
  5. Operation Determinant det(A), Matrix A 2, -3, 1; 2, 0, -1; 1, 4, 5 gives Result 49, Result in decimals 49.
  6. Operation Inverse A⁻¹, Matrix A 4, 7; 2, 6 gives Result [3/5, -7/10; -1/5, 2/5], Result in decimals [0.6, -0.7; -0.2, 0.4].
  7. Operation Power Aⁿ, Matrix A 1, 1; 1, 0, Power n 10 gives Result [89, 55; 55, 34].
  8. Operation Rank of A, Matrix A 1, 2, 3; 2, 4, 6; 1, 0, 1 gives Result 2.
  9. Operation Trace of A, Matrix A 1, 2; 3, 4 gives Result 5.
  10. Operation Transpose Aᵀ, Matrix A 1, 2, 3; 4, 5, 6 gives Result [1, 4; 2, 5; 3, 6], Size of the result 3 × 2.
  11. Operation k × A, Matrix A 1, -2; 0.1, 3, Scalar k 0.5 gives Result [1/2, -1; 1/20, 3/2].

How it works

Matrix A (and B for sums and products) can be 1 × 1 to 6 × 6. Pick one operation:

OperationRuleNeeds
A × B(AB)ᵢⱼ = Aᵢ₁B₁ⱼ + Aᵢ₂B₂ⱼ + … (row i of A times column j of B)columns of A = rows of B
A + B, A − Badd or subtract the entries in the same placethe same size
k × Amultiply every entry by the number kany A
Transpose Aᵀrow i of A becomes column iany A
Determinant det(A)Gaussian elimination to upper triangular form: det = (−1)^(number of row swaps) × the product of the diagonalsquare A
Inverse A⁻¹Gauss-Jordan elimination on [A | I]: when the left half becomes I, the right half is A⁻¹square A with det ≠ 0
Power AⁿA multiplied by itself n times (n from 0 to 20; A⁰ = I)square A
Rankthe number of pivots in the reduced row echelon formany A
Tracethe sum of the diagonal entriessquare A

Exact fractions

Each cell is read as an exact fraction, and all the arithmetic is exact:

  • A cell's number is taken as the fraction nearest to it with a bottom of at most 1,000,000, when that fraction rounds to the same 64-bit float; so a cell typed as 1/3 (which arrives as 0.333…) is exactly 1/3, and 0.1 is exactly 1/10. (This is Python's Fraction(x).limit_denominator(10**6), kept when float() of it equals x.)
  • Otherwise the cell is its shortest decimal, exactly: 0.1234567 is 1234567/10000000.
  • The scalar k is read the same way.

How the answer is written

  • Result: a matrix is written as [a, b; c, d]: entries separated by , , rows by ; . Each entry is a fraction in lowest terms with the minus sign in front, such as -7/10, or a whole number, such as 19. A determinant or trace is one such fraction; the rank is a whole number.
  • Result in decimals: the same entries, each rounded half up (away from zero) to 10 significant figures from its exact value, with trailing zeros dropped, and written like a JavaScript number: plain from 0.000001 up to below 10²¹, else e notation such as 1.5e-7 or 2.5e+21. There is no decimal line for the rank.
  • Size of the result: rows × columns of a matrix answer, such as 2 × 3.

Rules and messages

  • A × B when A's columns do not match B's rows: "To multiply, A needs as many columns as B has rows (A is 2 × 3, B is 2 × 2)."
  • A + B or A − B of different sizes: "A and B must be the same size to add them (A is …, B is …)." ("…to subtract them" for A − B).
  • Determinant, inverse, power, or trace of a matrix that is not square: "A must be square (the same number of rows and columns) to have a determinant." (or "…to have an inverse", "…to raise it to a power", "…to have a trace").
  • The inverse of a matrix with determinant 0: "The determinant of A is 0, so A has no inverse (it is singular)."

Worked examples by hand

A × B, 2 × 2. A = [1, 2; 3, 4], B = [5, 6; 7, 8]. Row 1 × column 1: 1 × 5 + 2 × 7 = 19; row 1 × column 2: 1 × 6 + 2 × 8 = 22; row 2: 3 × 5 + 4 × 7 = 43 and 3 × 6 + 4 × 8 = 50. So A × B = [19, 22; 43, 50].

A − B. [1, 2; 3, 4] − [5, 6; 7, 8] = [1 − 5, 2 − 6; 3 − 7, 4 − 8] = [-4, -4; -4, -4].

A × B, 2 × 3 times 3 × 2. [1, 2, 3; 4, 5, 6] × [7, 8; 9, 10; 11, 12]: 1 × 7 + 2 × 9 + 3 × 11 = 58, 1 × 8 + 2 × 10 + 3 × 12 = 64, 4 × 7 + 5 × 9 + 6 × 11 = 139, 4 × 8 + 5 × 10 + 6 × 12 = 154. So [58, 64; 139, 154], a 2 × 2 matrix.

A + B with fractions. [1, 2; 3, 4] + [0.5, −1; 1/3, 0] = [1 + 1/2, 2 − 1; 3 + 1/3, 4] = [3/2, 1; 10/3, 4], in decimals [1.5, 1; 3.333333333, 4].

Determinant, 3 × 3. For [2, −3, 1; 2, 0, −1; 1, 4, 5], expanding along the first row: 2 × (0 × 5 − (−1) × 4) − (−3) × (2 × 5 − (−1) × 1) + 1 × (2 × 4 − 0 × 1) = 2 × 4 + 3 × 11 + 8 = 49.

Inverse, 2 × 2. For [4, 7; 2, 6], det = 4 × 6 − 7 × 2 = 10, so A⁻¹ = 1/10 × [6, −7; −2, 4] = [3/5, -7/10; -1/5, 2/5] = [0.6, −0.7; −0.2, 0.4].

Power. [1, 1; 1, 0]¹⁰ = [89, 55; 55, 34]: the powers of this matrix hold the Fibonacci numbers, F(11) = 89, F(10) = 55, F(9) = 34.

Rank. In [1, 2, 3; 2, 4, 6; 1, 0, 1], row 2 is twice row 1, and row 3 is not a multiple of row 1, so the rank is 2.

Trace. [1, 2; 3, 4] has trace 1 + 4 = 5.

Transpose. [1, 2, 3; 4, 5, 6] becomes [1, 4; 2, 5; 3, 6], a 3 × 2 matrix.

k × A. ½ × [1, −2; 0.1, 3] = [1/2, -1; 1/20, 3/2].

Other questions people ask

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.