MATLAB code for Guassian Elimination with Partial Pivoting
I'm having trouble understanding the following segment:
for j = 1:n-1
[m,k] = max (abs(A(j:n,j))
k = k+j-1
if k ~= j
A([k,j],j:n+1) = A([j,k],j:n+1)
end
I'm uncertain about why k is set to be equal to k+j-1. I don't see how that helps to determine if the rows below the pivot element need to be swapped.
The first two lines are the search of the pivot, absolute maximum of the first rows.
$k$ is the pivot.
The two last lines swap $k$-th and $j$-th lines as part of the Gaussian elimination algorithm.