<html lang="en"> <head> <title>Minimizers - GNU Octave</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="GNU Octave"> <meta name="generator" content="makeinfo 4.13"> <link title="Top" rel="start" href="index.html#Top"> <link rel="up" href="Nonlinear-Equations.html#Nonlinear-Equations" title="Nonlinear Equations"> <link rel="prev" href="Solvers.html#Solvers" title="Solvers"> <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"><!-- pre.display { font-family:inherit } pre.format { font-family:inherit } pre.smalldisplay { font-family:inherit; font-size:smaller } pre.smallformat { font-family:inherit; font-size:smaller } pre.smallexample { font-size:smaller } pre.smalllisp { font-size:smaller } span.sc { font-variant:small-caps } span.roman { font-family:serif; font-weight:normal; } span.sansserif { font-family:sans-serif; font-weight:normal; } --></style> </head> <body> <div class="node"> <a name="Minimizers"></a> <p> Previous: <a rel="previous" accesskey="p" href="Solvers.html#Solvers">Solvers</a>, Up: <a rel="up" accesskey="u" href="Nonlinear-Equations.html#Nonlinear-Equations">Nonlinear Equations</a> <hr> </div> <h3 class="section">20.2 Minimizers</h3> <p><a name="index-local-minimum-2170"></a><a name="index-finding-minimums-2171"></a> Often it is useful to find the minimum value of a function rather than just the zeroes where it crosses the x-axis. <code>fminbnd</code> is designed for the simpler, but very common, case of a univariate function where the interval to search is bounded. For unbounded minimization of a function with potentially many variables use <code>fminunc</code>. See <a href="Optimization.html#Optimization">Optimization</a>, for minimization with the presence of constraint functions. Note that searches can be made for maxima by simply inverting the objective function (<code>Fto_max = -Fto_min</code>). <!-- fminbnd scripts/optimization/fminbnd.m --> <p><a name="doc_002dfminbnd"></a> <div class="defun"> — Function File: [<var>x</var>, <var>fval</var>, <var>info</var>, <var>output</var>] = <b>fminbnd</b> (<var>fun, a, b, options</var>)<var><a name="index-fminbnd-2172"></a></var><br> <blockquote><p>Find a minimum point of a univariate function. <var>fun</var> should be a function handle or name. <var>a</var>, <var>b</var> specify a starting interval. <var>options</var> is a structure specifying additional options. Currently, <code>fminbnd</code> recognizes these options: <code>"FunValCheck"</code>, <code>"OutputFcn"</code>, <code>"TolX"</code>, <code>"MaxIter"</code>, <code>"MaxFunEvals"</code>. For description of these options, see <a href="doc_002doptimset.html#doc_002doptimset">optimset</a>. <p>On exit, the function returns <var>x</var>, the approximate minimum point and <var>fval</var>, the function value thereof. <var>info</var> is an exit flag that can have these values: <ul> <li>1 The algorithm converged to a solution. <li>0 Maximum number of iterations or function evaluations has been exhausted. <li>-1 The algorithm has been terminated from user output function. </ul> <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002doptimset.html#doc_002doptimset">optimset</a>, <a href="doc_002dfzero.html#doc_002dfzero">fzero</a>, <a href="doc_002dfminunc.html#doc_002dfminunc">fminunc</a>. </p></blockquote></div> <!-- fminunc scripts/optimization/fminunc.m --> <p><a name="doc_002dfminunc"></a> <div class="defun"> — Function File: <b>fminunc</b> (<var>fcn, x0</var>)<var><a name="index-fminunc-2173"></a></var><br> — Function File: <b>fminunc</b> (<var>fcn, x0, options</var>)<var><a name="index-fminunc-2174"></a></var><br> — Function File: [<var>x</var>, <var>fvec</var>, <var>info</var>, <var>output</var>, <var>grad</var>, <var>hess</var>] = <b>fminunc</b> (<var>fcn, <small class="dots">...</small></var>)<var><a name="index-fminunc-2175"></a></var><br> <blockquote><p>Solve an unconstrained optimization problem defined by the function <var>fcn</var>. <var>fcn</var> should accepts a vector (array) defining the unknown variables, and return the objective function value, optionally with gradient. In other words, this function attempts to determine a vector <var>x</var> such that <var>fcn</var><code> (</code><var>x</var><code>)</code> is a local minimum. <var>x0</var> determines a starting guess. The shape of <var>x0</var> is preserved in all calls to <var>fcn</var>, but otherwise is treated as a column vector. <var>options</var> is a structure specifying additional options. Currently, <code>fminunc</code> recognizes these options: <code>"FunValCheck"</code>, <code>"OutputFcn"</code>, <code>"TolX"</code>, <code>"TolFun"</code>, <code>"MaxIter"</code>, <code>"MaxFunEvals"</code>, <code>"GradObj"</code>, <code>"FinDiffType"</code>, <code>"TypicalX"</code>, <code>"AutoScaling"</code>. <p>If <code>"GradObj"</code> is <code>"on"</code>, it specifies that <var>fcn</var>, called with 2 output arguments, also returns the Jacobian matrix of right-hand sides at the requested point. <code>"TolX"</code> specifies the termination tolerance in the unknown variables, while <code>"TolFun"</code> is a tolerance for equations. Default is <code>1e-7</code> for both <code>"TolX"</code> and <code>"TolFun"</code>. <p>For description of the other options, see <code>optimset</code>. <p>On return, <var>fval</var> contains the value of the function <var>fcn</var> evaluated at <var>x</var>, and <var>info</var> may be one of the following values: <dl> <dt>1<dd>Converged to a solution point. Relative gradient error is less than specified by TolFun. <br><dt>2<dd>Last relative step size was less that TolX. <br><dt>3<dd>Last relative decrease in function value was less than TolF. <br><dt>0<dd>Iteration limit exceeded. <br><dt>-3<dd>The trust region radius became excessively small. </dl> <p>Optionally, fminunc can also yield a structure with convergence statistics (<var>output</var>), the output gradient (<var>grad</var>) and approximate Hessian (<var>hess</var>). <p>Note: If you only have a single nonlinear equation of one variable, using <code>fminbnd</code> is usually a much better idea. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dfminbnd.html#doc_002dfminbnd">fminbnd</a>, <a href="doc_002doptimset.html#doc_002doptimset">optimset</a>. </p></blockquote></div> <!-- DO NOT EDIT! Generated automatically by munge-texi.pl. --> <!-- Copyright (C) 2009-2012 Jaroslav Hajek --> <!-- This file is part of Octave. --> <!-- Octave is free software; you can redistribute it and/or modify it --> <!-- under the terms of the GNU General Public License as published by the --> <!-- Free Software Foundation; either version 3 of the License, or (at --> <!-- your option) any later version. --> <!-- Octave is distributed in the hope that it will be useful, but WITHOUT --> <!-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or --> <!-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --> <!-- for more details. --> <!-- You should have received a copy of the GNU General Public License --> <!-- along with Octave; see the file COPYING. If not, see --> <!-- <http://www.gnu.org/licenses/>. --> </body></html>