function fminunc_example ( )

%% FMINUNC_EXAMPLE shows an example of unconstrained minimization.

  x0 = 14;
  x = fminunc ( @energy, x0 );
  fx = energy ( x );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  The minimizer X  = %f\n', x )
  fprintf ( 1, '  and F(X)    = %f\n', fx );

  return
end
function value = energy ( x )

%% ENERGY evaluates the energy function.

  x1 = 1;
  x2 = 2;
  x3 = 10;
  x4 = 27;
  x5 = 20;

  value = ( x - x1 ).^2 ...
        + ( x - x2 ).^2 ...
        + ( x - x3 ).^2 ...
        + ( x - x4 ).^2 ...
        + ( x - x5 ).^2;

  return
end

