I'm trying to solve a linear system of linear equations using the Gauss-Seidel iterative method. I'm writing c code to do it for me since I have over 349 entries to solve. In other words, I have 349 equations each with 3 unknowns so I'm calculated each unknown in 3 equation chunks.
at the end I average the weights I have calculated, so I'm not concerned with the solutions to each individual equation
the code looks like
int i;
double epsilon = .00000000001;
double error = 1;
double w1 = 1, w2 = 1, w3 = 1, error1, error2, error3, w1_sum = 0, w2_sum = 0, w3_sum = 0;
for (i = 0; i < 349; i++){
w1 = 1;
w2 = 1;
w3 = 1;
for (int j = 0; j < 1000; j++){
w1 = (pythag[i] - (adjD[i]*w2 + adjTemp[i]*w3)) / adjO[i];
w2 = (pythag[i+1] - (adjO[i+1]*w1 + adjTemp[i+1]*w3)) / adjD[i+1];
w3 = (pythag[i+2] - (adjO[i+2]*w1 + adjD[i+2]*w2)) / adjTemp[i+2];
}
w1_sum += w1;
w2_sum += w2;
w3_sum += w3;
}
double weight1 = w1_sum / 349;
double weight2 = w2_sum / 349;
double weight3 = w3_sum / 349;
printf("Weight 1 = %G\n", weight1);
printf("Weight 2 = %G\n", weight2);
printf("Weight 3 = %G\n", weight3);
as I increase the size of the inner loop, w1, w2, and w3 increase instead of converging