### Jacobi Iterative Method

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 (http://books.google.pt/books?id=weYj75E_t6MC&pg=PA236&lpg=PA236&dq=jacobi+iterative+method+c%2B%2B&source=bl&ots=LQ04T5v9qz&sig=h-3Im5vRfVK3mijKh4-7iZu2lFA&hl=pt-PT&sa=X&ei=bnRUUdu2IMWR7AazgoHgDA&ved=0CGoQ6AEwBg#v=onepage&q=jacobi&f=false page 237)
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:
 ``1234567891011121314151617181920212223`` ``````for(k=0; k prevx = x; //x = x(k+1); prevx=x(k) for(int i=0; i

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
Just a ^bump since its now on page...4?!
> 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
@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.
It may be a precision issue, ¿what and how are you testing?
I'm testing if my xi vectors (possible solution vectors) are the same as theirs. I test it by outputting the vectors onto the console.

Tbh, my program does more, e.g. it has to read the matrix and "n" from a txt, parse it, etc. So the problem may be in there...but as far as you can see, the Jacobi iteration itself is fine?

PS- I also have to calc the ||Ax -b|| (after the x solution is found), meaning, this is linear algebra. Will this do the trick?
 ``123456789101112`` ``````double getResidual(vector< vector > m, vector x, vector b) { double norm= .0; for(int i=0;i
Topic archived. No new replies allowed.