Last active
January 12, 2025 06:45
-
-
Save ssghost/5c7c5ba8db2cdf6a88066403d1438a63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gauss_elim(m: List[List[float]], eps: float = 1.0/(10**10)) -> bool: | |
(h, w) = (len(m), len(m[0])) | |
for i in range(h): | |
maxrow = i | |
for j in range(i+1, h): | |
if abs(m[j][i]) > abs(m[maxrow][i]): | |
maxrow = j | |
(m[i], m[maxrow]) = (m[maxrow], m[i]) | |
if abs(m[i][i]) <= eps: | |
return False | |
for j in range(i+1, h): | |
c = m[j][i] / m[i][i] | |
for x in range(i, w): | |
m[j][x] -= m[i][x] * c | |
for i in range(h-1, 0-1, -1): | |
c = m[i][i] | |
for j in range(0,i): | |
for x in range(w-1, i-1, -1): | |
m[j][x] -= m[i][x] * m[j][i] / c | |
m[i][i] /= c | |
for x in range(h, w): | |
m[i][x] /= c | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment