Created
June 11, 2022 04:10
-
-
Save nadhirxz/f083e0f556f921824a1a7c0ac3d9716c to your computer and use it in GitHub Desktop.
This file contains 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
import numpy as np | |
import sys | |
def gauss(a): | |
n = len(a) | |
m = len(a[0]) | |
for i in range(n): | |
if a[i][i] == 0.0: | |
sys.exit('Divide by zero detected!') | |
for j in range(i+1, n): | |
ratio = a[j][i]/a[i][i] | |
for k in range(m): | |
a[j][k] = a[j][k] - ratio * a[i][k] | |
for i in range(n-1, -1, -1): | |
if a[i][i] == 0.0: | |
sys.exit('Divide by zero detected!') | |
for j in range(i-1, -1, -1): | |
ratio = a[j][i]/a[i][i] | |
for k in range(m): | |
a[j][k] = a[j][k] - ratio * a[i][k] | |
for i in range(n): | |
for j in range(m): | |
a[i][j] = a[i][j] / a[i][i] | |
return a | |
size = (3,5) | |
a = np.random.randint(100, size=(3,5)) | |
print(a) | |
print(gauss(a)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment