x = fminunc(fun, x0)
x = fminunc(fun, x0, options)
x = fminunc(problem)
[x, fval, exitflag, output, grad, hessian] = fminunc(___)
| 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. |
| 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. |
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.
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])
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)
| Version | Description |
|---|---|
| 2.0.0 | initial version |