PHP Program to Check Involutory Matrix Last Updated : 22 Jul, 2024 Summarize Comments Improve Suggest changes Share 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 K kartik Follow Improve Article Tags : PHP Similar Reads PHP Program to Find the Maximum Element in a Matrix Given a matrix, the task is to find the maximum element of the matrix (arrays of arrays) in PHP. Finding the maximum element in a matrix is a common task that involves iterating through all the elements of the matrix and keeping track of the largest value found. Example: Input: matrix = [ [1, 2, 3], 4 min read How to Check an Array is Sorted or Not in PHP? Given an array, the task is to check whether the given array is sorted or not. Arrays are often used to store and manipulate data. One common task is to check if an array is sorted in ascending or descending order. This article will explore different approaches to determine whether an array is sorte 3 min read How to Calculate Determinant of a Matrix in PHP? Given a Matrix of size M*N, where N and M is an Integer, we need to Calculate calculate of a Matrix in PHP. Example: Input: [[1, 2],[2, 3]]Output: 6Explanation: (1*3)-(2*2)= 6-4= 2 There are several ways to find the determinant of the matrix in PHP which are as follows: Table of Content Using Recurs 4 min read How to do syntax checking using PHP ? Syntax checking is one of the most important tasks in programming. Our compiler checks our code and shows relevant errors if there is any in the code i.e. compile time, run time, syntax, etc. We can do the same thing i.e. syntax checking in PHP. In this article, we are going to learn how we can do s 2 min read How to Access and Print Matrix Element at Specific Position in PHP ? Accessing and printing elements at specific positions within a matrix is a fundamental operation in PHP when dealing with two-dimensional arrays. A matrix in PHP can be represented as an array of arrays, where each sub-array represents a row in the matrix. This article explores various approaches to 3 min read Like