diff --git a/src/Equation.java b/src/Equation.java
index 71d1907a79216f0c3d10a9a6bbf722eb84a2477c..e00e57ea6058a65b0bace48d177bc7b7c4ef9d80 100644
--- a/src/Equation.java
+++ b/src/Equation.java
@@ -169,6 +169,15 @@ public class Equation {
         return line;
     }
 
+    public int getNbLineMat() {
+        for (int i = 0; i < 7; i++) {
+            for (int j = 0; j < nbContraintes; j++) {
+
+            }
+        }
+        return 0;
+    }
+
     /**
      * Print les vecteurs et la matrice
      */
diff --git a/src/Main.java b/src/Main.java
index c2c14d58823378c6e6d4cce235400fb5c8617659..7dc3b8f462c3d64275254263e5d5748d493cd3b9 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -1,5 +1,6 @@
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.util.Arrays;
 import java.util.Scanner;
 import java.util.concurrent.TimeUnit;
 
@@ -71,16 +72,18 @@ public class Main {
             eq.printEq(line);
 
             // Tableau initiale
-            Simplex spx = new Simplex(4, 6);
+            Simplex spx = new Simplex(line+1, line + 3);
             spx.createMatEcart(eq);
             spx.printSimplex("Tableau");
+            //System.out.println(Arrays.deepToString(spx.getMatEcart()));
 
             // true = phase 1 membres de droite pas admissible | false = phase 2 membres de droite admissible
             if (spx.which_phase())
                 spx.tabAux();
-            else
-                spx.pivot(0);
-            spx.printSimplex("pivot");
+            else {
+                spx.pivot();
+                spx.printSimplex("pivot");
+            }
             sc.close();
         } catch (FileNotFoundException e) {
             throw new RuntimeException(e);
diff --git a/src/Simplex.java b/src/Simplex.java
index a7db097cd8f7833b63d1f7cd8e449212a97bf338..2d2b7971bbe76d78e72541f957b572a771e61297 100644
--- a/src/Simplex.java
+++ b/src/Simplex.java
@@ -3,6 +3,10 @@ public class Simplex {
     private final int x;
     private final int y;
 
+    public Double[][] getMatEcart() {
+        return matEcart;
+    }
+
     public void setMatEcartById(Double d, int x, int y) {
         matEcart[x][y] = d;
     }
@@ -39,7 +43,7 @@ public class Simplex {
         }
 
         // Membre de droite
-        for (int i = 0; i <= nbContraintes; i++)
+        for (int i = 0; i <= x-2; i++)
             setMatEcartById(eq.getRightVec().get(i), i, y-1);
 
         // Fonction obj
@@ -55,10 +59,10 @@ public class Simplex {
      * @return true = phase 1 | false = phase 2
      */
     boolean which_phase(){
-        boolean res = true;
+        boolean res = false;
         for (int i = 0; i < x; i++) {
-            if(signe(matEcart[i][y - 1]))
-                res = false;
+            if(!signe(matEcart[i][y - 1]))
+                res = true;
         }
         return res;
     }
@@ -66,15 +70,24 @@ public class Simplex {
 
     }
 
-    void pivot(int y) {
+    int getFirstNeg() {
+        for (int j = 0; j < this.y; j++) {
+            if(!signe(matEcart[x-1][j])) return j;
+        }
+        return -1;
+    }
+
+    void pivot() {
+        int firstNeg = getFirstNeg();
+        if (firstNeg == -1) return;
         boolean has_neg = false;
-        int id = ligneSortante(y);
-        double pivot = this.matEcart[id][y];
+        int id = ligneSortante(firstNeg);
+        double pivot = this.matEcart[id][firstNeg];
         for (int i = 0; i < this.y; i++) {
             this.matEcart[id][i] /= pivot;
         }
         for (int i = 0; i < this.x; i++) {
-            pivot = this.matEcart[i][y];
+            pivot = this.matEcart[i][firstNeg];
             for (int j = 0; j < this.y; j++) {
                 if (i != id) {
                     this.matEcart[i][j] -= pivot * this.matEcart[id][j];
@@ -84,9 +97,8 @@ public class Simplex {
         for (int j = 0; j < this.y; j++)
             if (!signe(this.matEcart[x - 1][j])) {
                 has_neg = true;
-                y = j;
             }
-        if (has_neg) pivot(y);
+        if (has_neg) pivot();
     }
 
 
diff --git a/src/input.txt b/src/input.txt
index 0bb445b34ba962d8a539fbc46738355fc040f3f5..0a54580ac62b754da6210f8cb49b8f356e367311 100644
--- a/src/input.txt
+++ b/src/input.txt
@@ -1,4 +1,5 @@
 max;8;9;
 2;5;<=;12;
 50;5;<=;150;
-5;50;<=;100;
\ No newline at end of file
+5;50;<=;100;
+1;2;<=;-1;
\ No newline at end of file