Matrix Multiplication Calculator

Multiply matrices with numbers or variables, with step-by-step solutions.

Numeric Mode Variable Mode
?
In Variable Mode, you can use algebraic expressions like 'x', 'y+2', '2a-b', etc. Variables are case-sensitive.
🅰️ Matrix A
Rows: Columns:
Columns of A must equal Rows of B for matrices to be compatible
🅱️ Matrix B
Rows: Columns:
🎯 Result: Matrix Product

📝 Step-by-Step Solution

Enter matrix dimensions and values, then click "Calculate" to see the step-by-step solution.

📋 Step-By-Step Instructions

1

Set Matrix Dimensions

Enter the number of rows and columns for each matrix. For matrices to be compatible for multiplication:

Number of columns in Matrix A must equal Number of rows in Matrix B
Example: A (2×3) × B (3×2) = Result (2×2)
2

Enter Matrix Values

Fill in each cell of your matrices with numbers (or variables if in Variable Mode).

  • Click the Random Values button to automatically fill with random numbers
  • Use the Load Example button to see pre-filled examples
  • You can use fractions like "1/2" in Numeric Mode
3

Calculate the Product

Click the Calculate Matrix Product button to perform the multiplication.

The calculator will multiply the matrices by taking the dot product of rows from Matrix A with columns from Matrix B:

Result[i,j] = (Row i from A) · (Column j from B)

= A[i,1]×B[1,j] + A[i,2]×B[2,j] + ... + A[i,n]×B[n,j]

4

Understand the Results

Review the result matrix and the detailed step-by-step solution below it.

  • Each element of the result shows how it was calculated
  • Follow the calculations to understand the matrix multiplication process
  • You can adjust your inputs and recalculate to see how changes affect the result

📚 Understanding Matrix Multiplication

What Is Matrix Multiplication?

Matrix multiplication is a binary operation that takes a pair of matrices and produces another matrix. Unlike simple arithmetic multiplication, matrix multiplication follows specific rules and has requirements on the dimensions of the matrices.

💡 Matrix multiplication is fundamental to linear algebra and has numerous applications in science, engineering, computer graphics, and data analysis.

Compatibility Rule

⚠️ Two matrices can be multiplied only when the number of columns in the first matrix equals the number of rows in the second matrix.

Compatibility Example

Matrix A (3×2)
a11 a12
a21 a22
a31 a32
×
Matrix B (2×4)
b11 b12 b13 b14
b21 b22 b23 b24
=
Result (3×4)
c11 c12 c13 c14
c21 c22 c23 c24
c31 c32 c33 c34

Columns of A (2) = Rows of B (2) ✓ Compatible

The Multiplication Process

To calculate the element at position (i, j) in the resulting matrix:

  1. Take the ith row of the first matrix
  2. Take the jth column of the second matrix
  3. Multiply corresponding elements and sum them up

🔢 Mathematically, if C = A×B, then:

C[i,j] = A[i,1]×B[1,j] + A[i,2]×B[2,j] + ... + A[i,n]×B[n,j]

Step-by-Step Example

Let's multiply these two matrices:

Matrix A (2×3)
1 2 3
4 5 6
×
Matrix B (3×2)
7 8
9 10
11 12
Element C[1,1]
Element C[1,2]
Element C[2,1]
Element C[2,2]

Calculating C[1,1]:

Take row 1 from A: [1, 2, 3]

Take column 1 from B: [7, 9, 11]

Multiply corresponding elements and sum:

C[1,1] = 1×7 + 2×9 + 3×11

C[1,1] = 7 + 18 + 33 = 58

Calculating C[1,2]:

Take row 1 from A: [1, 2, 3]

Take column 2 from B: [8, 10, 12]

Multiply corresponding elements and sum:

C[1,2] = 1×8 + 2×10 + 3×12

C[1,2] = 8 + 20 + 36 = 64

Calculating C[2,1]:

Take row 2 from A: [4, 5, 6]

Take column 1 from B: [7, 9, 11]

Multiply corresponding elements and sum:

C[2,1] = 4×7 + 5×9 + 6×11

C[2,1] = 28 + 45 + 66 = 139

Calculating C[2,2]:

Take row 2 from A: [4, 5, 6]

Take column 2 from B: [8, 10, 12]

Multiply corresponding elements and sum:

C[2,2] = 4×8 + 5×10 + 6×12

C[2,2] = 32 + 50 + 72 = 154

Final result:

58 64
139 154
Special Cases and Properties
🔄 Identity Matrix

