for(count = 0; count < max; count ++)
{
for (row=(count+1); row < max; row++)
{
for(column = 0; column < max; column ++)
{
double t = matrix[row][count]/matrix[count][count];
matrix[row][column] = (matrix[row][column] - (t*matrix[count][column]));
}
}
}
This is my code for the Gaussian elimination process, all variable were declared previously. The original matrix is:
1.4 2.1 2.1 7.4 9.6
1.6 1.5 1.1 0.7 5.0
3.8 8.0 9.6 5.4 8.8
4.6 8.2 8.4 0.4 8.0
2.6 2.9 0.1 9.6 7.7
The output I am getting is:
I perform a row swap so the matrix now looks like:
4.6 8.2 8.4 0.4 8
3.8 8 9.6 5.4 8.8
1.4 2.1 2.1 7.4 9.6
2.6 2.9 0.1 9.6 7.7
1.6 1.5 1.1 0.7 5
The output I am getting is:
4.6 8.2 8.4 0.4 8
0 8 9.6 5.4 8.8
0 0 2.1 7.4 9.6
0 0 0 9.6 7.7
0 0 0 0 5
As can be seen, the process is working partially, eliminating the leading terms in each row. However, it is not subtracting the the remaining terms. e.g. matrix[1][1] in the original matrix, after the row swap = 8 and matrix[1][1] after gaussian elimination is still 8.
I was wondering if anyone would know what my problem is as i cannot find it.
t
is inside the column loop but it only works if before the column loop. It isn't just an efficiency problem because you modify the inputs tot
when you don't wantt
to change. – JSF