Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

C++ Program to check Involutory Matrix

  • Last Updated : 18 Jan, 2022

Given a matrix and the task is to check matrix is involutory matrix or not. 
Involutory Matrix: A matrix is said to be involutory matrix if matrix multiply by itself return the identity matrix. Involutory matrix is the matrix that is its own inverse. The matrix A is said to be involutory matrix if A * A = I. Where I is the identity matrix. 
 

Involutory-Matrix

Examples: 

Input : mat[N][N] = {{1, 0, 0},
                     {0, -1, 0},
                     {0, 0, -1}}
Output : Involutory Matrix

Input : mat[N][N] = {{1, 0, 0},
                     {0, 1, 0},
                     {0, 0, 1}} 
Output : Involutory Matrix

C++




// Program to implement involutory matrix.
#include <bits/stdc++.h>
#define N 3
using namespace std;
  
// Function for matrix multiplication.
void multiply(int mat[][N], int res[][N])
{
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            res[i][j] = 0;
            for (int k = 0; k < N; k++)
                res[i][j] += mat[i][k] * mat[k][j];
        }
    }
}
  
// Function to check involutory matrix.
bool InvolutoryMatrix(int mat[N][N])
{
    int res[N][N];
  
    // multiply function call.
    multiply(mat, res);
  
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j && res[i][j] != 1)
                return false;
            if (i != j && res[i][j] != 0)
                return false;
        }
    }
    return true;
}
  
// Driver function.
int main()
{
    int mat[N][N] = { { 1, 0, 0 },
                      { 0, -1, 0 },
                      { 0, 0, -1 } };
  
    // Function call. If function return
    // true then if part will execute otherwise
    // else part will execute.
    if (InvolutoryMatrix(mat))
        cout << "Involutory Matrix";
    else
        cout << "Not Involutory Matrix";
  
    return 0;
}

Output : 

Involutory Matrix

Please refer complete article on Program to check Involutory Matrix for more details!


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!