function contour_gradient_3d ( xmin, xmax, nx, ymin, ymax, ny, f );

%*****************************************************************************80
%
%% contour_gradient_3d() plots Z(X,Y) with contour lines and gradient vectors.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    02 January 2019
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real XMIN, XMAX, the X range.
%
%    integer NX, the number of X grid points.
%
%    real YMIN, YMAX, the Y range.
%
%    integer NY, the number of Y grid points.
%
%    function handle F(X,Y), evaluates Z=F(X,Y).
%
  x = linspace ( xmin, xmax, nx );
  y = linspace ( ymin, ymax, ny );
  [ X, Y ] = meshgrid ( x, y );

  Z = f ( X, Y );

  level_num = 20;
  contour ( X, Y, Z, level_num )
  hold on
  surf ( X, Y, Z )

  h = 0.01;
  [ U, V ] = gradient ( Z, h );
  quiver ( X, Y, U, V );

  view ( 3 );
  hold ( 'off' );

  xlabel ( '--X--' );
  ylabel ( '--Y--' );
  zlabel ( '--Z(X,Y)--' );
  title ( 'Contour + Gradient Vectors' )

  return
end
