Skip to main content
Back to BlogCalculator Guides

How to Use a Matrix Calculator (and Why Matrix Multiplication Isn't Element-Wise)

Matrix addition is element-wise, but matrix multiplication is a dot-product operation that requires the inner dimensions to match. Learn the dimension rule (cols of A must equal rows of B), how each cell of the product is computed, why AB is not BA, what the determinant measures (volume scaling, zero means singular), how Gauss-Jordan elimination produces the inverse, and what RREF and rank tell you about linear independence.

The Toolbox TeamAugust 13, 20268 min read

The problem: people multiply matrices the way they add them

Matrix addition is intuitive: add the corresponding elements. A 2x2 plus a 2x2 gives a 2x2 where each cell is the sum of the two matching cells. People assume multiplication works the same way — multiply corresponding elements. It does not. Matrix multiplication is a dot-product operation that combines rows of the first matrix with columns of the second. The dimension rule is different (the inner dimensions must match, not all dimensions), the computation is different (sum of products, not element-wise), and the result can have different dimensions than either input. On top of that, matrix multiplication is not commutative — A times B is generally not equal to B times A.

The tool handles addition, subtraction, multiplication, determinant, inverse, transpose, RREF, rank, trace, and matrix powers for matrices up to 6x6, with step-by-step solutions for determinants and inverses. Understanding which operations are element-wise and which are not is the difference between using the tool correctly and getting dimension errors.

Fastest path

Open the Matrix Calculator, set the dimensions of matrices A and B using the rows and columns inputs, fill in the cell values, and pick an operation from the tabs. The tool validates dimensions and shows an error if the operation is incompatible (e.g., multiplying a 2x3 by a 2x2). For determinant and inverse, enable the step-by-step toggle to see the cofactor expansion or Gauss-Jordan row operations.

Matrix addition and subtraction: element-wise, same dimensions

Addition and subtraction work exactly how you would expect: corresponding elements are added or subtracted. Both matrices must have the same dimensions — a 2x3 cannot be added to a 3x2. The tool checks this and shows an error if the dimensions do not match.

A = [1 2]    B = [5 6]    A + B = [6  8]
    [3 4]        [7 8]            [10 12]

Each cell in the result is the sum of the two cells in the same position. Subtraction works the same way, with minus signs.

Matrix multiplication: the dot-product rule

Matrix multiplication is where most people get lost. The rule is: the number of columns in the first matrix must equal the number of rows in the second. A 2x3 matrix can multiply a 3x4 matrix — the inner dimensions (3 and 3) match, and the result is 2x4 (the outer dimensions). A 2x3 matrix cannot multiply a 2x4 matrix — the inner dimensions (3 and 2) do not match.

The computation for each cell in the product is a dot product: take row i of the first matrix and column j of the second, multiply corresponding elements, and sum them.

A = [1 2 3]    B = [7  8]
    [4 5 6]        [9  10]
                   [11 12]

A is 2x3, B is 3x2 → result is 2x2

Result[0][0] = 1×7 + 2×9 + 3×11  = 58
Result[0][1] = 1×8 + 2×10 + 3×12 = 64
Result[1][0] = 4×7 + 5×9 + 6×11  = 139
Result[1][1] = 4×8 + 5×10 + 6×12 = 154

A × B = [58  64]
         [139 154]

The tool implements this with a triple loop: for each cell (i, j), sum the product of A[i][k] times B[k][j] across all k. The result dimensions are rows(A) x cols(B).

Non-commutativity: AB is not BA

Unlike scalar multiplication (3 times 5 = 5 times 3 = 15), matrix multiplication is not commutative. In the example above, A times B gives a 2x2 result. But B times A would give a 3x3 result — different dimensions entirely. Even when both products have the same dimensions (square matrices), the values are generally different.

The tool does not have a B times A button. To compute B times A, use the swap button (the arrow icon on Matrix B's header) to exchange A and B, then multiply. The swap preserves all cell values and dimensions.

The determinant: what it measures and how to compute it

The determinant is a single number computed from a square matrix. It measures how the matrix scales volume when used as a linear transformation. A determinant of 1 preserves volume. A determinant of 2 doubles it. A determinant of 0 collapses space — the matrix maps some vectors to zero, which means it is singular (not invertible).

The tool computes the determinant two ways. For step-by-step mode, it uses cofactor expansion: pick a row (row 0), and for each element in that row, multiply the element by its cofactor (alternating sign times the determinant of the minor matrix — the submatrix obtained by deleting that row and column). The 2x2 base case is ad minus bc.

det([a b]) = ad - bc
    [c d]

For 3x3 and larger, the tool recurses: each cofactor expansion reduces the matrix size by 1 until reaching the 2x2 base case. The step-by-step output shows each expansion level with the sign, element value, and sub-determinant.

For fast mode (no steps), the tool uses LU decomposition with partial pivoting: it converts the matrix to upper triangular form using row operations, tracking sign changes from row swaps. The determinant is the product of the diagonal entries of the upper triangular matrix, multiplied by -1 for each row swap. This is O(n^3) rather than the O(n!) of naive cofactor expansion, making it practical for 6x6 matrices.

The inverse: Gauss-Jordan elimination

The inverse of a square matrix A is a matrix A^-1 such that A times A^-1 = I (the identity matrix). Not every matrix has an inverse — only square matrices with non-zero determinant do. A matrix with determinant zero is singular, and its inverse does not exist.

The tool computes the inverse using Gauss-Jordan elimination on an augmented matrix [A | I]. It performs three types of row operations:

  1. Row swap: exchange two rows (needed when the pivot element is zero)
  2. Row scaling: divide a row by its pivot to make the pivot 1
  3. Row elimination: subtract a multiple of the pivot row from another row to zero out that column

After processing all columns, the left half becomes the identity and the right half is the inverse. The step-by-step output shows each operation: "R2 = R2 / 3", "R3 = R3 - 2 * R1", "Swap R1 <-> R3". If a zero pivot is found with no row to swap in, the matrix is singular and the tool reports that the inverse does not exist.

RREF and rank: linear independence

RREF (Reduced Row Echelon Form) is the simplest form of a matrix obtained through row operations. Each leading entry (pivot) is 1, all entries above and below pivots are 0, and each pivot is to the right of the pivot above it. The rank is the number of non-zero rows in the RREF — it tells you how many linearly independent rows (or columns) the matrix has.

For a system of linear equations represented as an augmented matrix, the RREF tells you whether the system has a unique solution (rank = number of variables), infinitely many solutions (rank < number of variables, consistent), or no solution (inconsistent). The tool shows the RREF and its rank together, so you can see both the form and the count.

Gotchas

  • Matrix multiplication is not commutative. A times B and B times A are different matrices in general. The tool computes A times B only — use the swap button to compute B times A.
  • The determinant requires a square matrix. A 2x3 matrix has no determinant. The tool shows an error if you try to compute the determinant of a non-square matrix. Same for inverse, trace, and matrix power.
  • A zero determinant means no inverse. The tool checks for this during Gauss-Jordan elimination and reports "singular matrix" if a zero pivot appears with no row to swap in. This is not a bug — it is the correct mathematical answer.
  • Cofactor expansion is slow for large matrices. The tool uses cofactor expansion for step-by-step mode (O(n!) time) and LU decomposition for fast mode (O(n^3)). For a 6x6 matrix, cofactor expansion performs 720 base-case evaluations. The tool handles it, but the step list is long.
  • Floating-point rounding affects near-singular matrices. The tool uses a tolerance of 1e-10 to detect zero pivots and clean up near-zero values. A matrix with a determinant of 1e-12 will be treated as singular. This is correct for practical purposes but can differ from symbolic computation tools (like WolframAlpha) that use exact arithmetic.

Summary

  • Matrix addition and subtraction are element-wise and require identical dimensions. Matrix multiplication is a dot-product operation that requires cols(A) = rows(B) and is not commutative.
  • The determinant measures volume scaling. Zero means singular (no inverse). The tool uses cofactor expansion for step-by-step display and LU decomposition for fast computation.
  • The inverse is computed via Gauss-Jordan elimination on [A | I], transforming A into I and I into A^-1. Singular matrices (det = 0) have no inverse.
  • RREF and rank reveal linear independence: rank equals the number of independent rows, which determines whether a linear system has unique, infinite, or no solutions.
  • Use the Matrix Calculator for all operations up to 6x6 with step-by-step solutions, the Standard Deviation Calculator for statistical dispersion, the Statistics Calculator for summary statistics, and the Percentage Calculator for ratio-based calculations.