Skip to content
Snippets Groups Projects
Commit 87bac1a3 authored by fefe's avatar fefe
Browse files

Inv function tested ! Works fine Youhhhhou ! Solve function done but not tested yet !

parent c458dcf4
Branches
Tags
No related merge requests found
...@@ -105,7 +105,10 @@ public class Matrix { ...@@ -105,7 +105,10 @@ public class Matrix {
} }
public Matrix inv() { public Matrix inv() {
throw new UnsupportedOperationException("This feature isn't implemented yet"); Matrix newMat = this.adjugate();
newMat = newMat.mul(1.0/this.det());
return newMat;
} }
public double det() { public double det() {
...@@ -202,7 +205,16 @@ public class Matrix { ...@@ -202,7 +205,16 @@ public class Matrix {
throw new UnsupportedOperationException("This feature isn't implemented yet"); throw new UnsupportedOperationException("This feature isn't implemented yet");
} }
public static Vector solve(Matrix m, Vector b) { public static Vector solve(Matrix m, Vector b) {
throw new UnsupportedOperationException("This feature isn't implemented yet"); Matrix newMat = m.inv();
List<Double> newLst = new ArrayList<>();
for (int i = 0; i < newMat.nbCols(); i++){
double tot = 0.0;
for (int y = 0; y < b.len(); y++){
tot += newMat.cols().get(y).get(i) * b.get(i);
}
newLst.add(tot);
}
return Vector.of(newLst);
} }
} }
......
...@@ -240,4 +240,19 @@ class VectorTest { ...@@ -240,4 +240,19 @@ class VectorTest {
return (double)i + j; return (double)i + j;
})); }));
} }
@Test
void matrixInv() {
List<Vector> lstVec = new ArrayList<>();
lstVec.add(Vector.of(1.0, 1.0, 2.0));
lstVec.add(Vector.of(1.0, 2.0, 1.0));
lstVec.add(Vector.of(2.0, 1.0, 1.0));
Matrix m = Matrix.of(lstVec);
lstVec = new ArrayList<>();
lstVec.add(Vector.of(-0.25, -0.25, 0.75));
lstVec.add(Vector.of(-0.25, 0.75, -0.25));
lstVec.add(Vector.of(0.75, -0.25, -0.25));
assertEquals(m.inv(), Matrix.of(lstVec));
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment