18 lines
332 B
Matlab
18 lines
332 B
Matlab
function [x, nit] = jacobi(A, b, x0, err, maxnit)
|
|
n = length(b);
|
|
M = diag(diag(A));
|
|
N = M - A;
|
|
T = M^(-1)*N;
|
|
c = M^(-1)*b;
|
|
x = x0;
|
|
for k = 1:maxnit
|
|
old_x = x;
|
|
x = T*x+c;
|
|
if norm(x-old_x,inf) <= ((1-norm(T,inf))/norm(T,inf))*err
|
|
nit = k;
|
|
return;
|
|
endif
|
|
endfor
|
|
error('Too dificult');
|
|
end;
|