Javascript Program to check idempotent matrix Last Updated : 12 Sep, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Given an N * N matrix and the task is to check matrix is an idempotent matrix or not.Idempotent matrix: A matrix is said to be an idempotent matrix if the matrix multiplied by itself returns the same matrix. The matrix M is said to be an idempotent matrix if and only if M * M = M. In an idempotent matrix M is a square matrix.Examples: Input : mat[][] = {{3, -6}, {1, -2}};Output : Idempotent MatrixInput : mat[N][N] = {{2, -2, -4}, {-1, 3, 4}, {1, -2, -3}}Output : Idempotent Matrix. JavaScript // Javascript program to check given matrix // is idempotent matrix or not. let N = 3; // Function for matrix multiplication. function multiply(mat, res) { for (let i = 0; i < N; i++) { for (let j = 0; j < N; j++) { res[i][j] = 0; for (let k = 0; k < N; k++) res[i][j] += mat[i][k] * mat[k][j]; } } return res; } // Function to check idempotent // property of matrix. function checkIdempotent(mat) { // Calculate multiplication of matrix // with itself and store it into res. let res = Array.from(Array(N), () => Array(N).fill(0)); res = multiply(mat, res); for (let i = 0; i < N; i++) { for (let j = 0; j < N; j++) { if (mat[i][j] != res[i][j]) return false; } } return true; } // Driver code let mat = [[2, -2, -4], [-1, 3, 4], [1, -2, -3]]; // checkIdempotent function call. if (checkIdempotent(mat)) console.log("Idempotent Matrix"); else console.log("Not Idempotent Matrix."); // This code is contributed by noob2000. OutputIdempotent Matrix Complexity Analysis:Time Complexity: O(N3)Auxiliary Space: O(N2)Please refer complete article on Program to check idempotent matrix for more details! Comment More infoAdvertise with us Next Article Javascript Program to check idempotent matrix K kartik Follow Improve Article Tags : JavaScript Similar Reads Javascript Program to check Involutory Matrix Given a matrix, the task is to check matrix is an involutory matrix or not. Involutory Matrix: A matrix is said to be an involutory matrix if the matrix multiplied by itself returns the identity matrix. The involutory matrix is the matrix that is its inverse. The matrix A is said to be an involutory 2 min read Javascript Program to check if a matrix is symmetric A square matrix is said to be symmetric matrix if the transpose of the matrix is same as the given matrix. Symmetric matrix can be obtain by changing row to column and column to row.Examples: Input : 1 2 3 2 1 4 3 4 3 Output : Yes Input : 3 5 8 3 4 7 8 5 3 Output : NoA Simple solution is to do follo 2 min read Javascript Program to Check if a given matrix is sparse or not A matrix is a two-dimensional data object having m rows and n columns, therefore a total of m*n values. If most of the values of a matrix are 0 then we say that the matrix is sparse. Consider a definition of Sparse where a matrix is considered sparse if the number of 0s is more than half of the elem 2 min read JavaScript Program to Check if a Given Square Matrix is an Identity Matrix Given a matrix, our task is to check if a given square matrix is an Identity Matrix. An identity matrix (unit matrix) is a square matrix in which the principal diagonal elements are all one and other elements in the matrix are zero. Example:Input:[ [ 1, 0, 0] , [0, 1, 0] , [0, 0, 1]] Output: True Be 3 min read Javascript Program for Diagonally Dominant Matrix In mathematics, a square matrix is said to be diagonally dominant if for every row of the matrix, the magnitude of the diagonal entry in a row is larger than or equal to the sum of the magnitudes of all the other (non-diagonal) entries in that row. More precisely, the matrix A is diagonally dominant 2 min read Like