# Matrix Calculator

The matrix calculator is designed to compute the matrix addition, subtraction, multiplication, transpose, inverse, and determinant.

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

## How to Use the Matrix Calculator?

The matrix calculator can perform all the matrix operations. Follow the instructions below.

1. Firstly, set the number of rows and columns for both matrices. For that, you can simply press the up-down and right-left arrows to add or remove the rows and columns.
2. Now input values for both matrices.
3. To add, subtract, and multiply both matrices, press the 'A + B', 'A - B', and 'AB' buttons.
4. Also, you can swap both matrix values using the 'A ↔ B' button.
5. In addition, the tool allows you to find the transpose, determinant, inverse, and power of the matrix.
6. The 'All 0' button will insert all values as '0'. Similarly, 'All 1' adds all values as 1.
7. The 'Random' button will fill the matrix with random values from 0 to 9.
8. Use the 'Clear' button to clear the matrix values.

### What is Matrix?

A matrix can be simply defined as a set of numbers that are arranged in rows and columns to form a rectangular array. To form a matrix, there should be at least one column or row.

### Dimensions

The dimensions of a matrix tell about the number of rows and columns of the matrix. It is denoted as 'm × n', where m is the number of rows and n is the number of columns.

### Matrix Representation

Let's consider matrix 'A' which includes 2 rows and 3 columns. So, it can be represented as A2 × 3.

The elements of the matrix can be represented in an array form as follows:

A=
 4 2 3 5 6 1

Each element in the above matrices is represented as:

A1 , 1 = 4
A1 , 2 = 2
A1 , 3 = 3
A2 , 1 = 5
A2 , 2 = 6
A2 , 3 = 1

This is the way to represent a matrix as individual entities. The first subscript denotes row and the second one denotes column. Using this value, you can easily determine the position of an element.

### Matrix Operations

The most common matrix operations are addition, subtraction, multiplication, power, transpose, inverse, and calculating determinant. Let's learn all of them one by one.

### Matrix Addition

Matrix addition is only performed if both matrices are the same size. In other words, the matrices to be added should have the exact same number of rows and columns. This means they should have the same dimensions.

Addition Process: When the size/dimensions of the matrices are the same, you need to add the corresponding elements of the matrices to find the sum.

Formula: Ci , j = Ai , j + Bi , j

Here, A and B are the elements of the matrices to be added and C is the resultant matrix.

##### Example:
A =
 4 3 6 5
B =
 5 3 2 7
C =
 4 + 5 3 + 3 6 + 2 5 + 7
C =
 9 6 8 12

### Matrix Subtraction

Matrix subtraction is very much similar to the matrix addition. It is also performed if both matrices are the same size. In other words, both matrices should have exact same number of rows and columns.

Subtraction Process: You need to subtract the corresponding elements of the matrices.

Formula: Ci , j = Ai , j - Bi , j

Let's understand it with an example.

##### Example:
A =
 24 17 9 12
B =
 12 8 2 18
C =
 24 - 12 17 - 8 9 - 2 12 - 18
C =
 12 9 7 -6

### Matrix Multiplication

There are two types of matrix multiplication to be performed.

#### 1. Scalar Multiplication

In scalar multiplication, each element of the single matrix is multiplied by a scalar value. Let's take an example to understand it.

##### Example:
A =
 2 4 5 6
B = 3
3 ×
 2 4 5 6
=
 6 12 15 18

#### 2. Matrix Multiplication with Other Matrix

To multiply two matrices, the number of columns of the first matrix should be equal to the number of rows of the second matrix.

For example, you can multiply 3 × 4 with 4 × 2. But you can not multiply 3 × 4 with 2 × 4.

Note: Matrix multiplication is not a commutative property. It means, it is not necessary that A × B will always be equal to B × A.

Multiplication Process: Two matrices are multiplied by finding the dot product between the corresponding elements of the row of the first matrix and the column of the second matrix.

Formula:
C1 , 1 = (A1 , 1 , A1 , 2) × (B1 , 1 , B2 , 2)
Or
C1 , 1 = A1 , 1 × B1 , 1 + A1 , 2 × B2 , 2

Here, A and B are the elements of the matrices to be multiplied and c is the resultant matrix.

##### Example:
A =
 4 2 3 5
B =
 1 6 0 5
C =
 (4 × 1)+(2 × 0) (3 × 1)+(5 × 0) (4 × 6)+(2 × 5) (3 × 6)+(5 × 5)
C =
 4 34 3 43

### Power of Matrix

Power of matrix meaning is to raise a matrix to a given power.

For example, the given matrix is A. Now calculate matrix A with the power of 2 means: A2 = A × A.

Most importantly, the power can be raised to only square matrices. Because a non-square matrix can not be multiplied by itself.

##### Example:
A2 =
 4 8 3 2
2
=
 4 8 3 2
×
 4 8 3 2
=
 40 48 18 28

### Matrix Transpose

The transpose of a matrix flips its elements over its diagonal. The row elements become column elements whereas the column elements become row elements. Most importantly, the matrix should not be empty.

Transpose Process: To transpose a matrix just switch the rows and column elements. If the matrix contains 2 rows and 3 columns the matrix will now consist of 3 rows and 2 columns.

Formula: Tm , n = Tn , m = T'

Here, T is a matrix containing m rows and n columns that will become n rows and m columns after transpose.

##### Example:
A =
 6 3 9 7
AT =
 6 9 3 7
B =
 10 12 15 20 9 18 22 41
BT =
 10 9 12 18 15 22 20 41

### Matrix Determinant

The Laplace formula is widely used to calculate the determinant of the matrix of any size. Let's understand the process through this formula and example:

##### Formula:
|A|=
 a b c d e f g h i
=
 e f h i
-   b
 d f g i
+   c
 d e g h

= a(ei-fh) - b(di-fg) + c(dh-eg)

##### Example:
|A|=
 3 7 3 5 1 3 2 5 4
=
 1 3 5 4
-   5
 5 3 2 4
+   2
 5 1 2 5

= 3(1×4 - 5×3) – 5(7×4 – 5×3) + 2(7×3 – 3×1)

= 3(-11) – 5(13) + 2(18)

= -62

### Matrix Inverse

Pre-requisites: The matrix should not be empty and you should know the determinant of that matrix. Also, the determinant should not be equal to zero.

Process: To find the inverse of the matrix we use a simple formula where the inverse of the determinant is multiplied with the adjoint of the matrix.

Formula: A-1 = ( 1 / |A| ) × adj(A)

Where, the adjoint of a matrix is the collection of its cofactors which are the determinants of the minor matrices.