Gaussian elimination for lower triangular matrix

969 Views Asked by At

I have got a a trouble with Gaussian elimination for lower triangular matrix, I can't imagine how the loops should work right here. I tried to run loop backwards, but it didn't help. For now all I've got is Gaussian elimination for upper triangular matrix.

For[k = 1, k <= size - 1, k++,
     For[i = k + 1, i <= size, i++,
      If[tab[[k]][[k]] != 0,
       help = tab[[i]][[k]]/tab[[k]][[k]];
       For[j = k, j <= size, j++,
        tab[[i]][[j]] = tab[[i]][[j]] - help*tab[[k]][[j]];
        identity[[i]][[j]] = identity[[i]][[j]] - help*tab[[k]][[j]]
        ]
       ]
      ]
     ]

Can someone help me please?

@edit

I made loops like that

For[k = size, k > 1, k--,
 For[i = k - 1, i >= 1, i--,

And it seems like it works, but now I've got a problem, because these two loops doesn't give invertible matrix.

Example Matrix:

[ 3 4 2 ]
[ 5 5 5 ]
[ 1 5 3 ]

Output for upper-diagonal

[3   4   2  ]
[0 -5/3 5/3 ]
[0   0   6  ] 

Output for Identity-Matrix

  [1    0      0  ]
  [-5 -17/3 -10/3 ]  
  [-1   -5    -4  ]

And now, when I run loop for lower-diagonal, the output for it is not correct. It doesn't divide the main diagonal

1

There are 1 best solutions below

0
On

Well, actually I found the problem, but I don't know how could I solve that - upper-triangular-matrix-loop works fine, but the problem is with lower triangular one, it doesn't divide elements on diagonal.