PHP Program to Check Involutory Matrix Last Updated : 22 Jul, 2024 Comments Improve Suggest changes Like Article Like Report Given a matrix, the task is to check matrix is involutory matrix or not. Involutory Matrix: A matrix is said to be involutory matrix if the matrix multiply by itself return the identity matrix. Involutory matrix is the matrix that is its own inverse. The matrix A is said to be involutory matrix if A * A = I. Where I is the identity matrix. Examples: Input : mat = [[ 1, 0, 0 ], [ 0, -1, 0 ], [ 0, 0, -1 ]]Output : Involutory MatrixInput : mat = [[ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ]] Output : Involutory Matrix PHP <?php // Program to implement // involutory matrix. $N = 3; // Function for matrix // multiplication. function multiply($mat, $res) { global $N; for ($i = 0; $i < $N; $i++) { for ($j = 0; $j < $N; $j++) { $res[$i][$j] = 0; for ($k = 0; $k < $N; $k++) $res[$i][$j] += $mat[$i][$k] * $mat[$k][$j]; } } return $res; } // Function to check // involutory matrix. function InvolutoryMatrix($mat) { global $N; $res; for ($i = 0; $i < $N; $i++) for ($j = 0; $j < $N; $j++) $res[$i][$j] = 0; // multiply function call. $res = multiply($mat, $res); for ($i = 0; $i < $N; $i++) { for ($j = 0; $j < $N; $j++) { if ($i == $j && $res[$i][$j] != 1) return false; if ($i != $j && $res[$i][$j] != 0) return false; } } return true; } // Driver Code $mat = array(array(1, 0, 0), array(0, -1, 0), array(0, 0, -1)); // Function call. If function // return true then if part // will execute otherwise // else part will execute. if (InvolutoryMatrix($mat)) echo "Involutory Matrix"; else echo "Not Involutory Matrix"; ?> OutputInvolutory MatrixTime complexity: O(N3)Auxiliary space: O(N2)Please refer complete article on Program to check Involutory Matrix for more details! Comment More infoAdvertise with us Next Article PHP Program to Check Involutory Matrix kartik Follow Improve Article Tags : Mathematical Matrix Web Technologies PHP PHP Programs DSA +2 More Practice Tags : MathematicalMatrix Similar Reads PHP Program to Check if Matrix is Lower Triangular Given a square matrix and the task is to check the matrix is in lower triangular form or not. A square matrix is called lower triangular if all the entries above the main diagonal are zero.  Examples:  Input : mat = [[ 1, 0, 0, 0 ], [ 1, 4, 0, 0 ], [ 4, 6, 2, 0 ], [ 0, 4, 7, 6 ]];Output : Matrix is 2 min read PHP Program to Form coils in a matrix Given a positive integer n which represents the dimensions of a 4n x 4n matrix with values from 1 to n filled from left to right and top to bottom. Form two coils from the matrix and print the coils.Examples:  Input : n = 1; Output : Coil 1 : 10 6 2 3 4 8 12 16 Coil 2 : 7 11 15 14 13 9 5 1 Explanati 3 min read PHP Program to Check if a Matrix is Symmetric A square matrix is said to be a symmetric matrix if the transpose of the matrix is the same as the given matrix. A Symmetric matrix can be obtain by changing row to column and column to row.Examples: Input : [ [ 1, 2, 3 ], [ 2, 1, 4 ], [ 3, 4, 3 ] ] Output : Yes Input : [ [ 3, 5, 8 ], [ 3, 4, 7 ], [ 2 min read PHP Program to Check for Upper Triangular Matrix Given a Square Matrix, the task is to check whether the matrix is in upper triangular form or not. A square matrix is called upper triangular matrix if all the entries below the main diagonal are zero. Examples:  Input: mat = [ [1, 3, 5, 3], [0, 4, 6, 2], [0, 0, 2, 5], [0, 0, 0, 6]];Output: Matrix i 2 min read PHP Program for Identity Matrix Introduction to Identity Matrix : The dictionary definition of an Identity Matrix is a square matrix in which all the elements of the principal or main diagonal are 1's and all other elements are zeros. In the below image, every matrix is an Identity Matrix. In linear algebra, this is sometimes call 4 min read PHP Program to Check the Given Matrix is Sparse or Not A matrix is a two-dimensional data object having m rows and n columns, therefore a total of m*n values. If most of the values of a matrix are 0 then we say that the matrix is sparse. Consider a definition of Sparse where a matrix is considered sparse if the number of 0s is more than half of the elem 2 min read PHP Program for Markov matrix Given a m x n 2D matrix, check if it is a Markov Matrix.Markov Matrix: The matrix in which the sum of each row is equal to 1.Example of Markov MatrixExamples: Input :1 0 00.5 0 0.50 0 1Output : yesExplanation :Sum of each row results to 1, therefore it is a Markov Matrix.Input :1 0 00 0 21 0 0Output 2 min read PHP Program to Find Sum of All Matrix Elements Finding the sum of all elements in a matrix is a common operation in mathematical computations and programming. In PHP, this can be achieved using various approaches, including loops and array functions. In this article, we will explore different methods to calculate the sum of all elements in a mat 4 min read PHP Program to Print matrix in snake pattern Given an n x n matrix in the given matrix, you have to print the elements of the matrix in the snake pattern.Examples: Input: mat[][] = { {10, 20, 30, 40}, {15, 25, 35, 45}, {27, 29, 37, 48}, {32, 33, 39, 50}}; Output: 10 20 30 40 45 35 25 15 27 29 37 48 50 39 33 32 Input: mat[][] = { {1, 2, 3}, {4, 2 min read PHP Program to Count Sets of 1s and 0s in a Binary Matrix Given a N x M Binary Matrix, count the number of sets where a set can be formed one or more same values in a row or column. Examples: Input: [[ 1, 0, 1 ], [ 0, 1, 0 ]] Output: 8 Explanation: There are six one-element sets (three 1s and three 0s). There are two two - element sets, the first one consi 2 min read Like