function fjac = p16_jac ( n, x )

%*****************************************************************************80
%
%% P16_JAC sets the jacobian for problem 16.
%
%  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 );

  fjac(1,1) = 2.0 * x(1);
  fjac(1,2) = x(4);
  fjac(1,3) = x(7);
  fjac(1,4) = x(2);
  fjac(1,7) = x(3);

  fjac(2,1) = x(2);
  fjac(2,2) = x(1) + x(5);
  fjac(2,3) = x(8);
  fjac(2,5) = x(2);
  fjac(2,8) = x(3);

  fjac(3,1) = x(3);
  fjac(3,2) = x(6);
  fjac(3,3) = x(1) + x(9);
  fjac(3,6) = x(2);
  fjac(3,9) = x(3);

  fjac(4,1) = x(4);
  fjac(4,4) = x(1) + x(5);
  fjac(4,5) = x(4);
  fjac(4,6) = x(7);
  fjac(4,7) = x(6);

  fjac(5,2) = x(4);
  fjac(5,4) = x(2);
  fjac(5,5) = 2.0 * x(5);
  fjac(5,6) = x(8);
  fjac(5,8) = x(6);

  fjac(6,3) = x(4);
  fjac(6,4) = x(3);
  fjac(6,5) = x(6);
  fjac(6,6) = x(5) + x(9);
  fjac(6,9) = x(6);

  fjac(7,1) = x(7);
  fjac(7,4) = x(8);
  fjac(7,7) = x(1) + x(9);
  fjac(7,8) = x(4);
  fjac(7,9) = x(7);

  fjac(8,2) = x(7);
  fjac(8,5) = x(8);
  fjac(8,7) = x(2);
  fjac(8,8) = x(5) + x(9);
  fjac(8,9) = x(8);

  fjac(9,3) = x(7);
  fjac(9,6) = x(8);
  fjac(9,7) = x(3);
  fjac(9,8) = x(6);
  fjac(9,9) = 2.0 * x(9);

  return
end

