Added adjoint and inverse functions

This commit is contained in:
2022-02-07 19:27:53 +00:00
parent d630b6fdb4
commit a643248aa5

View File

@@ -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