Talk:Gauss-Jordan matrix inversion

From Rosetta Code

what's wrong (with REXX)?

My REXX algorithm works nicely most of the time. But sometimes it fails. E.g., with this matrix:

  3  1  8  9  6
  6  2  8 10  1
  5  7  2 10  3
  3  2  7  7  9
  3  5  6  1  1

The first elimination sets a.2.2=0 and how could this become 1 furtheron? Help! Thanks!! --Walter Pachl 08:52, 3 November 2018 (UTC)




I don't see your failure,   a.2.2   becomes zero and stays a zero.

Also, where it says "Main diagonal has all ones" isn't true.

With:

       a=  3 1 8 9 6     6 2 8 10 1     5 7 2 10 3     3 2 7 7 9     3 5 6 1 1 
Output:
show 1 The given matrix
  3  1  8  9  6  1  0  0  0  0
  6  2  8 10  1  0  1  0  0  0
  5  7  2 10  3  0  0  1  0  0
  3  2  7  7  9  0  0  0  1  0
  3  5  6  1  1  0  0  0  0  1

show 2 1
     3     1     8     9     6     1     0     0     0     0
     0     0    -4    -4 -11/2    -1   1/2     0     0     0
     0  16/5 -34/5    -3 -21/5    -1     0   3/5     0     0
     0     1    -1    -2     3    -1     0     0     1     0
     0     4    -2    -8    -5    -1     0     0     0     1

show 2 2
     3     1     8     9     6     1     0     0     0     0
     0     0    -4    -4 -11/2    -1   1/2     0     0     0
     0     0     4     4  11/2     1  -1/2     0     0     0
     0     0     4     4  11/2     1  -1/2     0     0     0
     0     0     4     4  11/2     1  -1/2     0     0     0

show 2 3
     3     1     8     9     6     1     0     0     0     0
     0     0    -4    -4 -11/2    -1   1/2     0     0     0
     0     0     4     4  11/2     1  -1/2     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0

show 2 4
     3     1     8     9     6     1     0     0     0     0
     0     0    -4    -4 -11/2    -1   1/2     0     0     0
     0     0     4     4  11/2     1  -1/2     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0

Lower part has all zeros

show 3
     3     1     8     9     6     1     0     0     0     0
     0     0    -4    -4 -11/2    -1   1/2     0     0     0
     0     0     4     4  11/2     1  -1/2     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0

show 4 5
     3     1     8     9     6     1     0     0     0     0
     0     0    -4    -4 -11/2    -1   1/2     0     0     0
     0     0     4     4  11/2     1  -1/2     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0

show 4 4
     3     1     8     9     6     1     0     0     0     0
     0     0    -4    -4 -11/2    -1   1/2     0     0     0
     0     0     4     4  11/2     1  -1/2     0     0     0
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0

show 4 3
    3    1    0    1   -5   -1    1    0    0    0
    0    0    0    0    0    0    0    0    0    0
    0    0    4    4 11/2    1 -1/2    0    0    0
    0    0    0    0    0    0    0    0    0    0
    0    0    0    0    0    0    0    0    0    0

show 4 2
    3    1    0    1   -5   -1    1    0    0    0
    0    0    0    0    0    0    0    0    0    0
    0    0    4    4 11/2    1 -1/2    0    0    0
    0    0    0    0    0    0    0    0    0    0
    0    0    0    0    0    0    0    0    0    0

Upper half has all zeros

show 5
    1  1/3    0  1/3 -5/3 -1/3  1/3    0    0    0
    0    0    0    0    0    0    0    0    0    0
    0    0    1    1 11/8  1/4 -1/8    0    0    0
    0    0    0    0    0    0    0    0    0    0
    0    0    0    0    0    0    0    0    0    0

Main diagonal has all ones

show 6 The inverse matrix
 -1/3  1/3    0    0    0
    0    0    0    0    0
  1/4 -1/8    0    0    0
    0    0    0    0    0
    0    0    0    0    0

The product of input and inverse matrix
      1    1/3      0    1/3   -5/3
      0      0      0      0      0
      0      0      1      1   11/8
      0      0      0      0      0
      0      0      0      0      0

I would add the statement   (at least for now):

  signal on noValue

as you have a piece of dead code (possibly a debugging leftover?):

  ss=sigl 


I used three different REXX interpreters, all yielded the same results.

-- Gerard Schildberger (talk) 09:25, 3 November 2018 (UTC)