The identity matrix (I) has 1s on the main diagonal and 0s elsewhere. When a matrix is multiplied by the identity matrix of appropriate size, the original matrix is unchanged.

Identity Property

A × I = I × A = A

This means the identity matrix works like the number 1 in regular multiplication

Example: 3×3 Identity Matrix

The identity matrix I3 for 3×3 matrices looks like this:

1 0 0
0 1 0
0 0 1
1s on the main diagonal, 0s elsewhere

When we multiply any 3×3 matrix by I3:

5 2 8
1 3 7
4 6 9
×
1 0 0
0 1 0
0 0 1
=
5 2 8
1 3 7
4 6 9

💡 Key Insight: The identity matrix is crucial in matrix algebra. It's used in finding matrix inverses and solving systems of linear equations.

Identity matrices exist for any square dimension (2×2, 3×3, 4×4, etc.).

⚠️ Order Matters

Unlike regular multiplication with numbers, matrix multiplication is not commutative. This is one of the most important properties to understand.

Non-Commutativity Property

A × B ≠ B × A

The order of multiplication matters! This is different from regular number multiplication where a×b = b×a.

Non-Commutativity Example

A × B
A
1 2
3 4
×
B
5 6
7 8
=
19 22
43 50

Steps:

  • 1×5 + 2×7 = 5 + 14 = 19
  • 1×6 + 2×8 = 6 + 16 = 22
  • 3×5 + 4×7 = 15 + 28 = 43
  • 3×6 + 4×8 = 18 + 32 = 50
B × A
B
5 6
7 8
×
A
1 2
3 4
=
23 34
31 46

Steps:

  • 5×1 + 6×3 = 5 + 18 = 23
  • 5×2 + 6×4 = 10 + 24 = 34
  • 7×1 + 8×3 = 7 + 24 = 31
  • 7×2 + 8×4 = 14 + 32 = 46

⚠️ Important: The results are completely different! A×B and B×A produce different matrices.

This non-commutativity has important implications in many applications, especially in physics and computer graphics where the order of transformations matters.

🔄 Other Important Properties
Associativity
(A × B) × C = A × (B × C)

The grouping of matrices doesn't matter when multiplying 3 or more matrices.

This lets you multiply multiple matrices in any order of operations.

Distributivity
A × (B + C) = A × B + A × C

Matrix multiplication distributes over addition.

This works like the distributive property of regular multiplication.

Scalar Multiplication

When multiplying a matrix by a scalar (number), multiply each element by that number.

3 ×
2 4
1 3
=
6 12
3 9
Transpose Property
(A × B)ᵀ = Bᵀ × Aᵀ

The transpose of a product equals the product of the transposes in reversed order.

Note: The transpose flips a matrix over its diagonal, turning rows into columns.

Original

a b
c d

Transpose

a c
b d

💡 Why These Properties Matter: These properties are the foundation of linear algebra and allow for solving complex systems of equations, proving mathematical theorems, and implementing efficient algorithms for computer graphics, machine learning, and quantum physics.

Applications of Matrix Multiplication

Matrix multiplication is a fundamental operation with powerful applications across numerous fields of science, technology, and business:

Technology
Science
Business
🖥️
Computer Graphics

3D transformations (rotation, scaling, translation) are represented as matrix operations. Games and animation rely heavily on matrix multiplication.

Example: When a 3D character moves in a game, its position is updated by multiplying its coordinates by transformation matrices.
🧠
Machine Learning

Neural networks use matrix multiplication for both forward and backward propagation. Weight matrices transform input data through layers.

Example: A single layer in a neural network computes: output = activation_function(weights × inputs + bias)
🔒
Cryptography

Matrix operations are used in encryption algorithms like Hill cipher. Secret keys are often represented as matrices.

Example: In Hill cipher, plaintext is converted to number matrices and multiplied by a key matrix to produce ciphertext.
📱
Image Processing

Convolution operations in image filters (blurring, edge detection) are implemented as matrix multiplications.

Example: The Sobel edge detection filter multiplies pixel neighborhoods by specific matrices to highlight edges.
🔬
Quantum Mechanics

Quantum states and operators are represented as matrices. Matrix multiplication describes how quantum systems evolve over time.

Example: Quantum gates (like the Hadamard or CNOT gates) are matrices that transform quantum states through multiplication.
🏙️
Structural Engineering

Stiffness matrices are used in finite element analysis to model how structures respond to forces and stresses.

Example: Engineers use matrix multiplication to simulate how a bridge will deform under different load conditions.
🧬
Genetics & Biology

