function gradient_descent_vector_f_test ( )

%*****************************************************************************80
%
%% gradient_descent_vector_f_test() uses gradient descent on a vector problem.
%
%  Discussion:
%
%    We apply gradient descent to minimize the L2 norm of a vector function 
%    f(x) of a vector argument x.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    29 July 2022
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'gradient_descent_vector_f_test():\n' );
  fprintf ( 1, '  Seek minimizer of vector function f(x).\n' );
%
%  Choose an initial guess.  X is a COLUMN vector.
% 
  x0 = [ 0.0; 0.0; 0.0 ];
%
%  Maximum number of iterations
%
  it_max = 83;
%
%  Choose a small learning rate.
%
  alpha = 0.001;

  x = gradient_descent_vector_f ( ...
    @(x)wiki3(x), @(x)wiki3_df(x), x0, it_max, alpha );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Initial x = (%g,%g,%g), ||f(x)|| = %g, ||J(x)|| = (%g)\n', ...
    x0, ...
    0.5 * ( norm ( wiki3 ( x0 ) ) )^2, ...
    norm ( wiki3_df ( x0 ), 'fro' ) );

  fprintf ( 1, '  Final   x = (%g,%g,%g), ||f(x)|| = %g, ||J(x)|| = (%g)\n', ...
    x, ...
    0.5 * ( norm ( wiki3 ( x ) ) ) ^2, ...
    norm ( wiki3_df ( x ), 'fro' ) );

  return
end

function value = wiki3 ( xyz )

%*****************************************************************************80
%
%% wiki3() evaluates the wiki3 function.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    29 July 2022
%
%  Input:
%
%    real xyz(3): the arguments.
%
%  Output:
%
%    real value(3): the function value.
%
  x = xyz(1);
  y = xyz(2);
  z = xyz(3);
  value = zeros ( 3, 1 );

  value(1) = 3.0 * x - cos ( y * z ) - 3.0 / 2.0;
  value(2) = 4.0 * x^2 - 625.0 * y^2 + 2.0 * y - 1.0;
  value(3) = exp ( - x * y ) + 20.0 * z + ( 10.0 * pi - 3.0 ) / 3.0;

  return
end
function value = wiki3_df ( xyz )

%*****************************************************************************80
%
%% wiki3_df() evaluates the wiki3 jacobian.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    29 July 2022
%
%  Input:
%
%    real xyz(3): the arguments.
%
%  Output:
%
%    real value(3,3): the Jacobian matrix.
%
  x = xyz(1);
  y = xyz(2);
  z = xyz(3);

  value = zeros ( 3, 3 );

  value(1,1) = 3.0;
  value(1,2) = sin ( y * z ) * z;
  value(1,3) = sin ( y * z ) * y;
  value(2,1) = 8.0 * x;
  value(2,2) =  - 1250.0 * y + 2.0;
  value(2,3) = 0.0;
  value(3,1) = - y * exp ( - x * y );
  value(3,2) = - x * exp ( - x * y );
  value(3,3) = 20.0;

  return
end


