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:
$\displaystyle {\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