Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function x = solJacobi(A,b,x0,tol,maxiter)
- [n n] = size(A)
- xc = zeros(n,1);
- xp = x0;
- W = 1;
- for k = 1 : maxiter
- for i = 1 : n
- ok = 1;
- s=0;
- for j = 1 : n
- if j==1
- ok = 0;
- endif
- if ok == 1
- s=s+A(i,j)*x(j);
- endif
- endfor
- xc(i) = (b(i) - s)/A(i,i);
- if xc - xp < tol
- W = 0;
- endif
- xp = xc;
- endfor
- if W = 100
- break;
- endif
- endfor
- x = xc;
- endfunction
Advertisement
Add Comment
Please, Sign In to add comment