function newx = jacobiStep(x, A, b) % Arguments % x = an n-vector, either in column or row format; % This is the current iterate % A = an n-by-n matrix % b = an n-vector, either in column or row format % % Return value: an n-vector (column format); % This is the next Jacobi iterate for the system Ax = b % Check that every input is of the same dimension. [m, n] = size(A); if (m ~= n || length(x) ~= n || length(b) ~= n) error('Matrix/vector dimensions not appropriate'); return; end % The following loop implements equation (2.6.3) from p. 71 for i = 1:n indices = [1:(i-1) (i+1):n]; % Leave out the one undesirable index newx(i) = (b(i) - dot(A(i,indices),x(indices)))/A(i,i); end % At this point, newx is a row vector. % The next command takes its transpose (the ' does this) and makes % newx this transpose. That is, it makes newx a column vector. newx = newx';