function fx = p06_fx ( n, x )

%*****************************************************************************80
%
%% P06_FX evaluates the function for problem 6.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    10 October 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of variables and equations.
%
%    real X(N), the evaluation point.
%
%  Output:
%
%    real FX(N), the function value.
%
  fx = zeros ( n, 1 );

  for i = 1 : 29

    ti = i / 29.0;

    sum1 = 0.0;
    temp = 1.0;
    for j = 2 : n
      sum1 = sum1 + ( j - 1 ) * temp * x(j);
      temp = ti * temp;
    end

    sum2 = 0.0;
    temp = 1.0;
    for j = 1 : n
      sum2 = sum2 + temp * x(j);
      temp = ti * temp;
    end

    temp = 1.0 / ti;

    for k = 1 : n
      fx(k) = fx(k) + temp * ( sum1 - sum2 * sum2 - 1.0 ) * ...
        ( ( k - 1 ) - 2.0 * ti * sum2 );
      temp = ti * temp;
    end

  end

  fx(1) = fx(1) + 3.0 * x(1) - 2.0 * x(1) * x(2) + 2.0 * x(1)^3;
  fx(2) = fx(2) + x(2) - x(1)^2 - 1.0;

  return
end

