For some reason my x0 = 0 when i tested your example. I gets to 0 exactly when k = 0 and j = 2. x = x - augmented_matriz[k][j] * x[j] turns into x = 1.5000000000000004 - 1 * 1.5000000000000004, so x = 0. I'm wondering if it's due to a minor floating point precision error that is causing the number to be unrepresentable (as e-16 is on the verge of underflow).
for some reason my last diagonal element isn't zero (in the A -matrix , as in Ax=b). I'm wandering if it's because i-variable stops before it reaches the n-th row.
import numpy as np
def gauss_elimination(a_matrix,b_matrix):
#adding some contingencies to prevent future problems
if a_matrix.shape[0] != a_matrix.shape[1]:
print("ERROR: Squarematrix not given!")
return
if b_matrix.shape[1] > 1 or b_matrix.shape[0] != a_matrix.shape[0]:
print("ERROR: Constant vector incorrectly sized")
return
#initialization of nexessary variables
n=len(b_matrix)
m=n-1
i=0
j=i-1
x=np.zeros(n)
new_line="/n"
#create our augmented matrix throug Numpys concatenate feature
augmented_matrix = np.concatenate((a_matrix, b_matrix,), axis=1, dtype=float)
print(f"the initial augmented matrix is: {new_line}{augmented_matrix}")
print("solving for the upper-triangular matrix:")
#applying gauss elimination:
while i
That's one of the best explanations and implementations i could find of Gauss Elimination. Thanks a lot!
Thank you so much for this! Keep up with the content, it is tremendously useful for a lot of students.
You're saving my life here bud.
Thanks for watching! Happy to hear the videos are helpful!
For some reason my x0 = 0 when i tested your example. I gets to 0 exactly when k = 0 and j = 2. x = x - augmented_matriz[k][j] * x[j] turns into x = 1.5000000000000004 - 1 * 1.5000000000000004, so x = 0.
I'm wondering if it's due to a minor floating point precision error that is causing the number to be unrepresentable (as e-16 is on the verge of underflow).
for some reason my last diagonal element isn't zero (in the A -matrix , as in Ax=b).
I'm wandering if it's because i-variable stops before it reaches the n-th row.