Mercurial > hg > octave-nkf
comparison scripts/optimization/fminbnd.m @ 11587:c792872f8942
all script files: untabify and strip trailing whitespace
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Jan 2011 17:35:29 -0500 |
parents | fd0a3ac60b0e |
children | b9a89ca0fb75 |
comparison
equal
deleted
inserted
replaced
11586:12df7854fa7c | 11587:c792872f8942 |
---|---|
24 ## function | 24 ## function |
25 ## handle or name. @var{a}, @var{b} specify a starting interval. @var{options} | 25 ## handle or name. @var{a}, @var{b} specify a starting interval. @var{options} |
26 ## is a | 26 ## is a |
27 ## structure specifying additional options. Currently, @code{fminbnd} | 27 ## structure specifying additional options. Currently, @code{fminbnd} |
28 ## recognizes these options: @code{"FunValCheck"}, @code{"OutputFcn"}, | 28 ## recognizes these options: @code{"FunValCheck"}, @code{"OutputFcn"}, |
29 ## @code{"TolX"}, @code{"MaxIter"}, @code{"MaxFunEvals"}. | 29 ## @code{"TolX"}, @code{"MaxIter"}, @code{"MaxFunEvals"}. |
30 ## For description of these options, see @ref{doc-optimset,,optimset}. | 30 ## For description of these options, see @ref{doc-optimset,,optimset}. |
31 ## | 31 ## |
32 ## On exit, the function returns @var{x}, the approximate minimum point | 32 ## On exit, the function returns @var{x}, the approximate minimum point |
33 ## and @var{fval}, the function value thereof. | 33 ## and @var{fval}, the function value thereof. |
34 ## @var{info} is an exit flag that can have these values: | 34 ## @var{info} is an exit flag that can have these values: |
35 ## | 35 ## |
36 ## @itemize | 36 ## @itemize |
41 ## Maximum number of iterations or function evaluations has been exhausted. | 41 ## Maximum number of iterations or function evaluations has been exhausted. |
42 ## | 42 ## |
43 ## @item -1 | 43 ## @item -1 |
44 ## The algorithm has been terminated from user output function. | 44 ## The algorithm has been terminated from user output function. |
45 ## @end itemize | 45 ## @end itemize |
46 ## @seealso{optimset, fzero, fminunc} | 46 ## @seealso{optimset, fzero, fminunc} |
47 ## @end deftypefn | 47 ## @end deftypefn |
48 | 48 |
49 ## This is patterned after opt/fmin.f from Netlib, which in turn is taken from | 49 ## This is patterned after opt/fmin.f from Netlib, which in turn is taken from |
50 ## Richard Brent: Algorithms For Minimization Without Derivatives, Prentice-Hall (1973) | 50 ## Richard Brent: Algorithms For Minimization Without Derivatives, Prentice-Hall (1973) |
51 | 51 |
139 d = c * e; | 139 d = c * e; |
140 endif | 140 endif |
141 | 141 |
142 ## f must not be evaluated too close to x. | 142 ## f must not be evaluated too close to x. |
143 u = x + max (abs (d), tol) * (sign (d) + (d == 0)); | 143 u = x + max (abs (d), tol) * (sign (d) + (d == 0)); |
144 | 144 |
145 fu = fun (u); | 145 fu = fun (u); |
146 nfev++; | 146 nfev++; |
147 niter++; | 147 niter++; |
148 | 148 |
149 ## update a, b, v, w, and x | 149 ## update a, b, v, w, and x |
196 ## bad results. | 196 ## bad results. |
197 function fx = guarded_eval (fun, x) | 197 function fx = guarded_eval (fun, x) |
198 fx = fun (x); | 198 fx = fun (x); |
199 fx = fx(1); | 199 fx = fx(1); |
200 if (! isreal (fx)) | 200 if (! isreal (fx)) |
201 error ("fminbnd:notreal", "fminbnd: non-real value encountered"); | 201 error ("fminbnd:notreal", "fminbnd: non-real value encountered"); |
202 elseif (isnan (fx)) | 202 elseif (isnan (fx)) |
203 error ("fminbnd:isnan", "fminbnd: NaN value encountered"); | 203 error ("fminbnd:isnan", "fminbnd: NaN value encountered"); |
204 endif | 204 endif |
205 endfunction | 205 endfunction |
206 | 206 |
207 %!shared opt0 | 207 %!shared opt0 |
208 %! opt0 = optimset ("tolx", 0); | 208 %! opt0 = optimset ("tolx", 0); |