1

Does first step in algorithm should look like following?

// find the element with largest absolute value in col p and below row p-1

So instead of all col p just part of it.

Algorithm:

  for p = 1 to n do
    // find the element with largest absolute value in col p <-first step
    // if max is zero, stop!
    // if max element not in row p, swap rows
    // set pivot element to 1
    multiply row p by 1/A[p][p]
    // clear lower column entries
    for r = p+1 to n do
        subtract row p times A[r,p] from current row,
        so that element in pivot column becomes 0
        // do backwards substitution
  for row = n-1 to 1
      for col = row+1 to n
          // subtract out known quantities
          b[row] = b[row] - A[row][col]*b[col]

EDIT:

We have matrix A. Algorithm starts from first step with p=3. My question is: should I choose largest element from {5,3,2,-1} (all elements od col p) or {2,-1} (only elements from col p which are below row p-1)?

[1 2 5 3]

[0 1 3 4]

[0 0 2 2] = A

[0 0 -1 1]

ldurniat
  • 1,687
  • 2
  • 9
  • 16
  • 1
    "Find (something that isn't zero) in column `p` below row `p-1`". Yes, that's a step in Gaussian elimination. Is that your actual question? Or are you wanting to figure out if your algorithm implements it correctly? (In which case, you'd want to implement the commented lines.) – Teepeemm Nov 02 '16 at 19:59
  • I know all steps of Gaussian elimination. Because I want implement algorithm as program it need some trick due to performace issue. So that's why algorithm pick largest element from col p. I'm not sure it is correct because in this case algorithm could swap rows with pivot element choose in previous step. I add more specific question. English is not my native language so sorry for that:) – ldurniat Nov 02 '16 at 20:56

1 Answers1

0

Yes, this step is correct. The first p - 1 rows already have pivot variables in them. The new pivot must in a different row according to the Gaussian elimination algorithm.

A simple example:

If you have a 2x2 matrix, the first row has already been processed and the matrix looks like

[1, 2] 
[0, 1]

you clearly need to pick the (2, 2) element as the pivot for the second column, not (1, 2).

kraskevich
  • 18,368
  • 4
  • 33
  • 45