Multiply matrices step by step with heatmap visualization and LaTeX export
Matrix multiplication is one of the most fundamental operations in linear algebra, with applications spanning computer graphics, machine learning, physics simulations, data science, cryptography, and engineering. Yet it is also one of the most commonly misunderstood operations — unlike regular number multiplication, matrix multiplication is not commutative (meaning A × B generally does not equal B × A) and can only be performed when the dimensions of the two matrices are compatible. Our Matrix Multiplication Calculator makes this powerful operation accessible to everyone, whether you are a student working through a linear algebra course, an engineer verifying numerical computations, or a developer debugging a transformation pipeline. This calculator allows you to define matrices of any size from 1×1 up to 10×10 and instantly compute their product. Each cell in your matrix accepts integers, decimal numbers, and even fractions in the form a/b (such as 1/3 or -2/5), so you can work with exact rational values without converting to decimals first. As you enter or modify values in any cell, the result updates automatically in real time — there is no need to press a Calculate button repeatedly. The auto-recalculation engine runs on every keystroke, keeping the result matrix and step-by-step breakdown continuously synchronized with your inputs. One of the most valuable learning features of this tool is the step-by-step solution panel. For every element C[i][j] in the result matrix, the calculator shows you the exact dot product computation: which row of matrix A and which column of matrix B were combined, the element-wise multiplication of each pair, and the final sum. This step-by-step breakdown follows the standard formula C[i][j] = Σ A[i][k] × B[k][j] for k = 1 to n, making the inner workings of matrix multiplication completely transparent. The steps panel is collapsed by default to keep the interface clean, but can be expanded with a single click whenever you want to trace the full computation. Beyond basic A × B multiplication, the calculator supports three additional operation modes. The Power mode raises a square matrix to any non-negative integer exponent, computing A^n using repeated squaring for efficiency. The Scalar mode multiplies every element of a matrix by a constant c, producing c × A. The Chain mode lets you multiply three matrices in sequence — A × B × C — automatically validating that each intermediate result dimension is compatible with the next matrix. Switching between modes via the tab buttons at the top instantly reconfigures the input panel to show only the controls relevant to that operation. For visual learners, the heatmap overlay on the result matrix provides an intuitive sense of the magnitude distribution across the output. Cells with large positive values receive a warm primary-color tint proportional to their absolute value relative to the maximum in the matrix, while large negative values receive a cool blue tint. Cells near zero remain uncolored. The heatmap can be toggled on or off at any time. A horizontal bar chart below the result shows the total magnitude (sum of absolute values) of each row, making it easy to identify which rows dominate the output. For students and academics who need to incorporate results into reports or homework, the calculator provides one-click copy in three formats: tab-separated plain text for pasting into spreadsheets, LaTeX bmatrix notation for including in TeX documents, and a formatted text grid for general use. The non-commutativity demonstration — available when multiplying two square matrices of the same size — computes both A × B and B × A side by side, making it visually obvious that changing the order of multiplication typically yields a different result. Five preset examples (2×2, 3×3, non-square, identity check, and non-commutative) are available as one-click chips so you can explore representative cases immediately without entering values manually.
Understanding Matrix Multiplication
What Is Matrix Multiplication?
Matrix multiplication is a binary operation that takes two matrices and produces a third matrix. Unlike element-wise multiplication (where each entry is simply multiplied by the corresponding entry), matrix multiplication combines entire rows of the first matrix with entire columns of the second matrix via dot products. Formally, given matrix A of size m×n and matrix B of size n×p, their product C = A × B is a matrix of size m×p where each element C[i][j] equals the dot product of row i of A and column j of B. This means the number of columns in A must equal the number of rows in B — if this condition is not met, multiplication is undefined. Matrix multiplication is associative (A × (B × C) = (A × B) × C) but generally not commutative (A × B ≠ B × A), which distinguishes it from ordinary scalar multiplication and is a source of frequent confusion for newcomers to linear algebra.
How Is Matrix Multiplication Calculated?
The standard algorithm for multiplying an m×n matrix A by an n×p matrix B involves three nested loops and runs in O(m × n × p) time. For each output position (i, j) in the result matrix C, you compute the sum: C[i][j] = A[i][1]×B[1][j] + A[i][2]×B[2][j] + ... + A[i][n]×B[n][j]. In practice, this means you take row i of matrix A (a vector of length n), take column j of matrix B (also a vector of length n), multiply the corresponding elements pair-by-pair, and sum all the products. For example, multiplying a 2×3 matrix by a 3×2 matrix produces a 2×2 result, and each of the four output cells requires three multiplications and two additions. This tool also supports matrix powers via repeated squaring: A^n = A × A^(n−1), with A^0 defined as the identity matrix.
Why Does Matrix Multiplication Matter?
Matrix multiplication is the backbone of an enormous range of computational tasks. In computer graphics and game engines, transformation matrices for rotation, scaling, translation, and projection are combined by multiplying them together, then applied to vertex coordinates to render 3D scenes. In machine learning and deep learning, forward passes through neural networks consist almost entirely of matrix multiplications between weight matrices and activation vectors. In physics and engineering, systems of linear equations are represented and solved using matrix algebra. In cryptography, certain encryption schemes use matrix operations over finite fields. In statistics and data science, principal component analysis, linear regression, and covariance matrix computations all depend on efficient matrix multiplication. Understanding how this operation works — and being able to verify it manually — is an essential skill in any quantitative field.
Limitations and Important Notes
This calculator uses standard floating-point arithmetic (IEEE 754 double precision), which means results for cells with many decimal places may exhibit small rounding errors — for instance, a true result of 1/3 may appear as 0.333333 rather than the exact fraction. For exact fractional outputs, consider using a computer algebra system. The step-by-step display is most useful for small matrices (up to 4×4); for larger matrices, the number of steps grows as m × p elements, so a 6×6 result would generate 36 step entries. The calculator supports matrices up to 10×10 for all operations. For matrix power mode, only non-negative integer exponents are supported; negative powers (A^−n) require computing the matrix inverse, which is not included in this tool. The chain multiplication mode (A × B × C) always computes left to right: (A × B) × C, which is mathematically equivalent to A × (B × C) due to associativity.
이 계산기 사용 방법
Choose an Operation Mode
Select a tab at the top: 'A × B Multiply' for standard matrix multiplication, 'A^n Power' to raise a square matrix to a power, 'c × A Scalar' to scale every element by a constant, or 'A × B × C Chain' to multiply three matrices in sequence.
Set Matrix Dimensions and Enter Values
Use the row and column dropdowns next to each matrix label to set the size (1 to 10 in each dimension). Then click each cell and type a value — integers, decimals, or fractions like 1/3 or -2/5 are all accepted. Use arrow keys to navigate between cells. Click 'Random' to fill a matrix with sample integers for quick testing, or choose a preset example from the chips at the bottom of the input panel.
Review the Result and Heatmap
The result matrix appears instantly on the right as soon as your inputs are valid. Toggle the heatmap to color cells by magnitude — warm tints for large positive values, cool tints for large negative values. The bar chart below shows the total magnitude of each row, helping you spot dominant components at a glance.
Explore Steps, Demo, and Export
Click 'Step-by-Step Solution' to expand the full dot product breakdown for every output cell. For square matrix multiplication, the non-commutativity demo shows A×B and B×A side by side. Use the copy buttons to export the result as tab-separated text, LaTeX bmatrix notation, or plain text for use in documents or spreadsheets.
자주 묻는 질문
Why can't I multiply my two matrices?
Matrix multiplication requires that the number of columns in the first matrix (A) equals the number of rows in the second matrix (B). If A is an m×n matrix and B is a p×q matrix, multiplication is only defined when n = p. For example, a 3×4 matrix can be multiplied by a 4×2 matrix (giving a 3×2 result), but not by a 3×4 matrix. When the dimensions are incompatible, the calculator shows a red error message explaining exactly which column and row counts do not match. Adjust the dimensions of one or both matrices until they are compatible.
Why is matrix multiplication not commutative?
Unlike regular number multiplication where a × b always equals b × a, matrix multiplication generally does not satisfy A × B = B × A. The reason is geometric: A × B applies transformation B first, then A, while B × A applies A first, then B. These two sequences of transformations typically produce different results. Even when both products are defined (which requires both matrices to be square and the same size), the results are almost always different. This is demonstrated visually by the non-commutativity demo in the results panel, which computes both A×B and B×A side by side whenever you multiply two square matrices of equal size.
What does the heatmap show?
The heatmap overlays color tints on the result matrix cells to visualize the relative magnitude of each value. Cells with large positive values receive a warm tint in the tool's primary color, with intensity proportional to the value's magnitude relative to the maximum absolute value in the matrix. Cells with large negative values receive a cool blue tint. Cells near zero remain uncolored. This visual layer makes it easy to identify at a glance which output cells are largest or smallest without reading every number. The heatmap can be toggled on and off with the button in the result panel header.
How does matrix power work, and what is A^0?
The matrix power operation computes A raised to a non-negative integer exponent n. A^1 = A (the matrix itself), A^2 = A × A, A^3 = A × A × A, and so on. A^0 is defined as the identity matrix — a square matrix with 1s along the main diagonal and 0s everywhere else — because multiplying any matrix by the identity leaves it unchanged (I × A = A), analogous to how any number raised to the power 0 equals 1. Matrix power requires the input matrix to be square (same number of rows and columns). The calculator uses repeated squaring for efficiency, so even large exponents compute quickly.
Can I enter fractions like 1/3 in the cells?
Yes. Each cell accepts integers (such as 5 or -3), decimal numbers (such as 2.5 or -0.75), and fractions in the form numerator/denominator (such as 1/3, -2/5, or 7/4). The calculator parses the fraction at calculation time and converts it to a decimal for the computation. Note that results are displayed in decimal form — a cell containing 1/3 contributes the value 0.33333... to the calculation. Use the decimal precision selector to control how many decimal places appear in the result. For exact fractional output, a symbolic CAS tool would be needed.
How do I copy the result for use in LaTeX or a spreadsheet?
The result panel includes three copy buttons. 'Copy as CSV' puts the values in tab-separated format, which can be pasted directly into Excel, Google Sheets, or any spreadsheet application — each column lands in its own cell. 'Copy as LaTeX' formats the matrix using the standard LaTeX bmatrix environment (\begin{bmatrix}...\end{bmatrix}), ready to paste into a TeX document or Overleaf editor. 'Copy as Text' produces a neatly spaced plain-text representation suitable for emails, notes, or any plain-text environment. All three formats respect the decimal precision setting you have selected.