function rhs = tridiagonal_mv ( a, b, c, x )

%*****************************************************************************80
%
%% tridiagonal_mv() multiplies a tridiagonal matrix times a vector.
%
%  Discussion:
%
%    There are M rows in the matrix, but at most three nonzero entries.
%    The subdiagonal is stored in A, the diagonal in B, the superdiagonal in C.
%
%    | b(1)    c(1)    ....  ....    ....    ....   |
%    | a(2)    b(2)    c(2)  ....    ....    ....   |
%    | ....    a(3)    b(3)  c(3)    ....    ....   |
%    | ....    ....    ....  ......  ....    ....   |
%    | ....    ....    ....  a(n-1)  b(n-1)  c(n-1) |
%    | ....    ....    ....  ......  a(n)    b(n)   |
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    15 January 2020
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    https://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm
%
%  Input:
%
%    real A(N), B(N), C(N), the matrix entries.
%    A(1) and C(N) are not used.
%
%    real X(N,:), the vector to be multiplied.
%
%  Output:
%
%    real RHS(N,:), the product.
%
  [ m, n ] = size ( x );

  rhs = zeros ( m, n );

  for j = 1 : n
    rhs(1:m,j)   =                b(1:m,1)   .* x(1:m,j);
    rhs(2:m,j)   = rhs(2:m,j)   + a(2:m,1)   .* x(1:m-1,j);
    rhs(1:m-1,j) = rhs(1:m-1,j) + c(1:m-1,1) .* x(2:m,j); 
  end

  return
end
