Math Help - Program for Jacobi iterative method using Matlab.

1. Program for Jacobi iterative method using Matlab.

Hi All
I need a program for Jacobi iterative method (Jacobin method for solving linear system)using Mat-lab program ,specially I need to programing the following summation

and I need to know how to do the summation such that i not equal j in mat-lab

Thanks for all

2. Well, CB is our resident MATLAB expert, but you could just sum from 1 to i-1, and then from i+1 to n, taking into account the special cases like i = 1 or i = n. You could do all that in a subroutine.

3. Originally Posted by raed
Hi All
I need a program for Jacobi iterative method (Jacobin method for solving linear system)using Mat-lab program ,specially I need to programing the following summation

and I need to know how to do the summation such that i not equal j in mat-lab

Thanks for all
At a guess you want:

${\bf{X}}^{(k+1)}=({\bf{b}}-{\bf{AX}}^{(k)}-\mbox{diag}({\bf{A}},0).*{\bf{X}} )./ \mbox{diag}({\bf{A}},0)$

though I would have to check that this did what I expect specially if there is some ambuigity about row and column vectors.

You will of course be better off going back to the definition of Jacobi iteration:

Code:
d=diag(A,0); %extracts the principle diagonal of A as a vector
D=diag(d);   %creates a diagonal matrix with d down the diagonal
R=A-D;       %remainder matrix

X_new=inv(D)*(b-R*X_old);  %Jacobi iteration
or using the fact that we know the inverse of a diagonal matrix:

Code:
d=diag(A,0);
D=diag(d);
R=A-D;

X_new=(b-R*X_old)./d;

Matlab is a vector/matrix language, don't translate vector/matrix operations into elementwise scalar operations.

CB