Matrix Calculator

Matrix A Input
row  column
  ×
Matrix B Input
row  column
  ×

A matrix, in a mathematical context, is a rectangular array of numbers, symbols, or expressions that are arranged in rows and columns. Matrices are often used in scientific fields such as physics, computer graphics, probability theory, statistics, calculus, numerical analysis, and more.

The dimensions of a matrix, A, are typically denoted as m × n. This means that A has m rows and n columns. When referring to a specific value in a matrix, called an element, a variable with two subscripts is often used to denote each element based on its position in the matrix. For example, given ai,j, where i = 1 and j = 3, a1,3 is the value of the element in the first row and the third column of the given matrix.

Matrix operations such as addition, multiplication, subtraction, etc., are similar to what most people are likely accustomed to seeing in basic arithmetic and algebra, but do differ in some ways, and are subject to certain constraints. Below are descriptions of the matrix operations that this calculator can perform.

Matrix addition

Matrix addition can only be performed on matrices of the same size. This means that you can only add matrices if both matrices are m × n. For example, you can add two or more 3 × 3, 1 × 2, or 5 × 4 matrices. You cannot add a 2 × 3 and a 3 × 2 matrix, a 4 × 4 and a 3 × 3, etc. The number of rows and columns of all the matrices being added must exactly match.

If the matrices are the same size, matrix addition is performed by adding the corresponding elements in the matrices. For example, given two matrices, A and B, with elements ai,j, and bi,j, the matrices are added by adding each element, then placing the result in a new matrix, C, in the corresponding position in the matrix:

A =
12
34
; B =
56
78

In the above matrices, a1,1 = 1; a1,2 = 2; b1,1 = 5; b1,2 = 6; etc. We add the corresponding elements to obtain ci,j. Adding the values in the corresponding rows and columns:

a1,1 + b1,1 = 1 + 5 = 6 = c1,1
a1,2 + b1,2 = 2 + 6 = 8 = c1,2
a2,1 + b2,1 = 3 + 7 = 10 = c2,1
a2,2 + b2,2 = 4 + 8 = 12 = c2,2

Thus, matrix C is:

C =
68
1012

Matrix subtraction

Matrix subtraction is performed in much the same way as matrix addition, described above, with the exception that the values are subtracted rather than added. If necessary, refer to the information and examples above for a description of notation used in the example below. Like matrix addition, the matrices being subtracted must be the same size. If the matrices are the same size, then matrix subtraction is performed by subtracting the elements in the corresponding rows and columns:

A =
12
34
; B =
56
78
a1,1 - b1,1 = 1 - 5 = -4 = c1,1
a1,2 - b1,2 = 2 - 6 = -4 = c1,2
a2,1 - b2,1 = 3 - 7 = -4 = c2,1
a2,2 - b2,2 = 4 - 8 = -4 = c2,2

Thus, matrix C is:

C =
-4-4
-4-4

Matrix multiplication

Scalar multiplication:

Matrices can be multiplied by a scalar value by multiplying each element in the matrix by the scalar. For example, given a matrix A and a scalar c:

A =
12
34
; c = 5

The product of c and A is:

5 ×
12
34
=
510
1520

Matrix-matrix multiplication:

Multiplying two (or more) matrices is more involved than multiplying by a scalar. In order to multiply two matrices, the number of columns in the first matrix must match the number of rows in the second matrix. For example, you can multiply a 2 × 3 matrix by a 3 × 4 matrix, but not a 2 × 3 matrix by a 4 × 3.

Can be multiplied:

A =
a1,1a1,2a1,3
a2,1a2,2a2,3
; B =
b1,1b1,2b1,3b1,4
b2,1b2,2b2,3b2,4
b3,1b3,2b3,3b3,4

Cannot be multiplied:

A =
a1,1a1,2a1,3
a2,1a2,2a2,3
; B =
b1,1b1,2b1,3
b2,1b2,2b2,3
b3,1b3,2b3,3
b4,1b4,2b4,3

Note that when multiplying matrices, A × B does not necessarily equal B × A. In fact, just because A can be multiplied by B doesn't mean that B can be multiplied by A.

If the matrices are the correct sizes, and can be multiplied, matrices are multiplied by performing what is known as the dot product. The dot product involves multiplying the corresponding elements in the row of the first matrix, by that of the columns of the second matrix, and summing up the result, resulting in a single value. The dot product can only be performed on sequences of equal lengths. This is why the number of columns in the first matrix must match the number of rows of the second.