Population genetics uses transition matrices to model how gene frequencies change over generations.

Example: The Hardy-Weinberg equilibrium can be represented and analyzed using matrix multiplication.
🌍
Physics & Engineering

Systems of differential equations are solved using matrix methods. Mechanical systems are modeled with matrices.

Example: Vibration analysis in mechanical systems uses matrix multiplication to predict how objects will respond to forces.
📊
Economics

Input-output models use matrices to analyze relationships between different sectors of an economy.

Example: Leontief's input-output model uses matrix multiplication to predict how changes in one industry affect others.
🌐
Network Analysis

Adjacency matrices representing networks can be multiplied to find paths between nodes. PageRank algorithm uses matrix operations.

Example: Google's original PageRank algorithm used matrix multiplication to determine the importance of web pages.
📈
Financial Modeling

Portfolio risk analysis, option pricing, and other financial models use matrix operations to represent correlations and dependencies.

Example: The covariance matrix in Modern Portfolio Theory uses matrix multiplication to optimize investment allocations.
🏭
Operations Research

Linear programming and optimization problems use matrix formulations to find optimal solutions for resource allocation.

Example: Transportation problems use matrices to minimize shipping costs across multiple sources and destinations.

🔍 Understanding the Applied Value: These applications show why matrix multiplication is so important in real-world contexts. The ability to perform complex mathematical operations through matrix multiplication enables more efficient computation and clearer mathematical modeling.

🔍 How to Use This Matrix Multiplication Calculator

Setting Up Matrices
  1. Enter the number of rows and columns for Matrix A
  2. Click "Update" to generate the input grid
  3. Enter the number of rows and columns for Matrix B
  4. Click "Update" to generate the input grid
  5. Fill in the values for each matrix cell

💡 Remember: For matrix multiplication to work, the number of columns in Matrix A must equal the number of rows in Matrix B.

This matrix multiplier calculator follows the standard rules for multiplying matrices. If you need to calculate a matrix product for matrices of different sizes, make sure they are compatible for multiplication.

Inputting Values

You can input:

  • Integers: 1, 2, 3, etc.
  • Decimals: 1.5, 2.75, etc.
  • Fractions: 1/2, 3/4, etc.
  • Variables (in Variable Mode): x, y, a, b, etc.
  • Expressions (in Variable Mode): 2x, y+z, 3a-b, etc.

⌨️ Pro Tip: You can use the Tab key to quickly navigate between matrix cells when entering values.

Need random values? Click the "Random Values" button to populate both matrices with random numbers between 1 and 10 (only available in Numeric Mode).

Calculating and Interpreting Results

After entering your matrices:

  1. Click the "Calculate A × B" button
  2. The result matrix will appear in the result section
  3. Review the step-by-step explanation to understand how each element was calculated

🔄 Want to start over? Click the "Clear" button to reset all matrix values.

In Variable Mode, the calculator will perform symbolic calculations and display algebraic expressions in the result.

Switching Between Numeric and Variable Modes

Use the mode toggle switch at the top of the calculator to switch between:

  • Numeric Mode: For calculations with numbers only
  • Variable Mode: For symbolic calculations with variables and expressions

When in Variable Mode, you'll see additional helper buttons for commonly used variables and operators to make entering expressions easier.

💡 Remember to clear your inputs when switching modes, as numeric and variable calculations work differently.

❓ Frequently Asked Questions

Why can't I multiply matrices of any size?

Matrix multiplication requires that the number of columns in the first matrix equals the number of rows in the second matrix. This is because each element in the result is calculated by taking the dot product of a row from the first matrix and a column from the second matrix, which requires them to be the same length.

What is the difference between matrix multiplication and element-wise multiplication?

Matrix multiplication follows specific rules as explained in this calculator, resulting in a matrix where each element is the sum of products of corresponding row and column elements.

Element-wise multiplication (sometimes called the Hadamard product) simply multiplies corresponding elements directly. For element-wise multiplication, both matrices must be the same size, and the result will also be that size.

Element-wise multiplication example:

1 2
3 4
5 6
7 8
=
5 12
21 32
Why is matrix multiplication not commutative?

Unlike regular number multiplication where a×b = b×a, matrix multiplication is not commutative because the operation depends on the specific arrangement of elements in the matrices. The dimensions and internal structure of matrices make A×B and B×A different operations that generally yield different results.

In some special cases (like when multiplying by an identity matrix), matrix multiplication can be commutative, but this is the exception rather than the rule.

What's the computational complexity of matrix multiplication?

