I am have a multi-dimensional array that needs to be resolved, to solve for the unknown values (x1,x2,x3,..). In this multi-dimensional array, my array size in the i and j coordinate are different; B[n][n+1]. I know this Basic C, Gauss Jordan Method to solve for the unknown, is incorrect and would like someone to point in how to modify it..
This code is accurate for an Array with the same n values only; eg. A[n][n].
//Computation to solve
for(j=0; j<=n; j++)
{
for(i=0; i<=n; i++)
{
if(i!=j)
{
c=B[i][j]/B[j][j];
for(k=0;k<=n+1;k++)
{
B[i][k] = B[i][k] - c*B[j][k];
}
}
}
}
//Print Solution
printf("\nThe solution is:\n");
for(i=0; i<=n; i++)
{
x[i]=B[i][n+1]/B[i][i];
printf("\n x%d=%.3f\n",i,x[i]);
}
An example would be if my n=2. The array that i would want to solve is B[2][3].
0 -20 0 -1
0 30 -10 0
0 -10 10 1
The output of this code is
x1= -inf
x2=0.050
x3=0.000
The correct output should be
x1=0.00
x2=0.05
x3=0.15