The dot product then becomes the value in the corresponding row and column of the new matrix, C. For example, from the section above of matrices that can be multiplied, the blue row in A is multiplied by the blue column in B to determine the value in the first column of the first row of matrix C. This is referred to as the dot product of row 1 of A and column 1 of B:

a1,1×b1,1 + a1,2×b2,1 + a1,3×b3,1 = c1,1

The dot product is performed for each row of A and each column of B until all combinations of the two are complete in order to find the value of the corresponding elements in matrix C. For example, when you perform the dot product of row 1 of A and column 1 of B, the result will be c1,1 of matrix C. The dot product of row 1 of A and column 2 of B will be c1,2 of matrix C, and so on, as shown in the example below:

A =
121
341
; B =
5611
7811
1111

When multiplying two matrices, the resulting matrix will have the same number of rows as the first matrix, in this case A, and the same number of columns as the second matrix, B. Since A is 2 × 3 and B is 3 × 4, C will be a 2 × 4 matrix. The colors here can help determine first, whether two matrices can be multiplied, and second, the dimensions of the resulting matrix. Next, we can determine the element values of C by performing the dot products of each row and column, as shown below:

C =
202344
445188

Below, the calculation of the dot product for each row and column of C is shown:

c1,1 = 1×5 + 2×7 + 1×1 = 20
c1,2 = 1×6 + 2×8 + 1×1 = 23
c1,3 = 1×1 + 2×1 + 1×1 = 4
c1,4 = 1×1 + 2×1 + 1×1 = 4
c2,1 = 3×5 + 4×7 + 1×1 = 44
c2,2 = 3×6 + 4×8 + 1×1 = 51
c2,3 = 3×1 + 4×1 + 1×1 = 8
c2,4 = 3×1 + 4×1 + 1×1 = 8

Power of a matrix

For the intents of this calculator, "power of a matrix" means to raise a given matrix to a given power. For example, when using the calculator, "Power of 2" for a given matrix, A, means A2. Exponents for matrices function in the same way as they normally do in math, except that matrix multiplication rules also apply, so only square matrices (matrices with an equal number of rows and columns) can be raised to a power. This is because a non-square matrix, A, cannot be multiplied by itself. A × A, in this case, is not possible to compute. Refer to the matrix multiplication section, if necessary, for a refresher on how to multiply matrices. Given:

A =
13
21

A raised to the power of 2 is:

A2 =
13
21
2
=
13
21
×
13
21
=
76
47

As with exponents in other mathematical contexts, A3, would equal A × A × A, A4 would equal A × A × A × A, and so on.

Transpose of a matrix

The transpose of a matrix, typically indicated with a "T" as an exponent, is an operation that flips a matrix over its diagonal. This results in switching the row and column indices of a matrix, meaning that aij in matrix A, becomes aji in AT. If necessary, refer above for a description of the notation used.

An m × n matrix, transposed, would therefore become an n × m matrix, as shown in the examples below:

A =
13
21
AT =
12
31
B =
202344
445188
BT =
2044
2351
48
48

Determinant of a matrix

The determinant of a matrix is a value that can be computed from the elements of a square matrix. It is used in linear algebra, calculus, and other mathematical contexts. For example, the determinant can be used to compute the inverse of a matrix or to solve a system of linear equations.

There are a number of methods and formulas for calculating the determinant of a matrix. The Leibniz formula and the Laplace formula are two commonly used formulas.

Determinant of a 2 × 2 matrix:

The determinant of a 2 × 2 matrix can be calculated using the Leibniz formula, which involves some basic arithmetic. Given matrix A:

A =
ab
cd

The determinant of A using the Leibniz formula is:

|A| =
ab
cd
= ad - bc

Note that taking the determinant is typically indicated with "| |" surrounding the given matrix. Given:

A =
24
68
|A| =
24
68
= 2×8 - 4×6= -8

Determinant of a 3 × 3 matrix:

One way to calculate the determinant of a 3 × 3 matrix is through the use of the Laplace formula. Both the Laplace formula and the Leibniz formula can be represented mathematically, but involve the use of notations and concepts that won't be discussed here. Below is an example of how to use the Laplace formula to compute the determinant of a 3 × 3 matrix:

|A| =
abc
def
ghi
=
a
ef
hi
- b
df
gi
+ c
de
gh

From this point, we can use the Leibniz formula for a 2 × 2 matrix to calculate the determinant of the 2 × 2 matrices, and since scalar multiplication of a matrix just involves multiplying all values of the matrix by the scalar, we can multiply the determinant of the 2 × 2 by the scalar as follows:

|A| =
abc
def
ghi
= a(ei-fh) - b(di-fg) + c(dh-eg)

This can further be simplified to:

|A| = aei + bfg + cdh - ceg - bdi - afh

This is the Leibniz formula for a 3 × 3 matrix.

Determinant of a 4 × 4 matrix and higher:

The determinant of a 4 × 4 matrix and higher can be computed in much the same way as that of a 3 × 3, using the Laplace formula or the Leibniz formula. As with the example above with 3 × 3 matrices, you may notice a pattern that essentially allows you to "reduce" the given matrix into a scalar multiplied by the determinant of a matrix of reduced dimensions, i.e. a 4 × 4 being reduced to a series of scalars multiplied by 3 × 3 matrices, where each subsequent pair of scalar × reduced matrix has alternating positive and negative signs (i.e. they are added or subtracted).

The process involves cycling through each element in the first row of the matrix. Eventually, we will end up with an expression in which each element in the first row will be multiplied by a lower-dimension (than the original) matrix. The elements of the lower-dimension matrix is determined by blocking out the row and column that the chosen scalar are a part of, and having the remaining elements comprise the lower dimension matrix. Refer to the example below for clarification.

Here, we first choose element a. The elements in blue are the scalar, a, and the elements that will be part of the 3 × 3 matrix we need to find the determinant of:

|A| =
abcd
efgh
ijkl
mnop
=
a
fgh
jkl
nop
- ...

Next, we choose element b:

abcd
efgh
ijkl
mnop
b
egh
ikl
mop

Continuing in the same manner for elements c and d, and alternating the sign (+ - + - ...) of each term:

|A| =
abcd
efgh
ijkl
mnop
= a
fgh
jkl
nop
- b
egh
ikl
mop
+ c
efh
ijl
mnp
- d
efg
ijk
mno

We continue the process as we would a 3 × 3 matrix (shown above), until we have reduced the 4 × 4 matrix to a scalar multiplied by a 2 × 2 matrix, which we can calculate the determinant of using Leibniz's formula. As can be seen, this gets tedious very quickly, but it is a method that can be used for n × n matrices once you have an understanding of the pattern. There are other ways to compute the determinant of a matrix that can be more efficient, but require an understanding of other mathematical concepts and notations.

Inverse of a matrix

The inverse of a matrix A is denoted as A-1, where A-1 is the inverse of A if the following is true:

A×A-1 = A-1×A = I, where I is the identity matrix

Identity matrix:

The identity matrix is a square matrix with "1" across its diagonal, and "0" everywhere else. The identity matrix is the matrix equivalent of the number "1." For example, the number 1 multiplied by any number n equals n. The same is true of an identity matrix multiplied by a matrix of the same size: A × I = A. Note that an identity matrix can have any square dimensions. For example, all of the matrices below are identity matrices. From left to right respectively, the matrices below are a 2 × 2, 3 × 3, and 4 × 4 identity matrix:

10
01
;  
100
010
001
;  
1000
0100
0010
0001
...

The n × n identity matrix is thus:

In =
100...0
010...0
001...0
...............
000...1

Inverse of a 2 × 2 matrix:

To invert a 2 × 2 matrix, the following equation can be used:

A-1 =
ab
cd
-1
=
1 
d-b
-ca
det(A)
=
1 
d-b
-ca
ad - bc

For example, given:

A =
24
37
A-1 =
1 
7-4
-32
2×7 - 4×3
=
1 
7-4
-32
2
=
3.5-2
-1.51

If you were to test that this is, in fact, the inverse of A you would find that both:

24
37
×
3.5-2
-1.51
and
3.5-2
-1.51
×
24
37

are equal to the identity matrix:

I =
10
01

Inverse of a 3 × 3 matrix:

The inverse of a 3 × 3 matrix is more tedious to compute. An equation for doing so is provided below, but will not be computed. Given:

M =
abc
def
ghi
M-1 =
1
det(M)
ABC
DEF
GHI
T
=
1
det(M)
ADG
BEH
CFI

where:

A=ei-fh; B=-(di-fg); C=dh-eg D=-(bi-ch); E=ai-cg; F=-(ah-bg) G=bf-ce; H=-(af-cd); I=ae-bd

4 × 4 and larger get increasingly more complicated, and there are other methods for computing them.

Financial Fitness & Health Math Other