function fjac = p12_jac ( n, x )

%*****************************************************************************80
%
%% P12_JAC sets the jacobian for problem 12.
%
%  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 FJAC(N,N), the jacobian matrix.
%
  fjac = zeros ( n, n );

  sum1 = 0.0
  for i = 1 : n
    sum1 = sum1 + i * ( x(i) - 1.0 );
  end

  for i = 1 : n
    for j = 1 : n

      fjac(i,j) = i * j * ( 1.0 + 6.0 * sum1 * sum1 );

      if ( i == j )
        fjac(i,j) = fjac(i,j) + 1.0;
      end

    end
  end

  return
end