The standard algorithm for multiplying an m×n matrix by an n×p matrix has a time complexity of O(m×n×p). For square matrices of size n×n, this becomes O(n³).

However, there are more efficient algorithms for large matrices:

  • Strassen's algorithm: O(n^2.807)
  • Coppersmith–Winograd algorithm: O(n^2.376)

For practical purposes with small to medium-sized matrices (like those in this calculator), the standard algorithm is usually sufficient.

How can I use variables in matrix calculations?

To use variables in your matrix calculations:

  1. Switch to "Variable Mode" using the toggle at the top of the calculator
  2. Enter single variables (like x, y, a) or expressions (like 2x, y+z) in the matrix cells
  3. Click "Calculate" to perform symbolic matrix multiplication

The calculator will handle the algebraic expressions and display the result as simplified symbolic expressions.

💡 Variable Mode is particularly useful for teaching and learning linear algebra concepts, proving matrix properties, and working with parameterized matrices.

Can I use this calculator for solving systems of linear equations?

While this calculator specifically focuses on matrix multiplication, solving systems of linear equations typically involves multiple matrix operations including:

  1. Representing the system as a matrix equation Ax = b
  2. Finding the inverse of A (if it exists)
  3. Computing x = A⁻¹b

For a full solution to systems of linear equations, you would need additional operations like matrix inversion or Gaussian elimination.

However, with the Variable Mode feature, you can now work with symbolic matrices that represent systems of equations, which is a step toward this capability.

📐 Matrix Multiplication Rules

Formal Definition

For matrices A (m×n) and B (n×p), the product C = A×B is an m×p matrix where:

Cij = ∑k=1n Aik × Bkj

or more explicitly:

Cij = Ai1B1j + Ai2B2j + ... + AinBnj

This means each element of the result matrix is the dot product of the corresponding row of the first matrix and the corresponding column of the second matrix.

Dimensional Constraints

For matrices A and B to be multipliable:

  • The number of columns in A must equal the number of rows in B
  • If A is m×n and B is n×p, then A×B will be m×p

⚠️ If the dimensions don't match, the multiplication is undefined.

Valid multiplications:

  • (2×3) × (3×4) = (2×4)
  • (5×2) × (2×5) = (5×5)
  • (1×4) × (4×1) = (1×1)

Invalid multiplications:

  • (2×3) × (4×5) - Cannot multiply because 3 ≠ 4
  • (3×2) × (3×2) - Cannot multiply because 2 ≠ 3
Key Properties
Property Mathematical Form Description
Non-Commutativity A×B ≠ B×A (generally) Matrix multiplication does not generally commute. The order matters.
Associativity (A×B)×C = A×(B×C) The grouping of multiplications doesn't affect the result.
Distributivity A×(B+C) = A×B + A×C Matrix multiplication distributes over addition.
Identity A×I = I×A = A Multiplying by the identity matrix leaves a matrix unchanged.
Zero Matrix A×0 = 0×A = 0 Multiplying by the zero matrix results in the zero matrix.
Transpose (A×B)ᵀ = Bᵀ×Aᵀ The transpose of a product equals the product of the transposes in reversed order.
Determinants det(A×B) = det(A)×det(B) The determinant of a product equals the product of the determinants.
Multiplication with Special Matrices

Identity Matrix

The identity matrix In is an n×n matrix with 1s on the main diagonal and 0s elsewhere.

For any m×n matrix A:

  • A×In = A
  • Im×A = A

Diagonal Matrices

When D is a diagonal matrix and A is any compatible matrix:

  • Multiplying D from the left (D×A) scales each row of A by the corresponding diagonal element
  • Multiplying D from the right (A×D) scales each column of A by the corresponding diagonal element

Permutation Matrices

Permutation matrices rearrange rows or columns:

  • P×A permutes the rows of A
  • A×P permutes the columns of A

Upper/Lower Triangular Matrices

The product of two upper (or lower) triangular matrices is also upper (or lower) triangular.

Computational Complexity

The standard algorithm for matrix multiplication has different complexities:

Algorithm Time Complexity Notes
Standard Algorithm O(n³) For n×n matrices; Simple nested loops implementation
Strassen's Algorithm O(n^2.807) Uses recursive divide-and-conquer approach
Coppersmith–Winograd O(n^2.376) Improved theoretical algorithm, but rarely used in practice

💡 Order of multiplication matters for efficiency. For matrices A (m×n), B (n×p), and C (p×q), computing (A×B)×C requires m×n×p + m×p×q operations, while A×(B×C) requires n×p×q + m×n×q operations. Choosing the right order can significantly reduce computation.