If for all i and j, the elements of the square matrix A satisfy aij=−aji, then the square matrix A is called an antisymmetric matrix. In other words, if the transpose of matrix A is equal to the negative value of matrix A, that is, (AT=−A), then matrix A is called an antisymmetric matrix.
Note that all main diagonal elements of an antisymmetric matrix are zero.
Let us take an example of a matrix
A= |0 -5 4| |5 0 -1| |-4 1 0|
This is a skew symmetric matrix because for all i and j, aij=−aji. For example, a12 = -5, a21 = 5, which means a12 = −a21. Likewise, this condition holds for all other values of i and j.
We can also verify that the transpose of matrix A is equal to the negative number of matrix A, that is, AT=−A.
A<sup>T</sup>= |0 5 -4| |-5 0 1| |4 -1 0| and A= |0 -5 4| |5 0 -1| |-4 1 0|
We can clearly see that AT=−A, which makes A a skew symmetric matrix.
Input: Enter the number of rows and columns: 2 2 Enter the matrix elements: 10 20 20 10 Output: The matrix is symmetric. 10 20 20 10
A matrix is a symmetric matrix if it is equal to its transpose.
Otherwise, if its transpose is equal to its negative, then the matrix is antisymmetric. Otherwise it is neither symmetric nor antisymmetric. The results will be printed accordingly.
The process for checking matrix symmetry is as follows:
Requires the user to enter the number of rows and columns of the matrix.
Requires the elements of the input matrix and stores them in 'A'. Initialize the variables 'x' and 'y' to 0.
If the matrix is not equal to its transpose, assign the value of 1 to the temporary variable 'x'.
Otherwise, if the negative number of the matrix is equal to its transpose, assign the value of 1 to the temporary variable 'y'.
If x equals 0, the matrix is symmetric. Otherwise, if y equals 1, the matrix is antisymmetric.
If none of the above conditions are met, the matrix is neither symmetric nor antisymmetric.
Then print the result.
#include<iostream> using namespace std; int main () { int A[10][10], i, j, m, n, x = 0, y = 0; cout << "Enter the number of rows and columns : "; cin >> m >> n; cout << "Enter the matrix elements : "; for (i = 0; i < m; i++) for (j = 0; j < n; j++) cin >> A[i][j]; for (i = 0; i < m; i++) { for( j = 0; j < n; j++) { if (A[i][j] != A[j][i]) x = 1; else if (A[i][j] == -A[j][i]) y = 1; } } if (x == 0) cout << "The matrix is symmetric.</p><p> "; else if (y == 1) cout << "The matrix is skew symmetric.</p><p> "; else cout << "It is neither symmetric nor skew-symmetric.</p><p> "; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) cout << A[i][j] << " "; cout << "</p><p> "; } return 0; }
The above is the detailed content of C program to check if matrix is antisymmetric?. For more information, please follow other related articles on the PHP Chinese website!