function [ X, Y, Z ] = peak ( nx, ny )

%*****************************************************************************80
%
%% peak evaluates a test function useful for demonstrating contour plotting.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    05 May 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real NX, NY: the number of sample values in the X and Y directions.
%
%  Output:
%
%    real X(NX,NY), Y(NX,NY), Z(NX,NY): sample values of the peak function.
%
  if ( nargin == 0 )
    nx = 7;
    ny = 7
  elseif ( nargin == 1 )
    ny = nx;
  end

  x = linspace ( -3.0, +3.0, nx );
  y = linspace ( -3.0, +3.0, ny );

  [ X, Y ] = ndgrid ( x, y );

  Z = 3*(1-X).^2 .* exp(-(X.^2) - (Y+1).^2) ... 
    - 10*(X/5 - X.^3 - Y.^5) .* exp(-X.^2-Y.^2) ... 
    - 1/3 * exp(-(X+1).^2 - Y.^2);

  return
end

