Hello all,

I'm quite new to programming, however I do have an assignment I've to do. Now the assignment itself is using the Jacobi iteration method to solve for 15 unknowns. I figured the best way to do it would be using matrices, as that kinda seemed simpler. Now, the problem is that, if A is a matrix that is the sum of U, L and D, where U and L are the lower and upper triangular parts of the matrix, and D is the diagonal part of the matrix, how do I separate U and L from the rest?

I got the diagonal of the matrix fine, but when I try to run a loop for separating U and L, it just doesn't give the correct answers. I know this is probably a very badly written loop, so I apologize for the 'newbiness' of it beforehand

P.S: It DOES give the correct answer for the Lower part, just not the upper part.

P.P.S: I didn't mention that the matrices would all be square matrices, as to solve for linear equations you'd need to have that and such.. But hey just in case someone asks.

By the way, I'm right now trying the loop for 2x2 matrix, then I'll move on to the larger ones.

Code:for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { k = i; if (i == j) { if (i != 0) { while (k > 0) { k--; U[k][j] = A[k][j]; } } k = j; if (i != n-1) { while (k < n-1) { k++; L[k][j] = A[k][j]; } } } } }