Skip to content

Commit

Permalink
Update reduced-row-echelon-form.java
Browse files Browse the repository at this point in the history
Solution for this issue: reduced-row-echelon-form.java returns wrong result acmeism#13
  • Loading branch information
enivill committed Dec 29, 2020
1 parent 9ad63ea commit c7bfdba
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions Task/Reduced-row-echelon-form/Java/reduced-row-echelon-form.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,19 @@ public boolean isRowZeroes(Coordinate a) {
}

public Coordinate findPivot(Coordinate a) {
int first_row = a.row;

Coordinate pivot = new Coordinate(a.row, a.col);
Coordinate current = new Coordinate(a.row, a.col);

for (int i = a.row; i < (numRows - first_row); i++) {
for (int i = a.row; i < (numRows); i++) {
current.row = i;
if (getCoordinate(current).doubleValue() == 1.0) {
Interchange(current, a);
}
}

current.row = a.row;
for (int i = current.row; i < (numRows - first_row); i++) {
for (int i = current.row; i < (numRows); i++) {
current.row = i;
if (getCoordinate(current).doubleValue() != 0) {
pivot.row = i;
Expand Down Expand Up @@ -256,5 +256,18 @@ public static void main (String[] args) {
System.out.println("before\n" + a.toString() + "\n");
a.RREF();
System.out.println("after\n" + a.toString() + "\n");

double[][] matrix_5 = {
{1,0,-1,0},
{0,1,0,-1},
{1,-2,-1,0},
{-1,0,3,1}
};


Matrix b = new Matrix(matrix_5);
System.out.println("before\n" + b.toString() + "\n");
b.RREF();
System.out.println("after\n" + b.toString() + "\n");
}
}

0 comments on commit c7bfdba

Please sign in to comment.