function value = tridiagonal_f ( x, n )

%*****************************************************************************80
%
%% TRIDIAGONAL_F evaluates the tridiagonal function.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    31 July 2016
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, real X(N), the evaluation point.
%
%    Input, integer N, the number of variables.
%
%    Output, real VALUE, the function value.
%
  value = x(1) ^ 2 + 2.0 * sum ( x(2:n) .^ 2 );

  for i = 1 : n - 1
    value = value - 2.0 * x(i) * x(i+1);
  end

  value = value - 2.0 * x(1);

  return
end
