From a31926dac3176384835b3557846b7cd63a539edd Mon Sep 17 00:00:00 2001 From: fefe <hofer.francois.01@gmail.com> Date: Thu, 9 Jan 2020 23:21:33 +0100 Subject: [PATCH] Few fonctions made like .det() -> already tested , mul -> tested, creation function -> tested, info function tested --- src/main/java/ch/hepia/numeric/Matrix.java | 6 +++--- src/test/java/ch/hepia/numeric/AppTest.java | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/hepia/numeric/Matrix.java b/src/main/java/ch/hepia/numeric/Matrix.java index 30b9c0a..3809e96 100644 --- a/src/main/java/ch/hepia/numeric/Matrix.java +++ b/src/main/java/ch/hepia/numeric/Matrix.java @@ -120,11 +120,11 @@ public class Matrix { } else { double tot = 0.0; for (int i = 0; i < this.nbCols();i++){ - if (i+this.nbCols() % 2 == 0){ - tot += this.removed(i, 0).mul(this.get(i, 0)).det(); + if (i % 2 == 0){ + tot += this.removed(i, 0).det() * this.get(i,0); } else{ - tot -= this.removed(i, 0).mul(this.get(i, 0)).det(); + tot += this.removed(i, 0).det() * this.get(i,0) * (-1.0); } } return tot; diff --git a/src/test/java/ch/hepia/numeric/AppTest.java b/src/test/java/ch/hepia/numeric/AppTest.java index d755632..7c6b60a 100644 --- a/src/test/java/ch/hepia/numeric/AppTest.java +++ b/src/test/java/ch/hepia/numeric/AppTest.java @@ -207,7 +207,11 @@ class VectorTest { lstVec.add(Vector.of(3.0,6.0,9.0)); Matrix mat = Matrix.of(lstVec); assertEquals(mat.det(), 0.0); - - + lstVec = new ArrayList<>(); + lstVec.add(Vector.of(1.0, 5.0, 9.0, 13.0)); + lstVec.add(Vector.of(2.0, 6.0, 10.0, 14.0)); + lstVec.add(Vector.of(3.0, 7.0, 11.0, 15.0)); + lstVec.add(Vector.of(4.0,8.0,12.0, 16.0)); + assertEquals(Matrix.of(lstVec).det(), 0.0); } } -- GitLab