Skip to content

Instantly share code, notes, and snippets.

@x0nu11byt3
Created June 4, 2022 04:30
Show Gist options
  • Save x0nu11byt3/440cd41bf9b6edb65ab8f2bd6784df58 to your computer and use it in GitHub Desktop.
Save x0nu11byt3/440cd41bf9b6edb65ab8f2bd6784df58 to your computer and use it in GitHub Desktop.
A simple implementation of the algorithm pure MethodGaussJordan Is a linear algebra algorithm used to determine the solutions of a system of linear equations Previous requirements for handling complex arrays you need to install numpy
#!/usr/bin/env python3
import numpy as np
class error(Exception): pass
class GaussJordan():
def __init__(self,x,y):
self.m = x
self.n = y
self.matrix = [[ 0 for i in range(x)] for j in range(y)]
self.np_mtx_tmp = np.zeros(1)
self.np_mtx = np.zeros(1)
def __getitem__(self, x,y):
return self.np_mtx[x][y]
def __setitem__(self,x,y, data):
self.np_mtx[x][y] = data
def __repr__(self):
return 'GaussJordan({})'.format(self.np_mtx_tmp)
def set_matrix(self):
for i in range(self.n):
for j in range(self.m):
self.matrix[i][j] = int(input("Enter a number:"))
self.np_mtx = self.np_mtx_tmp = np.squeeze(np.asarray(self.matrix))
def get_index(self):
mini = self.np_mtx_tmp[0][0]
for i in range(self.n):
for j in range(self.m):
if j == 0:
if i != 0:
if self.np_mtx_tmp[i][j] == 1:
response = i
break
else:
if mini > self.np_mtx_tmp[i][j]:
mini = self.np_mtx_tmp[i][j]
response = mini
return response
def swap_matrix(self,x,y):
l = []
k = []
for i in range(self.m):
l.append(self.np_mtx[x][i])
k.append(self.np_mtx[y][i])
for j in range(self.m):
self.np_mtx[y][j] = l[j]
self.np_mtx[x][j] = k[j]
def divizion_matrix(self,x,m):
for i in range(self.m):
self.np_mtx[x][i] = self.np_mtx[x][i] / self.np_mtx[x][i]
def fill_rows(self,x):
for j in range(self.n):
self.np_mtx[0][j] = self.np_mtx_tmp[x][j]
# substract
# add
# divizion
# multiplication
# make 0 top triangle
# make 0 down triangle
def main():
print('Welcome a method Gauss-Jordan')
#pass
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment