C program to check if matrix is antisymmetric?
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
Explanation
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.
Example
#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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Given below is a C language algorithm to convert Roman numerals to decimal numbers: Algorithm Step 1 - Start Step 2 - Read Roman numerals at runtime Step 3 - Length: = strlen(roman) Step 4 - For i=0 to Length-1 Step 4.1-switch(roman[i]) Step 4.1.1-case'm': &nbs

In the first article of this series, we discussed the connections and differences between artificial intelligence, machine learning, deep learning, data science, and more. We also made some hard choices about the programming languages, tools, and more that the entire series would use. Finally, we also introduced a little bit of matrix knowledge. In this article, we will discuss in depth the matrix, the core of artificial intelligence. But before that, let’s first understand the history of artificial intelligence. Why do we need to understand the history of artificial intelligence? There have been many AI booms in history, but in many cases the huge expectations for AI's potential failed to materialize. Understanding the history of artificial intelligence can help us see whether this wave of artificial intelligence will create miracles or is just another bubble about to burst. us

Linked lists use dynamic memory allocation, i.e. they grow and shrink accordingly. They are defined as collections of nodes. Here, a node has two parts, data and links. The representation of data, links and linked lists is as follows - Types of linked lists There are four types of linked lists, as follows: - Single linked list/Singly linked list Double/Doubly linked list Circular single linked list Circular double linked list We use the recursive method to find the length of the linked list The logic is -intlength(node *temp){ if(temp==NULL) returnl; else{&n

The rename function changes a file or directory from its old name to its new name. This operation is similar to the move operation. So we can also use this rename function to move files. This function exists in the stdio.h library header file. The syntax of the rename function is as follows: intrename(constchar*oldname,constchar*newname); The function of the rename() function accepts two parameters. One is oldname and the other is newname. Both parameters are pointers to constant characters that define the old and new names of the file. Returns zero if the file was renamed successfully; otherwise, returns a nonzero integer. During a rename operation

Hyperbolic functions are defined using hyperbolas instead of circles and are equivalent to ordinary trigonometric functions. It returns the ratio parameter in the hyperbolic sine function from the supplied angle in radians. But do the opposite, or in other words. If we want to calculate an angle from a hyperbolic sine, we need an inverse hyperbolic trigonometric operation like the hyperbolic inverse sine operation. This course will demonstrate how to use the hyperbolic inverse sine (asinh) function in C++ to calculate angles using the hyperbolic sine value in radians. The hyperbolic arcsine operation follows the following formula -$$\mathrm{sinh^{-1}x\:=\:In(x\:+\:\sqrt{x^2\:+\:1})}, Where\:In\:is\:natural logarithm\:(log_e\:k)

A map is a special type of container in C++ in which each element is a pair of two values, namely a key value and a map value. The key value is used to index each item, and the mapped value is the value associated with the key. Regardless of whether the mapped value is unique, the key is always unique. To print map elements in C++ we have to use iterator. An element in a set of items is indicated by an iterator object. Iterators are primarily used with arrays and other types of containers (such as vectors), and they have a specific set of operations that can be used to identify specific elements within a specific range. Iterators can be incremented or decremented to reference different elements present in a range or container. The iterator points to the memory location of a specific element in the range. Printing a map in C++ using iterators First, let's look at how to define

Modern science relies heavily on the concept of plural numbers, which was first established in the early 17th century by Girolamo Cardano, who introduced it in the 16th century. The formula for complex numbers is a+ib, where a holds the html code and b is a real number. A complex number is said to have two parts: the real part <a> and the imaginary part (<ib>). The value of i or iota is √-1. The plural class in C++ is a class used to represent complex numbers. The complex class in C++ can represent and control several complex number operations. Let's take a look at how to represent and control the display of plural numbers. imag() member function As mentioned above, complex numbers are composed of real part and imaginary part. To display the real part we use real()

Using strings or characters is sometimes very useful when solving some logic programming problems. A string is a collection of characters, which is a 1-byte data type used to hold symbols in ASCII values. Symbols can be English letters, numbers, or special characters. In this article, we will learn how to check if a character is an English letter or a letter of the alphabet using C++. Checking the isalpha() function To check if a number is a letter, we can use the isalpha() function in the ctype.h header file. This takes a character as input and returns true if it is an alphabet, false otherwise. Let us look at the following C++ implementation to understand the usage of this function. The Chinese translation of Example is: show
