function value = chebyquad_f ( x, n )

%*****************************************************************************80
%
%% chebyquad_f() evaluates the Chebyquad function.
%
%  Discussion:
%
%    The function is formed by the sum of squares of N separate terms.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    31 July 2016
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real X(N), the evaluation point.
%
%    integer N, the number of variables.
%
%  Output:
%
%    real VALUE, the function value.
%
  fvec = zeros ( n, 1 );

  for j = 1 : n

    t1 = 1.0;
    t2 = 2.0 * x(j) - 1.0;
    t = 2.0 * t2;

    for i = 1 : n
      fvec(i) = fvec(i) + t2;
      th = t * t2 - t1;
      t1 = t2;
      t2 = th;
    end

  end

  for i = 1 : n
    fvec(i) = fvec(i) / n;
    if ( mod ( i, 2 ) == 0 )
      fvec(i) = fvec(i) + 1.0 / ( i * i - 1 );
    end
  end
%
%  Compute F.
%
  value = norm ( fvec );

  return
end
