Gauss Elimination With Partial Pivoting In Python | Numerical Methods

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ต.ค. 2024

ความคิดเห็น • 8

  • @samramzi4639
    @samramzi4639 10 หลายเดือนก่อน +13

    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

  • @shimadabr
    @shimadabr ปีที่แล้ว +1

    That's one of the best explanations and implementations i could find of Gauss Elimination. Thanks a lot!

  • @patrickegry4237
    @patrickegry4237 ปีที่แล้ว +1

    Thank you so much for this! Keep up with the content, it is tremendously useful for a lot of students.

  • @thatlilvoice
    @thatlilvoice ปีที่แล้ว +1

    You're saving my life here bud.

    • @StudySessionYT
      @StudySessionYT  ปีที่แล้ว +1

      Thanks for watching! Happy to hear the videos are helpful!

  • @shimadabr
    @shimadabr ปีที่แล้ว

    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).

  • @katheodo
    @katheodo ปีที่แล้ว

    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.