function r = tri_resid ( A1, A2, A3, x, b )
%
%  function r = tri_resid ( A1, A2, A3, x, b )
%
%  TRI_RESID computes the residual for a compressed tridiagonal linear system.
%
%  Modified:
%
%    01 April 2000
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, real A1(N-1), A2(N), A3(N-1), the subdiagonal, diagonal, and
%    superdiagonal elements of the matrix A.
%
%    Input, real x(N), the solution of the linear system.
%
%    Input, real b(N), the right hand side.
%
%    Output, real r(N), the residual of the linear system.
%
n = length ( A2 );

r = A2 .* x - b;

r(2:n)   = r(2:n)   + A1 .* x(1:n-1);
r(1:n-1) = r(1:n-1) + A3 .* x(2:n);
