Mercurial > octave-nkf
comparison 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 |
comparison
equal
deleted
inserted
replaced
9626:bccba774af8b | 9627:5bcfa0b346e8 |
---|---|
18 ## | 18 ## |
19 ## Author: Jaroslav Hajek <highegg@gmail.com> | 19 ## Author: Jaroslav Hajek <highegg@gmail.com> |
20 | 20 |
21 ## -*- texinfo -*- | 21 ## -*- texinfo -*- |
22 ## @deftypefn{Function File} {} fminunc (@var{fcn}, @var{x0}, @var{options}) | 22 ## @deftypefn{Function File} {} fminunc (@var{fcn}, @var{x0}, @var{options}) |
23 ## @deftypefnx{Function File} {[@var{x}, @var{fvec}, @var{info}, @var{output}, @var{fjac}]} = fminunc (@var{fcn}, @dots{}) | 23 ## @deftypefnx{Function File} {[@var{x}, @var{fvec}, @var{info}, @var{output}, @var{grad}, @var{hess}]} = fminunc (@var{fcn}, @dots{}) |
24 ## Solve a unconstrained optimization problem defined by the function @var{fcn}. | 24 ## Solve a unconstrained optimization problem defined by the function @var{fcn}. |
25 ## @var{fcn} should accepts a vector (array) defining the unknown variables, | 25 ## @var{fcn} should accepts a vector (array) defining the unknown variables, |
26 ## and return the objective function value, optionally with gradient. | 26 ## and return the objective function value, optionally with gradient. |
27 ## In other words, this function attempts to determine a vector @var{x} such | 27 ## In other words, this function attempts to determine a vector @var{x} such |
28 ## that @code{@var{fcn} (@var{x})} is a local minimum. | 28 ## that @code{@var{fcn} (@var{x})} is a local minimum. |
57 ## @item 0 | 57 ## @item 0 |
58 ## Iteration limit exceeded. | 58 ## Iteration limit exceeded. |
59 ## @item -3 | 59 ## @item -3 |
60 ## The trust region radius became excessively small. | 60 ## The trust region radius became excessively small. |
61 ## @end table | 61 ## @end table |
62 ## | |
63 ## Optionally, fminunc can also yield a structure with convergence statistics | |
64 ## (@var{output}), the output gradient (@var{grad}) and approximate hessian | |
65 ## (@var{hess}). | |
62 ## | 66 ## |
63 ## Note: If you only have a single nonlinear equation of one variable, using | 67 ## Note: If you only have a single nonlinear equation of one variable, using |
64 ## @code{fminbnd} is usually a much better idea. | 68 ## @code{fminbnd} is usually a much better idea. |
65 ## @seealso{fminbnd, optimset} | 69 ## @seealso{fminbnd, optimset} |
66 ## @end deftypefn | 70 ## @end deftypefn |
306 | 310 |
307 output.iterations = niter; | 311 output.iterations = niter; |
308 output.successful = nsuciter; | 312 output.successful = nsuciter; |
309 output.funcCount = nfev; | 313 output.funcCount = nfev; |
310 | 314 |
315 if (nargout > 5) | |
316 hess = hesr'*hesr; | |
317 endif | |
318 | |
311 endfunction | 319 endfunction |
312 | 320 |
313 ## An assistant function that evaluates a function handle and checks for | 321 ## An assistant function that evaluates a function handle and checks for |
314 ## bad results. | 322 ## bad results. |
315 function [fx, gx] = guarded_eval (fun, x) | 323 function [fx, gx] = guarded_eval (fun, x) |