(*To Write Mathematica Code For Inverse of a Matrix, First of all you have to know about the condition for inverting a matrix. First Condition is Matrix should be a Square Matrix and Second is Matrix Should be a Non Singular Matrix. Here we will declare matrix enteries at first and then we will use nested if condition to check matrix is square and Non singular and then print result.*)
(* Input matrix entries *)
matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
(* Check if the matrix is square *)
If[SquareMatrixQ[matrix],
(* If the matrix is square, check if its determinant is non-zero *)
If[Det[matrix] != 0,
(* If the determinant is non-zero, print a message indicating that the matrix is square and non-singular *)
Print["The matrix is square and its determinant is non-zero."];
(* Print a message indicating that we're about to display the inverse of the matrix *)
Print["The inverse of the matrix is:"];
(* Print the inverse of the matrix *)
Print[Inverse[matrix]],
(* If the determinant is zero, print a message indicating that the matrix is square but singular *)
Print["The matrix is square but its determinant is zero."]
],
(* If the matrix is not square, print a message indicating that it's not square *)
Print["The matrix is not square."]
]