# fminunc

Find the unconstrained minimum of a real function.

## Syntax

x = fminunc(@func,x0)

x = fminunc(@func,x0,options)

[x,fval,info,output] = fminunc(...)

## Inputs

`func`- The function to minimize. See the optimset option GradObj for details.
`x0`- An estimate of the location of the minimum.
`options`- A struct containing option settings.

## Outputs

- x
- The location of the function minimum.
- fval
- The minimum of the function.
- info
- The convergence status flag.
- info = 4
- Relative step size converged to within tolX.
- info = 3
- Relative function value converged to within tolFun.
- info = 2
- Step size converged to within tolX.
- info = 1
- Function value converged to within tolFun.
- info = 0
- Reached maximum number of iterations or function calls, or the algorithm aborted because it was not converging.
- info = -3
- Trust region became too small to continue.

- output
- A struct containing iteration details. The members are as follows:
- iterations
- The number of iterations.
- nfev
- The number of function evaluations.
- xiter
- The candidate solution at each iteration.
- fvaliter
- The objective function value at each iteration.

## Example

Minimize the Rosenbrock function.

```
function obj = Rosenbrock(x)
obj = (1 - x(1))^2 + 100 * (x(2) - x(1)^2)^2;
end
x0 = [-1.2, 1.0];
[x,fval] = fminunc(@Rosenbrock, x0)
```

```
x = [Matrix] 1 x 2
1.00000 1.00000
fval = 1.29122e-15
```

## Comments

fminunc uses a quasi-Netwon algorithm with damped BFGS updates and a trust region method.

Options for convergence tolerance controls and analytical derivatives are specified with optimset.

To pass additional parameters to a function argument, use an anonymous function.

The optimset options and defaults are as follows:

- MaxIter: 100
- MaxFunEvals: 400
- TolFun: 1.0e-7
- TolX: 1.0e-7
- GradObj: 'off'
- Display: 'off'