function r = r8sd_res ( n, ndiag, offset, a, x, b )

%*****************************************************************************80
%
%% R8SD_RES computes the residual R = B-A*X for R8SD matrices.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    16 July 2016
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the order of the matrix.
%
%    Input, integer NDIAG, the number of diagonals that are stored.
%    NDIAG must be at least 1 and no more than N.
%
%    Input, integer OFFSET(NDIAG), the offsets for the diagonal
%    storage.
%
%    Input, real A(N,NDIAG), the R8SD matrix.
%
%    Input, real X(N), the vector to be multiplied by A.
%
%    Input, real B(N), the desired result A * x.
%
%    Output, real R(N), the residual R = B - A * X.
%
  r = r8sd_mv ( n, ndiag, offset, a, x );

  r(1:n,1) = b(1:n,1) - r(1:n,1);

  return
end

