Cho một ma trận M [r] [c], ‘r’ biểu thị số hàng và ‘c’ biểu thị số cột sao cho r =c tạo thành một ma trận vuông. Chúng tôi phải kiểm tra xem ma trận vuông đã cho có phải là Ma trận không có cơ sở hoặc không.
Ma trận xâm lược
Ma trận được gọi là Involutory ma trận nếu và chỉ khi, khi một ma trận được nhân với chính nó và kết quả của nó là một ma trận nhận dạng. Ma trận I là ma trận Nhận dạng nếu và chỉ khi đường chéo chính của nó là một và các phần tử khác ngoài đường chéo chính bằng không. Vì vậy, chúng ta có thể nói một ma trận là Ma trận không hoạt động nếu và chỉ khi M * M =I , ở đâu M là một số ma trận và tôi là một Ma trận Nhận dạng.
Giống như trong Ví dụ cho sẵn bên dưới -
Ở đây khi chúng ta nhân ma trận với chính nó, kết quả là ma trận nhận dạng; do đó ma trận đã cho là Ma trận xâm phạm.
Ví dụ
Input: { {1, 0, 0},
{0, -1, 0},
{0, 0, -1}}
Output: yes
Input: { {3, 0, 0},
{0, 2, 0},
{0, 0, 3} }
Output: no Thuật toán
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 Ví dụ
#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;
} Đầu ra
its an involutory matrix