ascent <- function(f, grad.f, x0, tol = 1e-9, n.max = 100) {
  #steepest ascent algorithm
  x.old <- x0
  x <- line.search(f, x0, grad.f(x0))
  n <- 1
  while((f(x) - f(x.old) > tol) & (n < n.max)) {
    x.old <- x
    x <- line.search(f, x, grad.f(x))
    n <- n + 1
  }
  return(x)
}