fminunc
Unconstrained nonlinear minimization.
📝Syntax
x = fminunc(fun, x0)
x = fminunc(fun, x0, options)
x = fminunc(problem)
[x, fval, exitflag, output, grad, hessian] = fminunc(___)
📥Input Arguments
Parameter Description
fun Objective function returning a real scalar. With gradient options enabled, it can also return the gradient and Hessian.
x0 Initial scalar, vector or matrix point.
options Options created with optimoptions or optimset.
problem Structure with fields objective, x0, solver and options.
📤Output Arguments
Parameter Description
x Computed minimizer.
fval Objective value at x.
exitflag Termination indicator.
output Diagnostic structure with iterations, funcCount, stepsize, algorithm, firstorderopt and message.
grad Gradient at x.
hessian Approximate or user supplied Hessian at x.
📄Description

fminunc minimizes a scalar nonlinear objective without constraints.

The default quasi-newton algorithm uses BFGS, DFP, steepest descent, or limited-memory BFGS depending on HessianApproximation and legacy HessUpdate options. The trust-region algorithm uses user gradients, optional objective Hessians, Hessian multiply functions and truncated conjugate gradients.

Accepted display modes are off, none, final, final-detailed, notify, notify-detailed, iter and iter-detailed.

💡Examples
Minimize a quadratic polynomial.
fun = @(x) 3*x(1)^2 + 2*x(1)*x(2) + x(2)^2 - 4*x(1) + 5*x(2);
[x, fval] = fminunc(fun, [1, 1])
Use a gradient with the trust-region algorithm.
function [f, g] = rosenwithgrad(x)
  f = 100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
  g = [-400*(x(2)-x(1)^2)*x(1) - 2*(1-x(1)); 200*(x(2)-x(1)^2)];
end
opts = optimoptions('fminunc', 'Algorithm', 'trust-region', 'SpecifyObjectiveGradient', true);
x = fminunc(@rosenwithgrad, [-1; 2], opts)
🔗See Also
fminconoptimoptionsfminsearch
Used Functions
optimoptions optimset
📚Bibliography
Broyden, C. G., The convergence of a class of double-rank minimization algorithms, IMA Journal of Applied Mathematics, 1970. Fletcher, R., Practical Methods of Optimization, Wiley, 1987. Liu, D. C. and Nocedal, J., On the limited memory BFGS method for large scale optimization, Mathematical Programming, 1989. Nocedal, J. and Wright, S. J., Numerical Optimization, Springer, 2006.
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub