선형 대수학에서 행렬 M[][]은 행렬의 전치가 행렬 자체와 동일한 경우에만 대칭 행렬이라고 합니다. 행렬의 전치는 행렬을 대각선으로 뒤집을 때 발생하며 결과적으로 행렬의 행 인덱스와 열 인덱스가 바뀝니다.
대칭 행렬의 예 아래 -
$$\begin{bmatrix} 1 &4 &7 \\ 4 &5 &6 \\ 7 &6 &9 \\ \end {bmatrix} \Rightarrow \begin{bmatrix} 1 &4 &7 \\ 4 &5 &6 \\ 7 &6 &9 \\ \end{bmatrix}$$
위의 행렬은 우리가 왼쪽에 있는 행렬을 가져와서 전치한 대칭 행렬이며 결과는 행렬 자체와 같습니다.
예시
Input: arr1[][n] = { { 1, 2, 3 },
{ 2, 2, 4 },
{ 3, 4, 1 } };
Output: its a symmetric matrix
Input: arr1[][n] = { { 1, 7, 3 },
{ 2, 9, 5 },
{ 4, 6, 8 } };
Output: its not a symmetric matrix 접근
다음 단계를 따르기만 하면 됩니다 −
- 1. 행렬을 가져와 다른 행렬에 전치를 저장합니다.
- 2. 결과 행렬이 입력 행렬과 동일한지 확인하십시오.
알고리즘
Start
Step 1 -> define macro as #define n 10
Step 2 -> declare function to find transporse of a matrix
void transpose(int arr1[][n], int arr2[][n], int a)
Loop For int i = 0 and i < a and i++
Loop For int j = 0 and j < a and j++
Set arr2[i][j] = arr1[j][i]
End
End
Step 3 -> declare function to check symmetric or not
bool check(int arr1[][n], int a)
declare variable as int arr2[a][n]
Call transpose(arr1, arr2, a)
Loop For int i = 0 and i < a and i++
Loop For int j = 0 and j < a and j++
IF (arr1[i][j] != arr2[i][j])
return false
End
End
End
Return true
Step 4 -> In main()
Declare variable as int arr1[][n] = { { 1, 2, 3 },
{ 2, 2, 4 },
{ 3, 4, 1 } }
IF (check(arr1, 3))
Print its a symmetric matrix
Else
Print its not a symmetric matrix
Stop 예시
#include <iostream>
#define n 10
using namespace std;
//find transporse of a matrix
void transpose(int arr1[][n], int arr2[][n], int a){
for (int i = 0; i < a; i++)
for (int j = 0; j < a; j++)
arr2[i][j] = arr1[j][i];
}
//check symmetric or not
bool check(int arr1[][n], int a){
int arr2[a][n];
transpose(arr1, arr2, a);
for (int i = 0; i < a; i++)
for (int j = 0; j < a; j++)
if (arr1[i][j] != arr2[i][j])
return false;
return true;
}
int main(){
int arr1[][n] = { { 1, 2, 3 },
{ 2, 2, 4 },
{ 3, 4, 1 } };
if (check(arr1, 3))
cout << "its a symmetric matrix";
else
cout << "its not a symmetric matrix";
return 0;
} 출력
its a symmetric matrix