Check Idempotent Matrix

Check Idempotent Matrix” is a problem of matrix where we need to check whether given matrix is an idempotent matrix or not.

There are basically three different types of matrix:

  1. Identity Matrix: An identity matrix is a square matrix of size N*N which have all the diagonal element as 1 and others as 0.
  2. Idempotent Matrix: An Idempotent matrix is a matrix which is when multiplied by itself produces the same matrix.
  3. Involuntary Matrix: An involutory matrix is a matrix which when multiplied by itself gives identity matrix.

Here, we are given a square matrix of size N*N. Our task is to check whether the given matrix is idempotent matrix or not. 


N = 3
2  -2 -4
-1  3  4
1  -2 -3
Idempotent Matrix

The solution of the above problem is to multiply the given matrix by itself and store the result in resultant matrix. If the resultant matrix is same as the given matrix, then given matrix is said to be idempotent. Else, it is not an idempotent matrix.

C++ Program to check whether the given matrix is idempotent or not is as follows:

using namespace std;  
int main()  

    // Scan Dimension of the matrix  
    int n;  
    cout<<"Enter the dimesion of square matrix:\n";  
    // Scan Elements of the matrix  
    int matrix[n][n];  
    cout<<"Enter the elements of square matrix:\n";  
    for(int i = 0 ; i < n ; i++)  
    for(int j = 0 ; j < n ; j++)  
    // Initializing resultant matrix with 0  
    int resultant[n][n];  
    for(int i = 0 ; i < n ; i++)  
    for(int j = 0 ; j < n ; j++)  
    resultant[i][j] = 0;  
    //Multiply the matrix with itself and storing  
    // the result in resultant matrix  
    for (int i = 0 ; i < n ; i++)  
        for (int j = 0 ; j < n ; j++)  
            for (int k = 0 ; k < n ; k++)   
                resultant[i][j] += matrix[i][k] * matrix[k][j];   
    //Check whether the resultant matrix is   
    // equal to given matrix or not   
    bool result = true;  
    for (int i = 0 ; i < n ; i++)  
        for (int j = 0 ; j < n ; j++)  
            if(matrix[i][j] != resultant[i][j])  
                result = false;  
    cout<<"Idempodent Matrix!!";  
    cout<<"Not Idempodent Matrix";  

Enter the dimesion of square matrix: 3
Enter the elements of square matrix:
2 -2 -4
-1 3 4
1 -2 -3
Idempotent Matrix!!

Related Posts:

  1. Program to check Involuntary Matrix.
  2. Program to print matrix in zig-zag order.
  3. Program to print matrix in spiral order.
  4. Program to sort a matrix.
  5. Program to Add two Matrix.
  6. Program to Transpose a Matrix.
  7. Program to Multiply Two Matrix.
  8. Program to check Identity Matrix.
  9. Program to find most frequent element in an array.
  10. Program to find pair in an array with given sum.
  11. Program to find first repeating element of an array.
  12. Program to merge two sorted arrays.
  13. Program to find missing number in an array.
  14. Program to sort if array is sorted.
  15. Program to print Alternate Elements of an Array.
  16. Program to swap kth element from beginning to kth element from end in an Array.
  17. Program to print all possible subarrays of the given array.
  18. Program to print kth smallest and kth largest element of an Array.
  19. Program to find longest palindromic Substring.
  20. Program to check Anagram Strings.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *