factor_max = 0.05;
factor = factor_max;
x = [2;-1];
i = 0;
fx = f3(x);

while ( true )

  fpx = fp3(x);
  fprintf ( 1, '  %d  (%g,%g)  %g  %g  %g\n', i, x(1), x(2), fx, norm ( fpx ), factor );
  pause
  if ( norm ( fpx ) < 0.001 )
    fprintf ( 1, 'Stopping because derivative is small.\n' );
    break
  end

  i = i + 1;
  if ( 2.0 * factor <= factor_max )
    factor = 2.0 * factor;
  end

  x_old = x;
  fx_old = fx;

  j = 0;
  while ( j < 100 )
    j = j + 1;
    x = x_old - factor * fpx;
    fx = f3(x);
    if ( fx <= fx_old )
      fprintf ( 'happy break\n' );
      break;
    end
    factor = 0.5 * factor;
  end

  if ( j == 100 )
    fprintf ( 'What the hell?\n' );
  end

end

