fmincon.RdFind minimum of multivariable functions with nonlinear constraints.
fmincon(x0, fn, gr = NULL, ..., method = "SQP",
A = NULL, b = NULL, Aeq = NULL, beq = NULL,
lb = NULL, ub = NULL, hin = NULL, heq = NULL,
tol = 1e-06, maxfeval = 10000, maxiter = 5000)starting point.
objective function to be minimized.
gradient function of the objective; not used for SQP method.
additional parameters to be passed to the function.
method options 'SQP', 'auglag'; only 'SQP is implemented.
linear ineqality constraints of the form A x <= b .
linear eqality constraints of the form Aeq x = beq .
bounds constraints of the form lb <= x <= ub .
nonlinear inequality constraints of the form hin(x) <= 0 .
nonlinear equality constraints of the form heq(x) = 0 .
relative tolerance.
maximum number of iterations.
maximum number of function evaluations.
Wraps the function solnl in the 'NlcOptim' package. The
underlying method is a Squential Quadratic Programming (SQP) approach.
Constraints can be defined in different ways, as linear constraints in matrix form, as nonlinear functions, or as bounds constraints.
List with the following components:
the best minimum found.
function value at the minimum.
integer indicating the terminating situation.
parameter list describing the final situation.
J. Nocedal and S. J. Wright (2006). Numerical Optimization. Second Edition, Springer Science+Business Media, New York.
fmincon mimics the Matlab function of the same name.
# Classical Rosenbrock function
n <- 10; x0 <- rep(1/n, n)
fn <- function(x) {n <- length(x)
x1 <- x[2:n]; x2 <- x[1:(n - 1)]
sum(100 * (x1 - x2^2)^2 + (1 - x2)^2)
}
# Equality and inequality constraints
heq1 <- function(x) sum(x)-1.0
hin1 <- function(x) -1 * x
hin2 <- function(x) x - 0.5
ub <- rep(0.5, n)
# Apply constraint minimization
res <- fmincon(x0, fn, hin = hin1, heq = heq1)
res$par; res$value
#> [1] 5.570683e-01 3.123570e-01 1.005245e-01 1.336732e-02 3.474438e-03
#> [6] 3.310229e-03 3.306258e-03 3.306336e-03 3.285536e-03 6.018569e-19
#> [1] 7.426002