I developed an algorithm to calculate the solution to equations by augmenting a matrix of coefficients with an identity matrix and then finding the inverse. So:
[A | I ] ---> [I | A-1 ]
Everything seems to work well at first. I seperate the rightmost coefficients from matrix A. Then i augment A with I. I use pivoting to make the largest number in the pivotal column the pivot element. I then want to use operations to reduce matrix A to an identity (which would cause I to be the inverse). HOWEVER, the operations don't work properly. Instead of being applied to the whole row, the subtraction only seems to work for the pivot column.
The code for that screwed up function is:
Code:
void row_ops(double a_ext[][10], int m, int n, int pivot_row)
{
int nn, j, i;
double factor;
nn = pivot_row;
pivot(a_ext, m, n, pivot_row);
factor = 1 / (a_ext[pivot_row][pivot_row]);
printf("\nTEST FACTOR: %f\n", factor);
for(j=0; j<(2*n); j++)
a_ext[pivot_row][j] = a_ext[pivot_row][j] * factor;
for(i=0; i<m; i++)
{
if(i != nn)
{
for(j=0; j<(2*n); j++)
a_ext[i][j] = a_ext[i][j] - (a_ext[i][pivot_row] * a_ext[pivot_row][j]);
}
else
continue;
}
mat_out(a_ext, m, (2*n), "a");
}
These are the operations i wish to be done. Row OP one is completed, but Row OP 2 is only applied to (in the following example,) number 2, or element [1][0]. LINK ---