๐ฅ MATRIX Operations implemented in JavaScript ๐
Welcoming you to this super exciting ๐งต where we will implement various matrix operations in JavaScript along with their Complexity Analysis (both Time and Space).
Are you excited to know? ๐
We will cover ๐
๐น Dimension
๐น Square Matrix
๐น Diagonal Matrix
๐น Upper Triangular
๐น Lower Triangular
๐น Identity Matrix
๐น Zero Matrix
๐น Transpose Matrix
๐น Scalar Multiplication
๐น Matrix Addition
๐น Matrix Subtraction
๐น Matrix Multiplication
๐น Orthogonal Matrix
โ
0๏ธโฃ Introduction
Matrix is a 2-dimensional (array) arrangement of numbers and it has vast use in Linear Algebra.
Example:
[[aโโ, aโโ, aโโ],
[aโโ, aโโ, aโโ],
[aโโ, aโโ, aโโ]]
Each element in the inner array is called an element of the matrix. Eg, aโโ
++
Each element in the main array is called a row. Eg, [aโโ, aโโ, aโโ]
A column is formed by taking elements at a specific index from each row in order. Eg, [aโโ, aโโ, aโโ]
โ
1๏ธโฃ Dimension of a Matrix
Dimension of a Matrix is specified as the number of rows and number of columns in the matrix.
Example:
[[aโโ, aโโ],
[aโโ, aโโ],
[aโโ, aโโ]]
Dimension is 3x2
โ
2๏ธโฃ Square Matrix
A matrix is called as a "Square Matrix" only if its "number of rows" is equal to its "number of columns".
Example:
[[aโโ, aโโ, aโโ],
[aโโ, aโโ, aโโ],
[aโโ, aโโ, aโโ]]
Here, number of rows is 3 and number of columns is also 3.
โ
3๏ธโฃ Diagonal Matrix
A "Diagonal Matrix" is a square matrix which has only Zeroes (0s) as its non-diagonal elements (row index = column index).
Diagonal elements can be both Non-Zero and Zero.
Example:
[[5, 0, 0],
[0, 2, 0],
[0, 0, -3]]
โ
4๏ธโฃ Upper Triangular Matrix
An "Upper Triangular Matrix" is a square matrix which has only Zeroes (0s) as elements "below" the diagonal elements.
Example:
[[5, 6, 7],
[0, 2, 3],
[0, 0, -3]]
โ
5๏ธโฃ Lower Triangular Matrix
An "Lower Triangular Matrix" is a square matrix which has only Zeroes (0s) as elements "above" the diagonal elements.
Example:
[[5, 0, 0],
[1, 2, 0],
[4, 7, -3]]
โ
6๏ธโฃ Identity/Unity Matrix
An "Identity Matrix" is a diagonal matrix with only 1s as its diagonal elements.
Example:
[[1, 0, 0],
[0, 1, 0],
[0, 0, 1]]
โ
7๏ธโฃ Zero Matrix
A "Zero Matrix" has only Zeroes (0s) as all its elements.
Example:
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0]]
โ
8๏ธโฃ Transpose Matrix
A "Transpose Matrix" is formed by converting rows of a matrix into columns (and thus columns into rows).
Dimension of a transpose matrix is exactly opposite of the dimension of the original matrix.
โ
9๏ธโฃ Scalar Multiplication
By doing "Scalar Multiplication", each element of the matrix is multiplied by a scalar value.
โ
1๏ธโฃ0๏ธโฃ Matrix Addition
By "Matrix Addition", elements at a specific row and column from 2 matrices are added.
โ
1๏ธโฃ1๏ธโฃ Matrix Subtraction
By "Matrix Subtraction", elements at a specific row and column from one matrix is subtracted from the another.
โ
1๏ธโฃ2๏ธโฃ Matrix Multiplication
By "Matrix Multiplication", elements of a row from the first matrix is first multiplied with elements of a column from the second matrix and then summation is taken.
โ
1๏ธโฃ3๏ธโฃ Orthogonal Matrix
A matrix is known as "Orthogonal" when multiplied with its transpose results into an Identity Matrix.
In other words, if transpose of a matrix is equivalent to its inverse, the matrix is orthogonal.
โ
OMISSIONS:
Inverse and, Determinant of a Matrix are omitted because of time constraints.
But, by now you must be familiar with matrix operations. Can you implement these 2 on your own? If you do, share that here in the reply.
We reached to the end of this ๐งต. I hope you enjoyed implementing all these matrix operations in JavaScript.
If you haven't followed yet, do follow me for receiving such informative threads in future.
Share your feedbacks. Support me by giving a Like and RT.
See you soon,๐
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.