function fjac = p23_jac ( n, x )

%*****************************************************************************80
%
%% p23_jac sets the jacobian for problem 23.
%
%  Discussion:
%
%    Errors in this calculation were corrected on 17 October 2020.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    17 October 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of variables and equations.
%
%    real X(N), the evaluation point.
%
%  Output:
%
%    real FJAC(N,N), the jacobian matrix.
%
  fjac = zeros ( n, n );

  for i = 1 : n
    fjac(i,i) = 1.0;
  end

  c = 0.9

  mu = zeros ( n, 1 );
  for i = 1 : n
    mu(i) = ( 2 * i - 1 ) / ( 2 * n );
  end

  for i = 1 : n

    term = 1.0 - c * sum ( mu(i) * x(1:n) ./ ( mu(i) + mu(1:n) ) ) / ( 2 * n );

    for j = 1 : n

      termp = c * mu(i) / ( mu(i) + mu(j) ) / ( 2 * n );

      fjac(i,j) = fjac(i,j) - ( termp / term ) / term;

    end

  end

  return
end

