[Python] Gauss-Jordan Elimination in python

Discussão em 'Python' iniciado por Stack, Março 20, 2025.

  1. Stack

    Stack Membro Participativo

    I am working on code to do Gauss-Jordan elimination in python. My directions are as follows:

    def gauss_jordan(A):
    for each row k do
    i* <- argmax_{k<i<n} |A_{ik}|
    if A_{i*k} = 0 then
    Matrix is not invertible
    end if
    Swap rows k and i*
    for each row j below k (i.e. j = k + 1,...,n) do
    f = A_{jk}/A_{kk}
    Aj = Aj - fA_{k}
    end for
    end for
    for each row k = n,..., 1 (i.e. in reverse) do
    A_{k} = A_{k}=A_{kk}
    for each row j above k (i.e. j = k -1,..., 1) do
    f = A_{jk}/A_{kk}
    Aj = A_{j}-fA_{k}
    end for
    end for


    So far I have:

    def gauss_jordan(A):
    (h, w) = (len(A), len(A[0]))
    for y in range(0,h):
    for pivot in range(y, h):
    if A[pivot][y].value % 2 != 0:
    break
    else:
    return None


    Is this the correct start? I feel quite lost in where to go next. The input will be a Numpy array. Any thoughts are much appreciated!

    Continue reading...

Compartilhe esta Página