diff --git a/src/main/java/com/mattrixwv/matrix/IntegerMatrix.java b/src/main/java/com/mattrixwv/matrix/IntegerMatrix.java index 205b695..a77eb76 100644 --- a/src/main/java/com/mattrixwv/matrix/IntegerMatrix.java +++ b/src/main/java/com/mattrixwv/matrix/IntegerMatrix.java @@ -680,6 +680,9 @@ public class IntegerMatrix{ //Return the determinant return det; } + public IntegerMatrix cof(){ + return cofactor(); + } public IntegerMatrix cofactor(){ //Make sure the matrix is square if(!isSquare()){ @@ -706,6 +709,27 @@ public class IntegerMatrix{ //Return the new matrix return new IntegerMatrix(newGrid); } + public IntegerMatrix adj(){ + return adjoint(); + } + public IntegerMatrix adjoint(){ + return cofactor().transpose(); + } + public IntegerMatrix inverse(){ + //Make sure the matrix is square + if(!isSquare()){ + throw new InvalidGeometryException("A matrix must be square for it to have an inverse"); + } + + //Make sure the determinant is not 0 + int determinant = determinant(); + if(determinant == 0){ + throw new InvalidScalarException("The determinant cannot be 0"); + } + + //Return the new matrix + return adjoint().multiply(1 / determinant); + } //Object funtions @Override