Can anyone help me with my Gaussian Elimination algorithm?
why is my Gaussian Elimination algorithm doesn't work, especially the second part, I made a lot more details on why I think it doesn't here https://scicomp.stackexchange.com/questions/45561/gaussian-elimination-2nd-part but I can't get it completely. can anyone help?
import numpy as np
A=np.array([[4,8,12],[3,8,13],[2,9,18]])
b=np.array([4,5,11])
def Gauss_Elimination(A,b):
n = np.shape(A)[0]
# 1st Part
for k in range(n):
pivot_element=A[k,k]
# if pivot_element==0: ### I'll deal with this condition later
for j in range(k+1,n):
b[j]=b[j]-(A[j,k]/pivot_element)*b[k]
A[j,:]=A[j,:]-(A[j,k]/pivot_element)*A[k,:]
# 2nd Part
x = np.zeros(n)
x[-1]=b[-1]/A[-1,-1]
for i in range(n-2,-1,-1):
x[i]=(b[i]-np.sum(x[i+1]-A[i,i+1]))/A[i,i]
return A,b, x # not necessary since it's call by reference
Gauss_Elimination(A,b)
print(A,'\n',b)