I have to say that your implementation of the backsub looks very bizarre. I have implemented back-substitution is several matrix numerical methods (PLU, QR, HH, Cholesky, SVD, etc.). I have checked them, and they look nothing like yours. Yours looks more like forward-substitution.
First, your bounds at line 14 and 16 are almost certainly wrong. You are definitely skipping elements. I think the bounds of these loops should both be j and not (j-1), because you want to visit the row/col before j, using (j-1) will skip that row/col. And that simply doesn't make sense.
Second, you are, oddly enough, traversing the array in a forward direction while doing back-substitution. You know, it's called back-substitution because you start at the end (last element of the diagonal) and work your way backwards. You are doing the opposite, and I cannot possibly understand how that could still work. If you look, for example, at this site , under the back-sub algorithm, you will notice how the elements are necessarily traversed backwards "(i=n,n-1,n-2,...1)" in the formula.
Finally, the fact that the diagonal is correctly inverted is quite meaningless, the diagonal is almost guaranteed to invert correct if you didn't screw up completely.
PS: Don't ask me to post my back-sub algorithm, it bears no more information than that in the formula at the link given above. And I presume that if you just wanted a ready made algorithm, you would have gotten one already from the numerous places you could get it off the internet.