function [ x , k , err , time ]= mjacobi ( A,b,x,tol ,max_it )
if nargin <5
max_it =1000;
end
if nargin <4
tol=1.e-5;
end
if nargin <3
x = zeros ( length ( b ));
end
tic;
bnrm2= norm ( b );
r= b - A *x;
err = norm ( r )/bnrm2;
if ( err < tol )
return ;
end
D = diag(diag ( A ));
for k =1:max_it
x = D \(( D - A )*x+ b );
r = b -A *x ;
err = norm ( r )/bnrm2;
if ( err <= tol )
break ;
end
end
time = toc ;
end