mirror of
https://bitbucket.org/Mattrixwv/matrix.git
synced 2025-12-06 23:13:57 -05:00
Added adjoint and inverse functions
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user