Scaled partial pivoting pseudocode doesn't seem to make sense

774 Views Asked by At

I got this pseudocode from my textbook for gaussian elimination with scaled partial pivoting:

for i=1 to n:
    L[i] = i
    smax = 0
    for j=1 to n:
        smax = max(smax, |A[i][j]|)
for k=1 to n-1:
    rmax = 0
    for i=k to n:
        r = |A[L[i]][k] / S[L[i]]|
        if (r > rmax):
            rmax = r
            j = i
    L[i] <-> L[k]
    for i=k+1 to n:
        xmult = A[L[i]][k] / A[L[k]][k]
        A[L[i]][k] = xmult
        for j=k+1 to n:
            A[L[i]][j] = A[L[i]][j] - xmult*A[L[k]][j]

I have two problems with this pseudocode, and both of them are in the two nested for-loops.

My first problem: Why am I assigning a value in the coefficient matrix to xmult (the number you multiply the pivot row by prior to subtraction)? I could be wrong, but this makes no sense whatsoever, mathematically. Doing so changes a single value in the equation, rendering the system inconsistent. Am I wrong?

My second problem: the int j in the nested loop where the forward elimination occurs starts at k+1, which is 2 at its lowest, but j needs to be 1 in order to zero-out the values in the first column. Since j is 2 at its lowest, how can the first column ever get modified during the forward elimination phase?

Bonus question that is to be answered if my two conclusions above are true: why bother publishing pseudo-code if it literally doesn't work?