Added adjoint and inverse functions
This commit is contained in:
@@ -680,6 +680,9 @@ public class IntegerMatrix{
|
|||||||
//Return the determinant
|
//Return the determinant
|
||||||
return det;
|
return det;
|
||||||
}
|
}
|
||||||
|
public IntegerMatrix cof(){
|
||||||
|
return cofactor();
|
||||||
|
}
|
||||||
public IntegerMatrix cofactor(){
|
public IntegerMatrix cofactor(){
|
||||||
//Make sure the matrix is square
|
//Make sure the matrix is square
|
||||||
if(!isSquare()){
|
if(!isSquare()){
|
||||||
@@ -706,6 +709,27 @@ public class IntegerMatrix{
|
|||||||
//Return the new matrix
|
//Return the new matrix
|
||||||
return new IntegerMatrix(newGrid);
|
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
|
//Object funtions
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user