Skip to content

Instantly share code, notes, and snippets.

@felipecruz
Created November 13, 2016 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipecruz/44d9d0d5b7b44835b2f30311bfd17211 to your computer and use it in GitHub Desktop.
Save felipecruz/44d9d0d5b7b44835b2f30311bfd17211 to your computer and use it in GitHub Desktop.
func MatrixLUDecomposition(matrix Matrix) Matrix {
columns := matrix.cols()
rows := matrix.rows()
for i := 0; i < columns-1; i++ {
val, pivot_index := PivotIndex(matrix, i, i)
MatrixExchangeRows(matrix, i, pivot_index)
for j := i + 1; j < rows; j++ {
multiplier := -matrix.at(j, i) / val
MatrixScaleAndSumRows(matrix, i, j, multiplier)
matrix.set(j, i, -(multiplier))
}
}
return matrix
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment