fmin
Syntax
fmin(f, X0, [fargs], [xtol=0.0001], [ftol=0.0001], [maxIter],
[maxFun])
Arguments
f is the objective function to be minimized.
X0 is a numeric scalar or vector indicating the initial guess.
fargs (optional) is a tuple specifying the extra arguments passed to
f for calling f(X, fargs...)
.
xtol (optional) is a floating-point number specifying the absolute error in xopt between iterations that is acceptable for convergence. The default value is 0.0001.
ftol (optional) is a floating-point number specifying the absolute error
in f(xopt)
between iterations that is acceptable for
convergence. The default value is 0.0001.
maxIter (optional) is a non-negative integer indicating the maximum number of iterations to perform. The default value is the number of elements in X0 * 200.
maxFun (optional) is a non-negative integer indicating the maximum number of function evaluations to make. The default value is the number of elements in X0 * 200.
Details
Use a Nelder-Mead simplex algorithm to find the minimum of function of one or more variables. This algorithm only uses function values, not derivatives or second derivatives.
It returns a dictionary with the following keys:
- xopt: Parameter that minimizes function.
- fopt: Value of function at minimum:
fopt = f(xopt)
. - iterations: Number of iterations performed.
- fcalls: Number of function calls made.
- warnFlag:
- 0: Optimization algorithm completed.
- 1: Maximum number of function evaluations made.
- 2: Maximum number of iterations reached.
Examples
def f(x) {return x*x}
fmin(f, 1)
/* ouput:
xopt->[-8.881784197001252E-16]
fopt->7.888609052210119E-31
iterations->17
fcalls->34
warnFlag->0
*/
def targetFunc(x,y,z){
return x*x+2*x*y+5*y+z
}
fmin(targetFunc,5,(11,4))
/* output:
fcalls->46
warnFlag->0
xopt->[-11.0000]
fopt->-62.0000
iterations->23
*/