Mercurial > hg > octave-nkf
diff scripts/optimization/fminunc.m @ 9627:5bcfa0b346e8
fix extra outputs in fminunc
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 08 Sep 2009 13:39:39 +0200 |
parents | bc0739d02724 |
children | 73e6ad869f08 |
line wrap: on
line diff
--- a/scripts/optimization/fminunc.m +++ b/scripts/optimization/fminunc.m @@ -20,7 +20,7 @@ ## -*- texinfo -*- ## @deftypefn{Function File} {} fminunc (@var{fcn}, @var{x0}, @var{options}) -## @deftypefnx{Function File} {[@var{x}, @var{fvec}, @var{info}, @var{output}, @var{fjac}]} = fminunc (@var{fcn}, @dots{}) +## @deftypefnx{Function File} {[@var{x}, @var{fvec}, @var{info}, @var{output}, @var{grad}, @var{hess}]} = fminunc (@var{fcn}, @dots{}) ## Solve a unconstrained optimization problem defined by the function @var{fcn}. ## @var{fcn} should accepts a vector (array) defining the unknown variables, ## and return the objective function value, optionally with gradient. @@ -60,6 +60,10 @@ ## The trust region radius became excessively small. ## @end table ## +## Optionally, fminunc can also yield a structure with convergence statistics +## (@var{output}), the output gradient (@var{grad}) and approximate hessian +## (@var{hess}). +## ## Note: If you only have a single nonlinear equation of one variable, using ## @code{fminbnd} is usually a much better idea. ## @seealso{fminbnd, optimset} @@ -308,6 +312,10 @@ output.successful = nsuciter; output.funcCount = nfev; + if (nargout > 5) + hess = hesr'*hesr; + endif + endfunction ## An assistant function that evaluates a function handle and checks for