e04dg {NAGFWrappers} | R Documentation |
e04dg minimizes an unconstrained nonlinear function of several variables using a pre-conditioned, limited memory quasi-Newton conjugate gradient method. First derivatives (or an ‘acceptable’ finite difference approximation to them) are required. It is intended for use on large scale problems.
e04dg(objfun, x, optlist, n = nrow(x))
objfun |
function objfun must calculate the objective function F(x) and possibly its gradient as well for a specified n element vector x.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
x |
double array An initial estimate of the solution. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
optlist |
options list Optional parameters may be listed, as shown in the following table:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
n |
integer: default = nrow(x) n, the number of variables. |
R interface to the NAG Fortran routine E04DGF.
ITER |
integer The total number of iterations performed. |
OBJF |
double The value of the objective function at the final iterate. |
OBJGRD |
double array The gradient of the objective function at the final iterate (or its finite difference approximation). |
X |
double array The final estimate of the solution. |
IFAIL |
integer ifail =0unless the function detects an error or a warning has been flagged (see the Errors section in Fortran library documentation). |
NAG
http://www.nag.co.uk/numeric/FL/nagdoc_fl23/pdf/E04/e04dgf.pdf
optlist <- list() ifail <- 0 objfun = function(mode, n, x, nstate) { objgrd <- as.matrix(mat.or.vec(2, 1)) expx1 <- exp(x[1]) objf <- expx1 %*% (4 %*% x[1]^2 + 2 %*% x[2]^2 + 4 %*% x[1] %*% x[2] + 2 %*% x[2] + 1) if (mode == 2) { objgrd[1] <- 4 %*% expx1 %*% (2 %*% x[1] + x[2]) + objf objgrd[2] <- 2 %*% expx1 %*% (2 %*% x[2] + 2 %*% x[1] + 1) } else { objgrd <- as.matrix(mat.or.vec(2, 1)) } list(MODE = as.integer(mode), OBJF = objf, OBJGRD = as.matrix(objgrd)) } x <- matrix(c(-1, 1), nrow = 2, ncol = 1, byrow = TRUE) e04dg(objfun, x, optlist)