행렬 M[r][c]가 주어졌을 때 'r'은 행의 개수를 나타내고 'c'는 r =c가 정방행렬을 이루는 열의 개수를 나타냅니다. 주어진 정사각형 행렬이 Involutory 행렬인지 확인해야 합니다. 여부.
Involutory 매트릭스
매트릭스를 Involutory라고 합니다. 행렬이 자체와 곱해지고 그 결과가 단위 행렬인 경우에만 행렬입니다. 행렬 I은 주대각선이 1이고 주대각선이 아닌 다른 요소가 0인 경우에만 단위 행렬입니다. 따라서 행렬은 Involutory 행렬이라고 말할 수 있습니다. M*M=I인 경우에만 , 여기서 M 는 일부 행렬이고 나는 항등 행렬입니다.
아래 주어진 예에서와 같이 -

여기서 행렬에 자체를 곱하면 결과는 단위 행렬입니다. 따라서 주어진 행렬은 Involutory Matrix입니다.
예시
Input: { {1, 0, 0},
{0, -1, 0},
{0, 0, -1}}
Output: yes
Input: { {3, 0, 0},
{0, 2, 0},
{0, 0, 3} }
Output: no 알고리즘
Start
Step 1 -> define macro as #define size 3
Step 2 -> declare function for matrix multiplication.
void multiply(int arr[][size], int res[][size])
Loop For int i = 0 and i < size and i++
Loop For int j = 0 and j < size and j++
Set res[i][j] = 0
Loop For int k = 0 and k < size and k++
Set res[i][j] += arr[i][k] * arr[k][j]
End
End
End
Step 3 -> declare function to check involutory matrix or not
bool check(int arr[size][size])
declare int res[size][size]
Call multiply(arr, res)
Loop For int i = 0 and i < size and i++
Loop For int j = 0 and j < size and j++
IF (i == j && res[i][j] != 1)
return false
End
If (i != j && res[i][j] != 0)
return false
End
End
End
Return true
Step 4 -> In main()
Declare int arr[size][size] = { { 1, 0, 0 },
{ 0, -1, 0 },
{ 0, 0, -1 } }
If (check(arr))
Print its an involutory matrix
Else
Print its not an involutory matrix
Stop 예시
#include <bits/stdc++.h>
#define size 3
using namespace std;
// matrix multiplication.
void multiply(int arr[][size], int res[][size]){
for (int i = 0; i < size; i++){
for (int j = 0; j < size; j++){
res[i][j] = 0;
for (int k = 0; k < size; k++)
res[i][j] += arr[i][k] * arr[k][j];
}
}
}
// check involutory matrix or not.
bool check(int arr[size][size]){
int res[size][size];
multiply(arr, res);
for (int i = 0; i < size; i++){
for (int j = 0; j < size; j++){
if (i == j && res[i][j] != 1)
return false;
if (i != j && res[i][j] != 0)
return false;
}
}
return true;
}
int main(){
int arr[size][size] = { { 1, 0, 0 },
{ 0, -1, 0 },
{ 0, 0, -1 } };
if (check(arr))
cout << "its an involutory matrix";
else
cout << "its not an involutory matrix";
return 0;
} 출력
its an involutory matrix