Need help understanding the following MATLAB operations for Gaussian Elimination with Partial Pivoting?

156 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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.