Solution

ID: past-exam-of-the-probability-statistics-and-options-ii-course-of-the-university-of-oxford/2010/u/u2/b/iii/solution

Here and . This implementation uses the undamped Newton step, checks a stationary point's curvature, and reports failure on a two-cycle or exhausted iteration limit:
R
newton_min <- function(x0, tol = 1e-10, maxit = 100L) {
  fp <- function(x) 4*x^3 - 12*x^2 + 4*x + 12
  fpp <- function(x) 12*x^2 - 24*x + 4
  x <- x0
  trace <- x
  for (k in seq_len(maxit)) {
    g <- fp(x)
    h <- fpp(x)
    if (abs(g) <= tol) {
      return(list(x = x, converged = h > 0,
                  reason = if (h > 0) "minimum" else "not a strict minimum",
                  trace = trace))
    }
    if (!is.finite(h) || abs(h) <= .Machine$double.eps)
      stop("Newton step has zero or invalid curvature")
    next_x <- x - g/h
    if (!is.finite(next_x)) stop("Nonfinite Newton iterate")
    trace <- c(trace, next_x)
    n <- length(trace)
    if (n >= 3L && abs(trace[n] - trace[n - 2L]) <= tol*(1 + abs(next_x)))
      return(list(x = next_x, converged = FALSE,
                  reason = "two-cycle", trace = trace))
    x <- next_x
  }
  list(x = x, converged = FALSE, reason = "iteration limit", trace = trace)
}
A sufficiently close start near converges to the minimum. The derivative cubic has exactly one real root: after it is proportional to , whose local maximum and minimum are both positive, so it crosses zero only once, on the left. Since the quartic tends to in both directions and its curvature at that stationary point is positive, this is the unique global minimum. The function reports convergence rather than assuming that every starting point must reach it.

New to topics? Read the docs here!