Mar 28, 2013 at 5:28pm UTC
Good evening guys.
For the past few days I have been working on what is basically, a Jacobi Iterative Method. For some reason, my results keep coming back differently from the wanted solution. They are good results, but clearly not true.
Today luckily I found a book with the code on how to make it (
and yet, as far as I can see, their code is exactly the same as mine (small differences in declared vars and names) and yet, using the same matrix and b vector as them I get different results.
Here's my code:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 for(k=0; k<nmax ; k++)
vector< double> prevx = x; //x = x(k+1); prevx=x(k)
for( int i=0; i<n; i++)
double sum = .0;
for( int j=0 ; j<n; j++)
if(i != j)
sum += matrix[i][j] * prevx[j];
x[i] = (b[i] - sum)/ matrix[i][i];
double norm = 0.0;
for( int i=0;i<x.size();i++)
norm += (pow(x[i]-prevx[i],2));
norm = sqrt(norm);
if(norm < epsilon)
success = true;
Am I blind or they are basically the same?
If so, how come mine isn't working properly?
PS- I know this sounds stupid, but I would rather prefer hints instead of a solution. Figuring out the problem by myself (even if with some assistance) is a great way to learn.
Last edited on
Mar 28, 2013 at 6:44pm UTC
Mar 28, 2013 at 7:07pm UTC
Just a ^bump since its now on page...4?!
Mar 28, 2013 at 8:09pm UTC
> my results keep coming back differently from the wanted solution.
> They are good results, but clearly not true.
Show an example.
Their stop condition is different
Mar 28, 2013 at 8:27pm UTC
@ne555- Thanks for your time mate. You are indeed right, their condition is an infinitenorm but that isn't what really concerns me. You see, each x (solution) vector per iteration is different from theirs, even the mean and variance, mine are much much smaller.
Mar 28, 2013 at 8:57pm UTC
It may be a precision issue, ¿what and how are you testing?