function fjac = p18_jac ( n, x )

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

  if ( x(1) ~= 0.0 )
    fjac(1,1) = x(2)^2 * ( 2.0 * exp ( - x(1)^2 ) - ...
      ( 1.0 - exp ( - x(1)^2 ) ) / x(1)^2);
    fjac(1,2) = 2.0 * x(2) * ( 1.0 - exp ( - x(1)^2 ) ) / x(1);

  else

    fjac(1,1) = x(2)^2;
    fjac(1,2) = 0.0;

  end

  if ( x(2) ~= 0.0 )

    fjac(2,1) = ( 1.0 - exp ( - x(2)^2 ) ) / x(2);
    fjac(2,2) = x(1) * ( 2.0 * exp ( - x(2)^2 ) - ...
      ( 1.0 - exp ( - x(2)^2 ) ) / x(2)^2 );

  else

    fjac(2,1) = 0.0;
    fjac(2,2) = x(1);

  end

  return
end
