I have implemented Question 2 and it works well but I a can't see what I am doing wrong on Q3. I have read pages 478 - 479 and I understand how the process works ( Or so I thought). But when it comes to programming it I get ridiculous results that I can't explain. The more iterations the greater the error. I have used Eq.(8.15) and Eq.(8.16). I am clearly missing something. Any ideas?
void calculateAverages()
{
for(int i = 1; i < 4; i++)
for(int j = 1; j < 5; j++)
Arr[j] = (Arr[0][j] + Arr[4][j] + Arr[0] + Arr[5])/4.0;
}
void copyArr2Fixed()
{
for(int i = 0; i < 5; i++) // Assign Arr to the Fixed values K
for(int j = 0; j < 6; j++)
Fixed[j] = Arr[j];
}
int calculateADI()
{
double p = 1;
double test;
int iter = 0;
calculateAverages();
do {
test = Arr[1][1];
copyArr2Fixed();
for(int i = 1; i < 4; i++)
for(int j = 1; j < 5; j++)
Arr[j] = Fixed[j] + p*(Arr[j-1]-(2*Arr[j])+ Arr[j+1])
+ p*(Fixed[i-1][j]-(2*Fixed[j])+ Fixed[i+1][j]);
iter++;
copyArr2Fixed();
for(int j = 1; j < 5; j++)
for(int i = 1; i < 4; i++)
Arr[j] = Fixed[j] + p*(Arr[i-1][j]-(2*Arr[j])+ Arr[i+1][j])
+ p*(Fixed[j-1]-(2*Fixed[j])+ Fixed[j+1]);
iter++;
}while (((test - Arr[1][1]) > 0.0001) || ((Arr[1][1] - test) > 0.0001));
return iter;
}