I apologize if I gave the impression that I was asking for someone else to do my assignment for me, which I sincerely did not. I do have the code itself, however, as the loop I previously mentioned doesn't work, neither does the algorithm itself. I know that the code is pretty ugly in itself, and I do apologize for it. Once I get the algorithm working, I will split it into a few functions (e.g a function for matrix multiplication, as it occurs way too often in the main for now).

As said, right now the code is more or less a draft of what it should be.

P.S.: I am using an example from wikipedia which I have checked for errors using other methods and found that it is a correct example/solution.

P.P.S.: I've already worked the problem out on paper, but for some reason my loops don't exactly work as I imagined the would

HERE is the link for it.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int n = 2;
int i, j, k, l;
float A[n][n], B[n], C[n], D[n][n], Dinv[n][n], L[n][n], R[n][n], T[n][n], U[n][n], Y[n];
float X[100], error = 1e-5;
int x0 = 1;
//Every member of the arrays initialized to zero
for (i = 0; i <= n-1; i++)
{
for (j = 0; j <= n-1; j++)
{
A[i][j] = 0.0;
D[i][j] = 0.0;
Dinv[i][j] = 0.0;
L[i][j] = 0.0;
R[i][j] = 0.0;
T[i][j] = 0.0;
U[i][j] = 0.0;
}
}
for (i = 0; i <= n-1; i++)
{
B[i] = 0;
C[i] = 0;
Y[i] = 0;
}
X[0] = x0;
X[1] = x0;
A[0][0] = 2;
A[0][1] = 1;
A[1][0] = 5;
A[1][1] = 7;
B[0] = 11;
B[1] = 13;
for (i = 0; i < n; i++)
{
D[i][i] = A[i][i];
Dinv[i][i] = 1/D[i][i];
}
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 = i;
if (i != n-1)
{
while (k < n-1)
{
k++;
L[k][j] = A[k][j];
}
}
}
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
R[i][j] = L[i][j] + U[i][j];
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
for (k = 0; k < n; k++)
T[i][j] += -Dinv[i][k] * R[k][j];
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < 1; j++)
{
for (k = 0; k < n; k++)
{
C[i] += Dinv[i][k] * B[k];
}
}
}
i = 0;
int z = 0;
do
{
z = 0;
for (l = 0; l < n; l++)
{
for (j = 0; j < 1; j++)
{
for (k = 0; k < n; k++)
{
Y[l] += T[l][k] * X[k];
}
}
}
X[i+2] = Y[z] + C[z];
X[i+3] = Y[z+1] + C[z+1];
printf("%f\n%f", X[i+2], X[i+3]);
i++;
} while (i < 3);
return 0;
}