Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determinant is wrong for matrix n > 3 #160

Open
plouffed opened this issue Apr 20, 2021 · 0 comments · May be fixed by #161
Open

Determinant is wrong for matrix n > 3 #160

plouffed opened this issue Apr 20, 2021 · 0 comments · May be fixed by #161

Comments

@plouffed
Copy link

From the source code, we can see that implemented method to calculate the determinant for dimension n>2 is

  for (col = 0; col < numCol; col++) {
      diagLeft = m[0][col];
      diagRight = m[0][col];
  
      for (row = 1; row < numRow; row++) {
        diagRight *= m[row][(((col + row) % numCol) + numCol) % numCol];
        diagLeft *= m[row][(((col - row) % numCol) + numCol) % numCol];
      }
  
      det += diagRight - diagLeft;
    }

It is pretty clear that this code represents Leibniz formula for a 3x3 matrix (according to wikipedia).

So it means that this piece of code cannot compute determinant of matrix n > 3.

For exemple:

    let m4x4 = [[2,3,4,6],[1,3,-2,4],[5,2,1,3],[1,5,2,-3]];
    numbers.matrix.determinant(m4x4) // expected 825, gives 534

    let m5x5 = [[2,2,3,4,6],[1,3,3,-2,4],[5,4,2,1,3],[1,4,2,0,3],[9,4,8,9,10]];
    numbers.matrix.determinant(m5x5); // expected 793, gives 2187
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant