<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Bisection</title>
<link rel="stylesheet" href="../../math.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Math Toolkit 3.0.0">
<link rel="up" href="../roots_noderiv.html" title="Root Finding Without Derivatives">
<link rel="prev" href="../roots_noderiv.html" title="Root Finding Without Derivatives">
<link rel="next" href="bracket_solve.html" title="Bracket and Solve Root">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../roots_noderiv.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../roots_noderiv.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="bracket_solve.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="math_toolkit.roots_noderiv.bisect"></a><a class="link" href="bisect.html" title="Bisection">Bisection</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Tol</span><span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">T</span><span class="special">&gt;</span>
   <span class="identifier">bisect</span><span class="special">(</span>  <span class="comment">// Unlimited iterations.</span>
      <span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span>
      <span class="identifier">T</span> <span class="identifier">min</span><span class="special">,</span>
      <span class="identifier">T</span> <span class="identifier">max</span><span class="special">,</span>
      <span class="identifier">Tol</span> <span class="identifier">tol</span><span class="special">);</span>

<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Tol</span><span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">T</span><span class="special">&gt;</span>
   <span class="identifier">bisect</span><span class="special">(</span>  <span class="comment">// Limited iterations.</span>
      <span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span>
      <span class="identifier">T</span> <span class="identifier">min</span><span class="special">,</span>
      <span class="identifier">T</span> <span class="identifier">max</span><span class="special">,</span>
      <span class="identifier">Tol</span> <span class="identifier">tol</span><span class="special">,</span>
      <span class="identifier">boost</span><span class="special">::</span><span class="identifier">uintmax_t</span><span class="special">&amp;</span> <span class="identifier">max_iter</span><span class="special">);</span>

<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Tol</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">T</span><span class="special">&gt;</span>
   <span class="identifier">bisect</span><span class="special">(</span> <span class="comment">// Specified policy.</span>
      <span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span>
      <span class="identifier">T</span> <span class="identifier">min</span><span class="special">,</span>
      <span class="identifier">T</span> <span class="identifier">max</span><span class="special">,</span>
      <span class="identifier">Tol</span> <span class="identifier">tol</span><span class="special">,</span>
      <span class="identifier">boost</span><span class="special">::</span><span class="identifier">uintmax_t</span><span class="special">&amp;</span> <span class="identifier">max_iter</span><span class="special">,</span>
      <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
</pre>
<p>
        These functions locate the root using <a href="https://en.wikipedia.org/wiki/Bisection" target="_top">bisection</a>.
      </p>
<p>
        <code class="computeroutput"><span class="identifier">bisect</span></code> function arguments
        are:
      </p>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">f</span></dt>
<dd><p>
              A unary functor (or C++ lambda) which is the function <span class="emphasis"><em>f(x)</em></span>
              whose root is to be found.
            </p></dd>
<dt><span class="term">min</span></dt>
<dd><p>
              The left bracket of the interval known to contain the root.
            </p></dd>
<dt><span class="term">max</span></dt>
<dd><p>
              The right bracket of the interval known to contain the root.<br>
              It is a precondition that <span class="emphasis"><em>min &lt; max</em></span> and <span class="emphasis"><em>f(min)*f(max)
              &lt;= 0</em></span>, the function raises an <a class="link" href="../error_handling.html#math_toolkit.error_handling.evaluation_error">evaluation_error</a>
              if these preconditions are violated. The action taken on error is controlled
              by the <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a> template argument: the
              default behavior is to throw a <span class="emphasis"><em>boost::math::evaluation_error</em></span>.
              If the <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a> is changed to not throw
              then it returns <span class="emphasis"><em>std::pair&lt;T&gt;(min, min)</em></span>.
            </p></dd>
<dt><span class="term">tol</span></dt>
<dd><p>
              A binary functor (or C++ lambda) that specifies the termination condition:
              the function will return the current brackets enclosing the root when
              <span class="emphasis"><em>tol(min, max)</em></span> becomes true. See also <a class="link" href="root_termination.html" title="Termination Condition Functors">predefined
              termination functors</a>.
            </p></dd>
<dt><span class="term">max_iter</span></dt>
<dd><p>
              The maximum number of invocations of <span class="emphasis"><em>f(x)</em></span> to make
              while searching for the root. On exit, this is updated to the actual
              number of invocations performed.
            </p></dd>
</dl>
</div>
<p>
        The final <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
        be used to control the behaviour of the function: how it handles errors,
        what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">policy
        documentation for more details</a>.
      </p>
<p>
        <span class="bold"><strong>Returns</strong></span>: a pair of values <span class="emphasis"><em>r</em></span>
        that bracket the root so that:
      </p>
<div class="blockquote"><blockquote class="blockquote"><p>
          f(r.first) * f(r.second) &lt;= 0
        </p></blockquote></div>
<p>
        and either
      </p>
<div class="blockquote"><blockquote class="blockquote"><p>
          tol(r.first, r.second) == true
        </p></blockquote></div>
<p>
        or
      </p>
<div class="blockquote"><blockquote class="blockquote"><p>
          max_iter &gt;= m
        </p></blockquote></div>
<p>
        where <span class="emphasis"><em>m</em></span> is the initial value of <span class="emphasis"><em>max_iter</em></span>
        passed to the function.
      </p>
<p>
        In other words, it's up to the caller to verify whether termination occurred
        as a result of exceeding <span class="emphasis"><em>max_iter</em></span> function invocations
        (easily done by checking the updated value of <span class="emphasis"><em>max_iter</em></span>
        when the function returns), rather than because the termination condition
        <span class="emphasis"><em>tol</em></span> was satisfied.
      </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2006-2021 Nikhar Agrawal, Anton Bikineev, Matthew Borland,
      Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert Holin, Bruno
      Lalande, John Maddock, Evan Miller, Jeremy Murphy, Matthew Pulver, Johan Råde,
      Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, Daryle
      Walker and Xiaogang Zhang<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../roots_noderiv.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../roots_noderiv.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="bracket_solve.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>