## minimize a 2D quadratic function:
f <- function(b) {
x <- b[1]; y <- b[2];
val <- -(x - 2)^2 - (y - 3)^2 # concave parabola
attr(val, "gradient") <- c(-2*x + 4, -2*y + 6)
attr(val, "hessian") <- matrix(c(-2, 0, 0, -2), 2, 2)
val
}
## Note that NR finds the minimum of a quadratic function with a single
## iteration. Use c(0,0) as initial value.
res <- maxNR( f, start = c(0,0) )
summary(res)
summary(res, hessian=TRUE)
Run the code above in your browser using DataLab