1 % Usage: [xopt, fmin, retcode] = nlopt_minimize(algorithm, f, f_data, lb, ub,
4 % Minimizes a nonlinear multivariable function f(x, f_data{:}), where
5 % x is a row vector, returning the optimal x found (xopt) along with
6 % the minimum function value (fmin = f(xopt)) and a return code (retcode).
7 % A variety of local and global optimization algorithms can be used,
8 % as specified by the algorithm parameter described below. lb and ub
9 % are row vectors giving the upper and lower bounds on x, xinit is
10 % a row vector giving the initial guess for x, and stop is a struct
11 % containing termination conditions (see below).
13 % This function is a front-end for the external routine nlopt_minimize
14 % in the free NLopt nonlinear-optimization library, which is a wrapper
15 % around a number of free/open-source optimization subroutines. More
16 % details can be found on the NLopt web page (ab-initio.mit.edu/nlopt)
17 % and also under 'man nlopt_minimize' on Unix.
19 % f should be a handle (@) to a function of the form:
21 % [val, gradient] = f(x, ...)
23 % where x is a row vector, val is the function value f(x), and gradient
24 % is a row vector giving the gradient of the function with respect to x.
25 % The gradient is only used for gradient-based optimization algorithms;
26 % some of the algorithms (below) are derivative-free and only require
27 % f to return val (its value). f can take additional arguments (...)
28 % which are passed via the argument f_data: f_data is a cell array
29 % of the additional arguments to pass to f. (Recall that cell arrays
30 % are specified by curly brackets { ... }. For example, pass f_data={}
31 % for functions that require no additional arguments.)
33 % stop describes the termination criteria, and is a struct with a
34 % number of optional fields:
35 % stop.ftol_rel = fractional tolerance on function value
36 % stop.ftol_abs = absolute tolerance on function value
37 % stop.xtol_rel = fractional tolerance on x
38 % stop.xtol_abs = row vector of absolute tolerances on x components
39 % stop.fmin_max = stop when f < fmin_max is found
40 % stop.maxeval = maximum number of function evaluations
41 % stop.maxtime = maximum run time in seconds
42 % stop.verbose = > 0 indicates verbose output
43 % Minimization stops when any one of these conditions is met; any
44 % condition that is omitted from stop will be ignored. WARNING:
45 % not all algorithms interpret the stopping criteria in exactly the
46 % same way, and in any case ftol/xtol specify only a crude estimate
47 % for the accuracy of the minimum function value/x.
49 % The algorithm should be one of the following constants (name and
50 % interpretation are the same as for the C function). Names with
51 % _G*_ are global optimization, and names with _L*_ are local
52 % optimization. Names with _*N_ are derivative-free, while names
53 % with _*D_ are gradient-based algorithms. Algorithms:
55 % NLOPT_GD_MLSL_LDS, NLOPT_GD_MLSL, NLOPT_GD_STOGO, NLOPT_GD_STOGO_RAND,
56 % NLOPT_GN_CRS2_LM, NLOPT_GN_DIRECT_L, NLOPT_GN_DIRECT_L_NOSCAL,
57 % NLOPT_GN_DIRECT_L_RAND, NLOPT_GN_DIRECT_L_RAND_NOSCAL, NLOPT_GN_DIRECT,
58 % NLOPT_GN_DIRECT_NOSCAL, NLOPT_GN_ISRES, NLOPT_GN_MLSL_LDS, NLOPT_GN_MLSL,
59 % NLOPT_GN_ORIG_DIRECT_L, NLOPT_GN_ORIG_DIRECT, NLOPT_LD_AUGLAG_EQ,
60 % NLOPT_LD_AUGLAG, NLOPT_LD_LBFGS, NLOPT_LD_LBFGS_NOCEDAL, NLOPT_LD_MMA,
61 % NLOPT_LD_TNEWTON, NLOPT_LD_TNEWTON_PRECOND,
62 % NLOPT_LD_TNEWTON_PRECOND_RESTART, NLOPT_LD_TNEWTON_RESTART,
63 % NLOPT_LD_VAR1, NLOPT_LD_VAR2, NLOPT_LN_AUGLAG_EQ, NLOPT_LN_AUGLAG,
64 % NLOPT_LN_BOBYQA, NLOPT_LN_COBYLA, NLOPT_LN_NELDERMEAD,
65 % NLOPT_LN_NEWUOA_BOUND, NLOPT_LN_NEWUOA, NLOPT_LN_PRAXIS, NLOPT_LN_SBPLX
67 % For more information on individual algorithms, see their individual
68 % help pages (e.g. "help NLOPT_LN_SBPLX").
69 function [xopt, fmin, retcode] = nlopt_minimize(algorithm, f, f_data, lb, ub, xinit, stop)
71 [xopt, fmin, retcode] = nlopt_minimize_constrained(algorithm, f, f_data, {}, {}, lb, ub, xinit, stop);