function x = r8st_jac_sl ( n, nz_num, row, col, a, b, x, it_max )

%*****************************************************************************80
%
%% r8st_jac_sl() solves an r8st system using Jacobi iteration.
%
%  Discussion:
%
%    The r8st storage format corresponds to the SLAP Triad format.
%
%    The r8st storage format stores the row, column and value of each nonzero
%    entry of a sparse matrix.  The entries may be given in any order.  No
%    check is made for the erroneous case in which a given matrix entry is
%    specified more than once.
%
%    This routine REQUIRES that the matrix be square, that the matrix
%    have nonzero diagonal entries, and that the first N entries of
%    the array A be exactly the diagonal entries of the matrix, in order.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    22 September 2015
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the order of the matrix.
%
%    integer NZ_NUM, the number of nonzero elements in 
%    the matrix.
%
%    integer ROW(NZ_NUM), COL(NZ_NUM), the row and column 
%    indices of the nonzero elements.
%
%    real A(NZ_NUM), the nonzero elements of the matrix.
%
%    real B(N), the right hand side of the linear system.
%
%    real X(N), a starting estimate for the solution.
%
%    integer IT_MAX, the maximum number of iterations.
%
%  Output:
%
%    real X(N), the approximate solution.
%
  b = b(:);
%
%  Ensure that the matrix lists diagonal elements first.
%
  [ row, col, a ] = r8st_diagonal ( n, n, nz_num, row, col, a );

  for it_num = 1 : it_max
%
%  Initialize to right hand side.
%
    x_new(1:n,1) = b(1:n,1);
%
%  Subtract off-diagonal terms.
%
    for k = n + 1 : nz_num
      i = row(k);
      j = col(k);
      x_new(i) = x_new(i) - a(k) * x(j);
    end
%
%  Divide by diagonal terms.
%
    x_new(1:n,1) = x_new(1:n,1) ./ a(1:n,1);
%
%  Update.
%
    x(1:n,1) = x_new(1:n,1);

  end

  return
end
