CalculusWithJuliaNotes.jl/quarto/308797b5/derivatives/more_zeros.html
2022-08-11 13:00:43 -04:00

1932 lines
119 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.0.32">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>Calculus with Julia - 31&nbsp; Derivative-free alternatives to Newtons method</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<script src="../site_libs/quarto-nav/quarto-nav.js"></script>
<script src="../site_libs/quarto-nav/headroom.min.js"></script>
<script src="../site_libs/clipboard/clipboard.min.js"></script>
<script src="../site_libs/quarto-search/autocomplete.umd.js"></script>
<script src="../site_libs/quarto-search/fuse.min.js"></script>
<script src="../site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="../">
<link href="../derivatives/lhospitals_rule.html" rel="next">
<link href="../derivatives/newtons_method.html" rel="prev">
<script src="../site_libs/quarto-html/quarto.js"></script>
<script src="../site_libs/quarto-html/popper.min.js"></script>
<script src="../site_libs/quarto-html/tippy.umd.min.js"></script>
<script src="../site_libs/quarto-html/anchor.min.js"></script>
<link href="../site_libs/quarto-html/tippy.css" rel="stylesheet">
<link href="../site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="../site_libs/bootstrap/bootstrap.min.js"></script>
<link href="../site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="../site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
<script id="quarto-search-options" type="application/json">{
"location": "navbar",
"copy-button": false,
"collapse-after": 3,
"panel-placement": "end",
"type": "overlay",
"limit": 20,
"language": {
"search-no-results-text": "No results",
"search-matching-documents-text": "matching documents",
"search-copy-link-title": "Copy link to search",
"search-hide-matches-text": "Hide additional matches",
"search-more-match-text": "more match in this document",
"search-more-matches-text": "more matches in this document",
"search-clear-button-title": "Clear",
"search-detached-cancel-button-title": "Cancel",
"search-submit-button-title": "Submit"
}
}</script>
<script async="" src="https://hypothes.is/embed.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" integrity="sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script>
<script type="application/javascript">define('jquery', [],function() {return window.jQuery;})</script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js" type="text/javascript"></script>
</head>
<body class="nav-sidebar floating nav-fixed">
<div id="quarto-search-results"></div>
<header id="quarto-header" class="headroom fixed-top">
<nav class="navbar navbar-expand-lg navbar-dark ">
<div class="navbar-container container-fluid">
<a class="navbar-brand" href="../index.html">
<img src="../logo.png" alt="">
<span class="navbar-title">Calculus with Julia</span>
</a>
<div id="quarto-search" class="" title="Search"></div>
</div> <!-- /container-fluid -->
</nav>
<nav class="quarto-secondary-nav" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
<div class="container-fluid d-flex justify-content-between">
<h1 class="quarto-secondary-nav-title"><span class="chapter-number">31</span>&nbsp; <span class="chapter-title">Derivative-free alternatives to Newtons method</span></h1>
<button type="button" class="quarto-btn-toggle btn" aria-label="Show secondary navigation">
<i class="bi bi-chevron-right"></i>
</button>
</div>
</nav>
</header>
<!-- content -->
<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar">
<!-- sidebar -->
<nav id="quarto-sidebar" class="sidebar collapse sidebar-navigation floating overflow-auto">
<div class="mt-2 flex-shrink-0 align-items-center">
<div class="sidebar-search">
<div id="quarto-search" class="" title="Search"></div>
</div>
</div>
<div class="sidebar-menu-container">
<ul class="list-unstyled mt-1">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../index.html" class="sidebar-item-text sidebar-link">Preface</a>
</div>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="false">Precalculus Concepts</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/calculator.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">From calculator to computer</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/variables.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Variables</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/numbers_types.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Number systems</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/logical_expressions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Inequalities, Logical expressions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/vectors.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Vectors</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/ranges.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">6</span>&nbsp; <span class="chapter-title">Ranges and Sets</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">7</span>&nbsp; <span class="chapter-title">Functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">The Graph of a Function</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/transformations.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Function manipulations</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/inversefunctions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">The Inverse of a Function</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/polynomial.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Polynomials</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/polynomial_roots.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">12</span>&nbsp; <span class="chapter-title">Roots of a polynomial</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/polynomials_package.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">13</span>&nbsp; <span class="chapter-title">The Polynomials package</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/rational_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">14</span>&nbsp; <span class="chapter-title">Rational functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/exp_log_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">15</span>&nbsp; <span class="chapter-title">Exponential and logarithmic functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/trig_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">16</span>&nbsp; <span class="chapter-title">Trigonometric functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/julia_overview.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">17</span>&nbsp; <span class="chapter-title">Overview of Julia commands</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" aria-expanded="false">Limits</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-2" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/limits.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">18</span>&nbsp; <span class="chapter-title">Limits</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/limits_extensions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">19</span>&nbsp; <span class="chapter-title">Limits, issues, extensions of the concept</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/continuity.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">20</span>&nbsp; <span class="chapter-title">Continuity</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/intermediate_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">21</span>&nbsp; <span class="chapter-title">Implications of continuity</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="true">Derivatives</a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="true">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-3" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">22</span>&nbsp; <span class="chapter-title">Derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/numeric_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">23</span>&nbsp; <span class="chapter-title">Numeric derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/symbolic_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">24</span>&nbsp; <span class="chapter-title">Symbolic derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/mean_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">25</span>&nbsp; <span class="chapter-title">The mean value theorem for differentiable functions.</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/optimization.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">26</span>&nbsp; <span class="chapter-title">Optimization</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/first_second_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">27</span>&nbsp; <span class="chapter-title">The first and second derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/curve_sketching.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">28</span>&nbsp; <span class="chapter-title">Curve Sketching</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/linearization.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">29</span>&nbsp; <span class="chapter-title">Linearization</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/newtons_method.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">30</span>&nbsp; <span class="chapter-title">Newtons method</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/more_zeros.html" class="sidebar-item-text sidebar-link active"><span class="chapter-number">31</span>&nbsp; <span class="chapter-title">Derivative-free alternatives to Newtons method</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/lhospitals_rule.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">32</span>&nbsp; <span class="chapter-title">LHospitals Rule</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/implicit_differentiation.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">33</span>&nbsp; <span class="chapter-title">Implicit Differentiation</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/related_rates.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">34</span>&nbsp; <span class="chapter-title">Related rates</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/taylor_series_polynomials.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">35</span>&nbsp; <span class="chapter-title">Taylor Polynomials and other Approximating Polynomials</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-4" aria-expanded="false">Integrals</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-4" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-4" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/area.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">36</span>&nbsp; <span class="chapter-title">Area under a curve</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/ftc.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">37</span>&nbsp; <span class="chapter-title">Fundamental Theorem or Calculus</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/substitution.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">38</span>&nbsp; <span class="chapter-title">Substitution</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/integration_by_parts.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">39</span>&nbsp; <span class="chapter-title">Integration By Parts</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/partial_fractions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">40</span>&nbsp; <span class="chapter-title">Partial Fractions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/improper_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">41</span>&nbsp; <span class="chapter-title">Improper Integrals</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/mean_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">42</span>&nbsp; <span class="chapter-title">Mean value theorem for integrals</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/area_between_curves.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">43</span>&nbsp; <span class="chapter-title">Area between two curves</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/center_of_mass.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">44</span>&nbsp; <span class="chapter-title">Center of Mass</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/volumes_slice.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">45</span>&nbsp; <span class="chapter-title">Volumes by slicing</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/arc_length.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">46</span>&nbsp; <span class="chapter-title">Arc length</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/surface_area.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">47</span>&nbsp; <span class="chapter-title">Surface Area</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-5" aria-expanded="false">ODEs</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-5" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-5" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../ODEs/odes.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">48</span>&nbsp; <span class="chapter-title">ODEs</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../ODEs/euler.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">49</span>&nbsp; <span class="chapter-title">Eulers method</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../ODEs/solve.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">50</span>&nbsp; <span class="chapter-title">The problem-algorithm-solve interface</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../ODEs/differential_equations.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">51</span>&nbsp; <span class="chapter-title">The <code>DifferentialEquations</code> suite</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-6" aria-expanded="false">Differential vector calculus</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-6" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-6" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/polar_coordinates.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">52</span>&nbsp; <span class="chapter-title">Polar Coordinates and Curves</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/vectors.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">53</span>&nbsp; <span class="chapter-title">Vectors and matrices</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/vector_valued_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">54</span>&nbsp; <span class="chapter-title">Vector-valued functions, <span class="math inline">\(f:R \rightarrow R^n\)</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/scalar_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">55</span>&nbsp; <span class="chapter-title">Scalar functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/scalar_functions_applications.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">56</span>&nbsp; <span class="chapter-title">Applications with scalar functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/vector_fields.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">57</span>&nbsp; <span class="chapter-title">Functions <span class="math inline">\(R^n \rightarrow R^m\)</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/plots_plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">58</span>&nbsp; <span class="chapter-title">2D and 3D plots in Julia with Plots</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-7" aria-expanded="false">Integral vector calculus</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-7" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-7" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/double_triple_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">59</span>&nbsp; <span class="chapter-title">Multi-dimensional integrals</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/line_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">60</span>&nbsp; <span class="chapter-title">Line and Surface Integrals</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/div_grad_curl.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">61</span>&nbsp; <span class="chapter-title">The Gradient, Divergence, and Curl</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/stokes_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">62</span>&nbsp; <span class="chapter-title">Greens Theorem, Stokes Theorem, and the Divergence Theorem</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/review.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">63</span>&nbsp; <span class="chapter-title">Quick Review of Vector Calculus</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-8" aria-expanded="false">Alternatives</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-8" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-8" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../alternatives/plotly_plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">64</span>&nbsp; <span class="chapter-title">JavaScript based plotting libraries</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../alternatives/makie_plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">65</span>&nbsp; <span class="chapter-title">Calculus plots with Makie</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-9" aria-expanded="false">Appendices</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-9" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-9" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/getting_started_with_julia.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">66</span>&nbsp; <span class="chapter-title">Getting started with Julia</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/julia_interfaces.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">67</span>&nbsp; <span class="chapter-title">Julia interfaces</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/calculus_with_julia.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">68</span>&nbsp; <span class="chapter-title">The <code>CalculusWithJulia</code> package</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/unicode.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">69</span>&nbsp; <span class="chapter-title">Usages of Unicode symbols</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/quick_notes.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">70</span>&nbsp; <span class="chapter-title">Quick introduction to Calculus with Julia</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../references.html" class="sidebar-item-text sidebar-link">References</a>
</div>
</li>
</ul>
</div>
</nav>
<!-- margin-sidebar -->
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
<nav id="TOC" role="doc-toc">
<h2 id="toc-title">Table of contents</h2>
<ul>
<li><a href="#the-find_zerof-x0-function" id="toc-the-find_zerof-x0-function" class="nav-link active" data-scroll-target="#the-find_zerof-x0-function"> <span class="header-section-number">31.1</span> The <code>find_zero(f, x0)</code> function</a></li>
<li><a href="#the-secant-method" id="toc-the-secant-method" class="nav-link" data-scroll-target="#the-secant-method"> <span class="header-section-number">31.2</span> The secant method</a>
<ul class="collapse">
<li><a href="#steffensens-method" id="toc-steffensens-method" class="nav-link" data-scroll-target="#steffensens-method"> <span class="header-section-number">31.2.1</span> Steffensens method</a></li>
</ul></li>
<li><a href="#inverse-quadratic-interpolation" id="toc-inverse-quadratic-interpolation" class="nav-link" data-scroll-target="#inverse-quadratic-interpolation"> <span class="header-section-number">31.3</span> Inverse quadratic interpolation</a></li>
<li><a href="#tolerances" id="toc-tolerances" class="nav-link" data-scroll-target="#tolerances"> <span class="header-section-number">31.4</span> Tolerances</a></li>
<li><a href="#questions" id="toc-questions" class="nav-link" data-scroll-target="#questions"> <span class="header-section-number">31.5</span> Questions</a></li>
</ul>
<div class="toc-actions"><div><i class="bi bi-github"></i></div><div class="action-links"><p><a href="https://github.com/jverzani/CalculusWithJuliaNotes.jl/edit/main/quarto/derivatives/more_zeros.qmd" class="toc-action">Edit this page</a></p><p><a href="https://github.com/jverzani/CalculusWithJuliaNotes.jl/issues/new" class="toc-action">Report an issue</a></p></div></div></nav>
</div>
<!-- main -->
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title d-none d-lg-block"><span class="chapter-number">31</span>&nbsp; <span class="chapter-title">Derivative-free alternatives to Newtons method</span></h1>
</div>
<div class="quarto-title-meta">
</div>
</header>
<p>This section uses these add-on packages:</p>
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">CalculusWithJulia</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">Plots</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">ImplicitEquations</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">Roots</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">SymPy</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<hr>
<p>Newtons method is not the only algorithm of its kind for identifying zeros of a function. In this section we discuss some alternatives.</p>
<section id="the-find_zerof-x0-function" class="level2" data-number="31.1">
<h2 data-number="31.1" class="anchored" data-anchor-id="the-find_zerof-x0-function"><span class="header-section-number">31.1</span> The <code>find_zero(f, x0)</code> function</h2>
<p>The function <code>find_zero</code> from the <code>Roots</code> packages provides several different algorithms for finding a zero of a function, including some a derivative-free algorithms for finding zeros when started with an initial guess. The default method is similar to Newtons method in that only a good initial guess is needed. However, the algorithm, while possibly slower in terms of function evaluations and steps, is engineered to be a bit more robust to the choice of initial estimate than Newtons method. (If it finds a bracket, it will use a bisection algorithm which is guaranteed to converge, but can be slower to do so.) Here we see how to call the function:</p>
<div class="cell" data-execution_count="4">
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x) <span class="op">=</span> <span class="fu">cos</span>(x) <span class="op">-</span> x</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a>x₀ <span class="op">=</span> <span class="fl">1</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="fu">find_zero</span>(f, x₀)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="5">
<pre><code>0.7390851332151607</code></pre>
</div>
</div>
<p>Compare to this related call which uses the bisection method:</p>
<div class="cell" data-execution_count="5">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="fu">find_zero</span>(f, (<span class="fl">0</span>, <span class="fl">1</span>)) <span class="co">## [0,1] must be a bracketing interval</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="6">
<pre><code>0.7390851332151607</code></pre>
</div>
</div>
<p>For this example both give the same answer, but the bisection method is a bit less convenient as a bracketing interval must be pre-specified.</p>
</section>
<section id="the-secant-method" class="level2" data-number="31.2">
<h2 data-number="31.2" class="anchored" data-anchor-id="the-secant-method"><span class="header-section-number">31.2</span> The secant method</h2>
<p>The default <code>find_zero</code> method above uses a secant-like method unless a bracketing method is found. The secant method is historic, dating back over <span class="math inline">\(3000\)</span> years. Here we discuss the secant method in a more general framework.</p>
<p>One way to view Newtons method is through the inverse of <span class="math inline">\(f\)</span> (assuming it exists): if <span class="math inline">\(f(\alpha) = 0\)</span> then <span class="math inline">\(\alpha = f^{-1}(0)\)</span>.</p>
<p>If <span class="math inline">\(f\)</span> has a simple zero at <span class="math inline">\(\alpha\)</span> and is locally invertible (that is some <span class="math inline">\(f^{-1}\)</span> exists) then the update step for Newtons method can be identified with:</p>
<ul>
<li>fitting a polynomial to the local inverse function of <span class="math inline">\(f\)</span> going through through the point <span class="math inline">\((f(x_0),x_0)\)</span>,</li>
<li>and matching the slope of <span class="math inline">\(f\)</span> at the same point.</li>
</ul>
<p>That is, we can write <span class="math inline">\(g(y) = h_0 + h_1 (y-f(x_0))\)</span>. Then <span class="math inline">\(g(f(x_0)) = x_0 = h_0\)</span>, so <span class="math inline">\(h_0 = x_0\)</span>. From <span class="math inline">\(g'(f(x_0)) = 1/f'(x_0)\)</span>, we get <span class="math inline">\(h_1 = 1/f'(x_0)\)</span>. That is, <span class="math inline">\(g(y) = x_0 + (y-f(x_0))/f'(x_0)\)</span>. At <span class="math inline">\(y=0,\)</span> we get the update step <span class="math inline">\(x_1 = g(0) = x_0 - f(x_0)/f'(x_0)\)</span>.</p>
<p>A similar viewpoint can be used to create derivative-free methods.</p>
<p>For example, the <a href="https://en.wikipedia.org/wiki/Secant_method">secant method</a> can be seen as the result of fitting a degree-<span class="math inline">\(1\)</span> polynomial approximation for <span class="math inline">\(f^{-1}\)</span> through two points <span class="math inline">\((f(x_0),x_0)\)</span> and <span class="math inline">\((f(x_1), x_1)\)</span>.</p>
<p>Again, expressing this approximation as <span class="math inline">\(g(y) = h_0 + h_1(y-f(x_1))\)</span> leads to <span class="math inline">\(g(f(x_1)) = x_1 = h_0\)</span>. Substituting <span class="math inline">\(f(x_0)\)</span> gives <span class="math inline">\(g(f(x_0)) = x_0 = x_1 + h_1(f(x_0)-f(x_1))\)</span>. Solving for <span class="math inline">\(h_1\)</span> leads to <span class="math inline">\(h_1=(x_1-x_0)/(f(x_1)-f(x_0))\)</span>. Then <span class="math inline">\(x_2 = g(0) = x_1 + (x_1-x_0)/(f(x_1)-f(x_0)) \cdot f(x_1)\)</span>. This is the first step of the secant method:</p>
<p><span class="math display">\[
x_{n+1} = x_n - f(x_n) \frac{x_n - x_{n-1}}{f(x_n) - f(x_{n-1})}.
\]</span></p>
<p>That is, where the next step of Newtons method comes from the intersection of the tangent line at <span class="math inline">\(x_n\)</span> with the <span class="math inline">\(x\)</span>-axis, the next step of the secant method comes from the intersection of the secant line defined by <span class="math inline">\(x_n\)</span> and <span class="math inline">\(x_{n-1}\)</span> with the <span class="math inline">\(x\)</span> axis. That is, the secant method simply replaces <span class="math inline">\(f'(x_n)\)</span> with the slope of the secant line between <span class="math inline">\(x_n\)</span> and <span class="math inline">\(x_{n-1}\)</span>.</p>
<p>We code the update step as <code>λ2</code>:</p>
<div class="cell" data-execution_count="6">
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="fu">λ2</span>(f0,f1,x0,x1) <span class="op">=</span> x1 <span class="op">-</span> f1 <span class="op">*</span> (x1<span class="op">-</span>x0) <span class="op">/</span> (f1<span class="op">-</span>f0)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="7">
<pre><code>λ2 (generic function with 1 method)</code></pre>
</div>
</div>
<p>Then we can run a few steps to identify the zero of sine starting at <span class="math inline">\(3\)</span> and <span class="math inline">\(4\)</span></p>
<div class="cell" data-hold="true" data-term="true" data-execution_count="7">
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>x0,x1 <span class="op">=</span> <span class="fl">4</span>,<span class="fl">3</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a>f0,f1 <span class="op">=</span> <span class="fu">sin</span>.((x0,x1))</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a><span class="pp">@show</span> x1,f1</span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a>x0,x1 <span class="op">=</span> x1, <span class="fu">λ2</span>(f0,f1,x0,x1)</span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a>f0,f1 <span class="op">=</span> f1, <span class="fu">sin</span>(x1)</span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a><span class="pp">@show</span> x1,f1</span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a>x0,x1 <span class="op">=</span> x1, <span class="fu">λ2</span>(f0,f1,x0,x1)</span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true" tabindex="-1"></a>f0,f1 <span class="op">=</span> f1, <span class="fu">sin</span>(x1)</span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true" tabindex="-1"></a><span class="pp">@show</span> x1,f1</span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true" tabindex="-1"></a>x0,x1 <span class="op">=</span> x1, <span class="fu">λ2</span>(f0,f1,x0,x1)</span>
<span id="cb8-14"><a href="#cb8-14" aria-hidden="true" tabindex="-1"></a>f0,f1 <span class="op">=</span> f1, <span class="fu">sin</span>(x1)</span>
<span id="cb8-15"><a href="#cb8-15" aria-hidden="true" tabindex="-1"></a><span class="pp">@show</span> x1,f1</span>
<span id="cb8-16"><a href="#cb8-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-17"><a href="#cb8-17" aria-hidden="true" tabindex="-1"></a>x0,x1 <span class="op">=</span> x1, <span class="fu">λ2</span>(f0,f1,x0,x1)</span>
<span id="cb8-18"><a href="#cb8-18" aria-hidden="true" tabindex="-1"></a>f0,f1 <span class="op">=</span> f1, <span class="fu">sin</span>(x1)</span>
<span id="cb8-19"><a href="#cb8-19" aria-hidden="true" tabindex="-1"></a>x1,f1</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>(x1, f1) = (3, 0.1411200080598672)
(x1, f1) = (3.157162792479947, -0.015569509788328599)
(x1, f1) = (3.14154625558915, 4.639800062679684e-5)
(x1, f1) = (3.1415926554589646, -1.8691713617942337e-9)</code></pre>
</div>
<div class="cell-output cell-output-display" data-execution_count="8">
<pre><code>(3.141592653589793, 1.2246467991473532e-16)</code></pre>
</div>
</div>
<p>Like Newtons method, the secant method coverges quickly for this problem (though its rate is less than the quadratic rate of Newtons method).</p>
<p>This method is included in <code>Roots</code> as <code>Secant()</code> (or <code>Order1()</code>):</p>
<div class="cell" data-execution_count="8">
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="fu">find_zero</span>(sin, (<span class="fl">4</span>,<span class="fl">3</span>), <span class="fu">Secant</span>())</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="9">
<pre><code>3.141592653589793</code></pre>
</div>
</div>
<p>Though the derivative is related to the slope of the secant line, that is in the limit. The convergence of the secant method is not as fast as Newtons method, though at each step of the secant method, only one new function evaluation is needed, so it can be more efficient for functions that are expensive to compute or differentiate.</p>
<p>Let <span class="math inline">\(\epsilon_{n+1} = x_{n+1}-\alpha\)</span>, where <span class="math inline">\(\alpha\)</span> is assumed to be the <em>simple</em> zero of <span class="math inline">\(f(x)\)</span> that the secant method converges to. A <a href="https://math.okstate.edu/people/binegar/4513-F98/4513-l08.pdf">calculation</a> shows that</p>
<p><span class="math display">\[
\begin{align*}
\epsilon_{n+1} &amp;\approx \frac{x_n-x_{n-1}}{f(x_n)-f(x_{n-1})} \frac{(1/2)f''(\alpha)(e_n-e_{n-1})}{x_n-x_{n-1}} \epsilon_n \epsilon_{n-1}\\
&amp; \approx \frac{f''(\alpha)}{2f'(\alpha)} \epsilon_n \epsilon_{n-1}\\
&amp;= C \epsilon_n \epsilon_{n-1}.
\end{align*}
\]</span></p>
<p>The constant <code>C</code> is similar to that for Newtons method, and reveals potential troubles for the secant method similar to those of Newtons method: a poor initial guess (the initial error is too big), the second derivative is too large, the first derivative too flat near the answer.</p>
<p>Assuming the error term has the form <span class="math inline">\(\epsilon_{n+1} = A|\epsilon_n|^\phi\)</span> and substituting into the above leads to the equation</p>
<p><span class="math display">\[
\frac{A^{1-1/\phi}}{C} = |\epsilon_n|^{1 - \phi +1/\phi}.
\]</span></p>
<p>The left side being a constant suggests <span class="math inline">\(\phi\)</span> solves: <span class="math inline">\(1 - \phi + 1/\phi = 0\)</span> or <span class="math inline">\(\phi^2 -\phi - 1 = 0\)</span>. The solution is the golden ratio, <span class="math inline">\((1 + \sqrt{5})/2 \approx 1.618\dots\)</span>.</p>
<section id="steffensens-method" class="level3" data-number="31.2.1">
<h3 data-number="31.2.1" class="anchored" data-anchor-id="steffensens-method"><span class="header-section-number">31.2.1</span> Steffensens method</h3>
<p>Steffensens method is a secant-like method that converges with <span class="math inline">\(|\epsilon_{n+1}| \approx C |\epsilon_n|^2\)</span>. The secant is taken between the points <span class="math inline">\((x_n,f(x_n))\)</span> and <span class="math inline">\((x_n + f(x_n), f(x_n + f(x_n))\)</span>. Like Newtons method this requires <span class="math inline">\(2\)</span> function evaluations per step. Steffensens is implemented through <code>Roots.Steffensen()</code>. Steffensens method is more sensitive to the initial guess than other methods, so in practice must be used with care, though it is a starting point for many higher-order derivative-free methods.</p>
</section>
</section>
<section id="inverse-quadratic-interpolation" class="level2" data-number="31.3">
<h2 data-number="31.3" class="anchored" data-anchor-id="inverse-quadratic-interpolation"><span class="header-section-number">31.3</span> Inverse quadratic interpolation</h2>
<p>Inverse quadratic interpolation fits a quadratic polynomial through three points, not just two like the Secant method. The third being <span class="math inline">\((f(x_2), x_2)\)</span>.</p>
<p>For example, here is the inverse quadratic function, <span class="math inline">\(g(y)\)</span>, going through three points marked with red dots. The blue dot is found from <span class="math inline">\((g(0), 0)\)</span>.</p>
<div class="cell" data-hold="true" data-execution_count="9">
<div class="cell-output cell-output-display" data-execution_count="10">
<p><img src="more_zeros_files/figure-html/cell-10-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Here we use <code>SymPy</code> to identify the degree-<span class="math inline">\(2\)</span> polynomial as a function of <span class="math inline">\(y\)</span>, then evaluate it at <span class="math inline">\(y=0\)</span> to find the next step:</p>
<div class="cell" data-execution_count="10">
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> y hs[<span class="fl">0</span><span class="op">:</span><span class="fl">2</span>] xs[<span class="fl">0</span><span class="op">:</span><span class="fl">2</span>] fs[<span class="fl">0</span><span class="op">:</span><span class="fl">2</span>]</span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a><span class="fu">H</span>(y) <span class="op">=</span> <span class="fu">sum</span>(<span class="fu">hᵢ*</span>(y <span class="op">-</span> fs[<span class="kw">end</span>])<span class="op">^</span>i <span class="cf">for</span> (hᵢ,i) <span class="op"></span> <span class="fu">zip</span>(hs, <span class="fl">0</span><span class="op">:</span><span class="fl">2</span>))</span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a>eqs <span class="op">=</span> [<span class="fu">H</span>(fᵢ) <span class="op">~</span> xᵢ for (xᵢ, fᵢ) <span class="op"></span> <span class="fu">zip</span>(xs, fs)]</span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a>ϕ <span class="op">=</span> <span class="fu">solve</span>(eqs, hs)</span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a>hy <span class="op">=</span> <span class="fu">subs</span>(<span class="fu">H</span>(y), ϕ)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="11">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
xs₂ + \frac{\left(- fs₂ + y\right)^{2} \left(- fs₀ xs₁ + fs₀ xs₂ + fs₁ xs₀ - fs₁ xs₂ - fs₂ xs₀ + fs₂ xs₁\right)}{fs₀^{2} fs₁ - fs₀^{2} fs₂ - fs₀ fs₁^{2} + fs₀ fs₂^{2} + fs₁^{2} fs₂ - fs₁ fs₂^{2}} + \frac{\left(- fs₂ + y\right) \left(fs₀^{2} xs₁ - fs₀^{2} xs₂ - 2 fs₀ fs₂ xs₁ + 2 fs₀ fs₂ xs₂ - fs₁^{2} xs₀ + fs₁^{2} xs₂ + 2 fs₁ fs₂ xs₀ - 2 fs₁ fs₂ xs₂ - fs₂^{2} xs₀ + fs₂^{2} xs₁\right)}{fs₀^{2} fs₁ - fs₀^{2} fs₂ - fs₀ fs₁^{2} + fs₀ fs₂^{2} + fs₁^{2} fs₂ - fs₁ fs₂^{2}}
\]
</span>
</div>
</div>
<p>The value of <code>hy</code> at <span class="math inline">\(y=0\)</span> yields the next guess based on the past three, and is given by:</p>
<div class="cell" data-execution_count="11">
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a>q⁻¹ <span class="op">=</span> <span class="fu">hy</span>(y <span class="op">=&gt;</span> <span class="fl">0</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="12">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
\frac{fs₂^{2} \left(- fs₀ xs₁ + fs₀ xs₂ + fs₁ xs₀ - fs₁ xs₂ - fs₂ xs₀ + fs₂ xs₁\right)}{fs₀^{2} fs₁ - fs₀^{2} fs₂ - fs₀ fs₁^{2} + fs₀ fs₂^{2} + fs₁^{2} fs₂ - fs₁ fs₂^{2}} - \frac{fs₂ \left(fs₀^{2} xs₁ - fs₀^{2} xs₂ - 2 fs₀ fs₂ xs₁ + 2 fs₀ fs₂ xs₂ - fs₁^{2} xs₀ + fs₁^{2} xs₂ + 2 fs₁ fs₂ xs₀ - 2 fs₁ fs₂ xs₂ - fs₂^{2} xs₀ + fs₂^{2} xs₁\right)}{fs₀^{2} fs₁ - fs₀^{2} fs₂ - fs₀ fs₁^{2} + fs₀ fs₂^{2} + fs₁^{2} fs₂ - fs₁ fs₂^{2}} + xs₂
\]
</span>
</div>
</div>
<p>Though the above can be simplified quite a bit when computed by hand, here we simply make this a function with <code>lambdify</code> which we will use below.</p>
<div class="cell" data-execution_count="12">
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a>λ<span class="fl">3</span> <span class="op">=</span> <span class="fu">lambdify</span>(q⁻¹) <span class="co"># fs, then xs</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="13">
<pre><code>#118 (generic function with 1 method)</code></pre>
</div>
</div>
<p>(<code>SymPy</code>s <code>lambdify</code> function, by default, picks the order of its argument lexicographically, in this case they will be the <code>f</code> values then the <code>x</code> values.)</p>
<p>An inverse quadratic step is utilized by Brents method, as possible, to yield a rapidly convergent bracketing algorithm implemented as a default zero finder in many software languages. <code>Julia</code>s <code>Roots</code> package implements the method in <code>Roots.Brent()</code>. An inverse cubic interpolation is utilized by <a href="https://dl.acm.org/doi/10.1145/210089.210111">Alefeld, Potra, and Shi</a> which gives an asymptotically even more rapidly convergent algorithm then Brents (implemented in <code>Roots.AlefeldPotraShi()</code> and also <code>Roots.A42()</code>). This is used as a finishing step in many cases by the default hybrid <code>Order0()</code> method of <code>find_zero</code>.</p>
<p>In a bracketing algorithm, the next step should reduce the size of the bracket, so the next iterate should be inside the current bracket. However, quadratic convergence does not guarantee this to happen. As such, sometimes a subsitute method must be chosen.</p>
<p><a href="https://www.google.com/books/edition/Computational_Physics/cC-8BAAAQBAJ?hl=en&amp;gbpv=1&amp;pg=PA95&amp;printsec=frontcover">Chandrapatlas</a> method, is a bracketing method utilizing an inverse quadratic step as the centerpiece. The key insight is the test to choose between this inverse quadratic step and a bisection step. This is done in the following based on values of <span class="math inline">\(\xi\)</span> and <span class="math inline">\(\Phi\)</span> defined within:</p>
<div class="cell" data-execution_count="13">
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span> <span class="fu">chandrapatla</span>(f, u, v, λ; verbose<span class="op">=</span><span class="cn">false</span>)</span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a> a,b <span class="op">=</span> <span class="fu">promote</span>(<span class="fu">float</span>(u), <span class="fu">float</span>(v))</span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a> fa,fb <span class="op">=</span> <span class="fu">f</span>(a),<span class="fu">f</span>(b)</span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true" tabindex="-1"></a> <span class="pp">@assert</span> fa <span class="op">*</span> fb <span class="op">&lt;</span> <span class="fl">0</span></span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="fu">abs</span>(fa) <span class="op">&lt;</span> <span class="fu">abs</span>(fb)</span>
<span id="cb17-7"><a href="#cb17-7" aria-hidden="true" tabindex="-1"></a> a,b,fa,fb <span class="op">=</span> b,a,fb,fa</span>
<span id="cb17-8"><a href="#cb17-8" aria-hidden="true" tabindex="-1"></a> <span class="cf">end</span></span>
<span id="cb17-9"><a href="#cb17-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-10"><a href="#cb17-10" aria-hidden="true" tabindex="-1"></a> c, fc <span class="op">=</span> a, fa</span>
<span id="cb17-11"><a href="#cb17-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-12"><a href="#cb17-12" aria-hidden="true" tabindex="-1"></a> maxsteps <span class="op">=</span> <span class="fl">100</span></span>
<span id="cb17-13"><a href="#cb17-13" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> ns <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span>maxsteps</span>
<span id="cb17-14"><a href="#cb17-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-15"><a href="#cb17-15" aria-hidden="true" tabindex="-1"></a> Δ <span class="op">=</span> <span class="fu">abs</span>(b<span class="op">-</span>a)</span>
<span id="cb17-16"><a href="#cb17-16" aria-hidden="true" tabindex="-1"></a> m, fm <span class="op">=</span> (<span class="fu">abs</span>(fa) <span class="op">&lt;</span> <span class="fu">abs</span>(fb)) ? (a, fa) <span class="op">:</span> (b, fb)</span>
<span id="cb17-17"><a href="#cb17-17" aria-hidden="true" tabindex="-1"></a> ϵ <span class="op">=</span> <span class="fu">eps</span>(m)</span>
<span id="cb17-18"><a href="#cb17-18" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> Δ <span class="op"></span> <span class="fl">2</span>ϵ</span>
<span id="cb17-19"><a href="#cb17-19" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> m</span>
<span id="cb17-20"><a href="#cb17-20" aria-hidden="true" tabindex="-1"></a> <span class="cf">end</span></span>
<span id="cb17-21"><a href="#cb17-21" aria-hidden="true" tabindex="-1"></a> <span class="pp">@show</span> m,fm</span>
<span id="cb17-22"><a href="#cb17-22" aria-hidden="true" tabindex="-1"></a> <span class="fu">iszero</span>(fm) <span class="op">&amp;&amp;</span> <span class="cf">return</span> m</span>
<span id="cb17-23"><a href="#cb17-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-24"><a href="#cb17-24" aria-hidden="true" tabindex="-1"></a> ξ <span class="op">=</span> (a<span class="op">-</span>b)<span class="op">/</span>(c<span class="op">-</span>b)</span>
<span id="cb17-25"><a href="#cb17-25" aria-hidden="true" tabindex="-1"></a> Φ <span class="op">=</span> (fa<span class="op">-</span>fb)<span class="op">/</span>(fc<span class="op">-</span>fb)</span>
<span id="cb17-26"><a href="#cb17-26" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-27"><a href="#cb17-27" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> Φ<span class="op">^</span><span class="fl">2</span> <span class="op">&lt;</span> ξ <span class="op">&lt;</span> <span class="fl">1</span> <span class="op">-</span> (<span class="fl">1</span><span class="op">-</span>Φ)<span class="op">^</span><span class="fl">2</span></span>
<span id="cb17-28"><a href="#cb17-28" aria-hidden="true" tabindex="-1"></a> xt <span class="op">=</span> <span class="fu">λ</span>(fa,fc,fb, a,c,b) <span class="co"># inverse quadratic</span></span>
<span id="cb17-29"><a href="#cb17-29" aria-hidden="true" tabindex="-1"></a> <span class="cf">else</span></span>
<span id="cb17-30"><a href="#cb17-30" aria-hidden="true" tabindex="-1"></a> xt <span class="op">=</span> a <span class="op">+</span> (b<span class="op">-</span>a)<span class="op">/</span><span class="fl">2</span></span>
<span id="cb17-31"><a href="#cb17-31" aria-hidden="true" tabindex="-1"></a> <span class="cf">end</span></span>
<span id="cb17-32"><a href="#cb17-32" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-33"><a href="#cb17-33" aria-hidden="true" tabindex="-1"></a> ft <span class="op">=</span> <span class="fu">f</span>(xt)</span>
<span id="cb17-34"><a href="#cb17-34" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-35"><a href="#cb17-35" aria-hidden="true" tabindex="-1"></a> <span class="fu">isnan</span>(ft) <span class="op">&amp;&amp;</span> <span class="cf">break</span></span>
<span id="cb17-36"><a href="#cb17-36" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-37"><a href="#cb17-37" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="fu">sign</span>(fa) <span class="op">==</span> <span class="fu">sign</span>(ft)</span>
<span id="cb17-38"><a href="#cb17-38" aria-hidden="true" tabindex="-1"></a> c,fc <span class="op">=</span> a,fa</span>
<span id="cb17-39"><a href="#cb17-39" aria-hidden="true" tabindex="-1"></a> a,fa <span class="op">=</span> xt,ft</span>
<span id="cb17-40"><a href="#cb17-40" aria-hidden="true" tabindex="-1"></a> <span class="cf">else</span></span>
<span id="cb17-41"><a href="#cb17-41" aria-hidden="true" tabindex="-1"></a> c,b,a <span class="op">=</span> b,a,xt</span>
<span id="cb17-42"><a href="#cb17-42" aria-hidden="true" tabindex="-1"></a> fc,fb,fa <span class="op">=</span> fb,fa,ft</span>
<span id="cb17-43"><a href="#cb17-43" aria-hidden="true" tabindex="-1"></a> <span class="cf">end</span></span>
<span id="cb17-44"><a href="#cb17-44" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-45"><a href="#cb17-45" aria-hidden="true" tabindex="-1"></a> verbose <span class="op">&amp;&amp;</span> <span class="pp">@show</span> ns, a, fa</span>
<span id="cb17-46"><a href="#cb17-46" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-47"><a href="#cb17-47" aria-hidden="true" tabindex="-1"></a> <span class="cf">end</span></span>
<span id="cb17-48"><a href="#cb17-48" aria-hidden="true" tabindex="-1"></a> <span class="fu">error</span>(<span class="st">"no convergence: [a,b] = </span><span class="sc">$</span>(<span class="fu">sort</span>([a,b]))<span class="st">"</span>)</span>
<span id="cb17-49"><a href="#cb17-49" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="14">
<pre><code>chandrapatla (generic function with 1 method)</code></pre>
</div>
</div>
<p>Like bisection, this method ensures that <span class="math inline">\(a\)</span> and <span class="math inline">\(b\)</span> is a bracket, but it moves <span class="math inline">\(a\)</span> to the newest estimate, so does not maintain that <span class="math inline">\(a &lt; b\)</span> throughout.</p>
<p>We can see it in action on the sine function. Here we pass in <span class="math inline">\(\lambda\)</span>, but in a real implementation (as in <code>Roots.Chandrapatla()</code>) we would have programmed the algorithm to compute the inverse quadratic value.</p>
<div class="cell" data-term="true" data-execution_count="14">
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="fu">chandrapatla</span>(sin, <span class="fl">3</span>, <span class="fl">4</span>, λ<span class="fl">3</span>, verbose<span class="op">=</span><span class="cn">true</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>(m, fm) = (3.0, 0.1411200080598672)
(ns, a, fa) = (1, 3.5, -0.35078322768961984)
(m, fm) = (3.0, 0.1411200080598672)
(ns, a, fa) = </code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>(2, 3.1315894157911264, 0.010003070970892524)
(m, fm) = (3.1315894157911264, 0.010003070970892524)
(ns, a, fa) = (3, 3.141678836157296, -8.618256739611538e-5)
(m, fm) = (3.141678836157296, -8.618256739611538e-5)
(ns, a, fa) = (4, 3.141592600257386, 5.3332407057633926e-8)
(m, fm) = (3.141592600257386, 5.3332407057633926e-8)
(ns, a, fa) = (5, 3.1415926535898007, -7.42705188753633e-15)
(m, fm) = (3.1415926535898007, -7.42705188753633e-15)
(ns, a, fa) = (6, 3.141592653589793, 1.2246467991473532e-16)
(m, fm) = (3.141592653589793, 1.2246467991473532e-16)
(ns, a, fa) = (7, 3.1415926535897936, -3.216245299353273e-16)</code></pre>
</div>
<div class="cell-output cell-output-display" data-execution_count="15">
<pre><code>3.141592653589793</code></pre>
</div>
</div>
<p>The condition <code>Φ^2 &lt; ξ &lt; 1 - (1-Φ)^2</code> can be visualized. Assume <code>a,b=0,1</code>, <code>fa,fb=-1/2,1</code>, Then <code>c &lt; a &lt; b</code>, and <code>fc</code> has the same sign as <code>fa</code>, but what values of <code>fc</code> will satisfy the inequality?</p>
<div class="cell" data-execution_count="15">
<div class="sourceCode cell-code" id="cb23"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ξ</span>(c,fc) <span class="op">=</span> (a<span class="op">-</span>b)<span class="op">/</span>(c<span class="op">-</span>b)</span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a><span class="fu">Φ</span>(c,fc) <span class="op">=</span> (fa<span class="op">-</span>fb)<span class="op">/</span>(fc<span class="op">-</span>fb)</span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a><span class="fu">Φl</span>(c,fc) <span class="op">=</span> <span class="fu">Φ</span>(c,fc)<span class="op">^</span><span class="fl">2</span></span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a><span class="fu">Φr</span>(c,fc) <span class="op">=</span> <span class="fl">1</span> <span class="op">-</span> (<span class="fl">1</span><span class="fu"></span>(c,fc))<span class="op">^</span><span class="fl">2</span></span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true" tabindex="-1"></a>a,b <span class="op">=</span> <span class="fl">0</span>, <span class="fl">1</span></span>
<span id="cb23-6"><a href="#cb23-6" aria-hidden="true" tabindex="-1"></a>fa,fb <span class="op">=</span> <span class="op">-</span><span class="fl">1</span><span class="op">/</span><span class="fl">2</span>, <span class="fl">1</span></span>
<span id="cb23-7"><a href="#cb23-7" aria-hidden="true" tabindex="-1"></a>region <span class="op">=</span> <span class="fu">Lt</span>(Φl, ξ) <span class="op">&amp;</span> <span class="fu">Lt</span>(ξ,Φr)</span>
<span id="cb23-8"><a href="#cb23-8" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(region, xlims<span class="op">=</span>(<span class="op">-</span><span class="fl">2</span>,a), ylims<span class="op">=</span>(<span class="op">-</span><span class="fl">3</span>,<span class="fl">0</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="16">
<p><img src="more_zeros_files/figure-html/cell-16-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>When <code>(c,fc)</code> is in the shaded area, the inverse quadratic step is chosen. We can see that <code>fc &lt; fa</code> is needed.</p>
<p>For these values, this area is within the area where a implicit quadratic step will result in a value between <code>a</code> and <code>b</code>:</p>
<div class="cell" data-execution_count="16">
<div class="sourceCode cell-code" id="cb24"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a><span class="fu">l</span>(c,fc) <span class="op">=</span> <span class="fu">λ3</span>(fa,fb,fc,a,b,c)</span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a>region₃ <span class="op">=</span> ImplicitEquations.<span class="fu">Lt</span>(l,b) <span class="op">&amp;</span> ImplicitEquations.<span class="fu">Gt</span>(l,a)</span>
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(region₃, xlims<span class="op">=</span>(<span class="op">-</span><span class="fl">2</span>,<span class="fl">0</span>), ylims<span class="op">=</span>(<span class="op">-</span><span class="fl">3</span>,<span class="fl">0</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="17">
<p><img src="more_zeros_files/figure-html/cell-17-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>There are values in the parameter space where this does not occur.</p>
</section>
<section id="tolerances" class="level2" data-number="31.4">
<h2 data-number="31.4" class="anchored" data-anchor-id="tolerances"><span class="header-section-number">31.4</span> Tolerances</h2>
<p>The <code>chandrapatla</code> algorithm typically waits until <code>abs(b-a) &lt;= 2eps(m)</code> (where <span class="math inline">\(m\)</span> is either <span class="math inline">\(b\)</span> or <span class="math inline">\(a\)</span> depending on the size of <span class="math inline">\(f(a)\)</span> and <span class="math inline">\(f(b)\)</span>) is satisfied. Informally this means the algorithm stops when the two bracketing values are no more than a small amount apart. What is a “small amount?”</p>
<p>To understand, we start with the fact that floating point numbers are an approximation to real numbers.</p>
<p>Floating point numbers effectively represent a number in scientific notation in terms of</p>
<ul>
<li>a sign (plus or minus) ,</li>
<li>a <em>mantissa</em> (a number in <span class="math inline">\([1,2)\)</span>, in binary ), and</li>
<li>an exponent (to represent a power of <span class="math inline">\(2\)</span>).</li>
</ul>
<p>The mantissa is of the form <code>1.xxxxx...xxx</code> where there are <span class="math inline">\(m\)</span> different <code>x</code>s each possibly a <code>0</code> or <code>1</code>. The <code>i</code>th <code>x</code> indicates if the term <code>1/2^i</code> should be included in the value. The mantissa is the sum of <code>1</code> plus the indicated values of <code>1/2^i</code> for <code>i</code> in <code>1</code> to <code>m</code>. So the last <code>x</code> represents if <code>1/2^m</code> should be included in the sum. As such, the mantissa represents a discrete set of values, separated by <code>1/2^m</code>, as that is the smallest difference possible.</p>
<p>For example if <code>m=2</code> then the possible value for the mantissa are <code>11 =&gt; 1 + 1/2 + 1/4 = 7/4</code>, <code>10 =&gt; 1 + 1/2 = 6/4</code>, <code>01 =&gt; 1 + 1/4 = 5/4</code>. and <code>00 =&gt; 1 = 4/4</code>, values separated by <code>1/4 = 1/2^m</code>.</p>
<p>For <span class="math inline">\(64\)</span>-bit floating point numbers <code>m=52</code>, so the values in the mantissa differ by <code>1/2^52 = 2.220446049250313e-16</code>. This is the value of <code>eps()</code>.</p>
<p>However, this “gap” between numbers is for values when the exponent is <code>0</code>. That is the numbers in <code>[1,2)</code>. For values in <code>[2,4)</code> the gap is twice, between <code>[1/2,1)</code> the gap is half. That is the gap depends on the size of the number. The gap between <code>x</code> and its next largest floating point number is given by <code>eps(x)</code> and that always satisfies <code>eps(x) &lt;= eps() * abs(x)</code>.</p>
<p>One way to think about this is the difference between <code>x</code> and the next largest floating point values is <em>basically</em> <code>x*(1+eps()) - x</code> or <code>x*eps()</code>.</p>
<p>For the specific example, <code>abs(b-a) &lt;= 2eps(m)</code> means that the gap between <code>a</code> and <code>b</code> is essentially 2 floating point values from the <span class="math inline">\(x\)</span> value with the smallest <span class="math inline">\(f(x)\)</span> value.</p>
<p>For bracketing methods that is about as good as you can get. However, once floating values are understood, the absolute best you can get for a bracketing interval would be</p>
<ul>
<li>along the way, a value <code>f(c)</code> is found which is <em>exactly</em> <code>0.0</code></li>
<li>the endpoints of the bracketing interval are <em>adjacent</em> floating point values, meaning the interval can not be bisected and <code>f</code> changes sign between the two values.</li>
</ul>
<p>There can be problems when the stopping criteria is <code>abs(b-a) &lt;= 2eps(m))</code> and the answer is <code>0.0</code> that require engineering around. For example, the algorithm above for the function <code>f(x) = -40*x*exp(-x)</code> does not converge when started with <code>[-9,1]</code>, even though <code>0.0</code> is an obvious zero.</p>
<div class="cell" data-hold="true" data-execution_count="17">
<div class="sourceCode cell-code" id="cb25"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="fu">fu</span>(x) <span class="op">=</span> <span class="fu">-40*x*exp</span>(<span class="op">-</span>x)</span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a><span class="fu">chandrapatla</span>(fu, <span class="op">-</span><span class="fl">9</span>, <span class="fl">1</span>, λ<span class="fl">3</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>(m, fm) = (1.0, -14.715177646857693)
(m, fm) = (1.0, -14.715177646857693)
(m, fm) = (1.0, -14.715177646857693)
(m, fm) = (-0.25, 12.840254166877415)
(m, fm) = (0.375, -10.309339181864583)
(m, fm) = (0.0625, -2.3485326570336893)
(m, fm) = (-0.010153633209987412, 0.41029018616686774)
(m, fm) = (0.00020479607707152292, -0.008190165597310655)
(m, fm) = (-2.0313182169488797e-7, 8.125274518297165e-6)
(m, fm) = (6.287189464795201e-13, -2.5148757859164994e-11)
(m, fm) = (-5.293955920339377e-23, 2.117582368135751e-21)
(m, fm) = (1.0097419586828951e-28, -4.0389678347315804e-27)
(m, fm) = (-5.877471754111438e-39, 2.350988701644575e-37)
(m, fm) = (1.1210387714598537e-44, -4.484155085839415e-43)
(m, fm) = (-6.525304467998525e-55, 2.61012178719941e-53)
(m, fm) = (1.2446030555722283e-60, -4.978412222288913e-59)
(m, fm) = (-7.24454326306137e-71, 2.897817305224548e-69)
(m, fm) = (1.3817869688151111e-76, -5.527147875260445e-75)
(m, fm) = (-8.043058733543795e-87, 3.217223493417518e-85)
(m, fm) = (1.5340917079055395e-92, -6.136366831622158e-91)
(m, fm) = (-8.929588994392773e-103, 3.5718355977571093e-101)
(m, fm) = (1.7031839360032603e-108, -6.812735744013041e-107)
(m, fm) = (-9.913835302014255e-119, 3.965534120805702e-117)
(m, fm) = (1.8909140209225187e-124, -7.563656083690075e-123)</code></pre>
</div>
<div class="cell-output cell-output-error">
<pre><code>LoadError: no convergence: [a,b] = [-9.913835302014255e-119, 1.8909140209225187e-124]</code></pre>
</div>
</div>
<p>Here the issue is <code>abs(b-a)</code> is tiny (of the order <code>1e-119</code>) but <code>eps(m)</code> is even smaller.</p>
<p>For non-bracketing methods, like Newtons method or the secant method, different criteria are useful. There may not be a bracketing interval for <code>f</code> (for example <code>f(x) = (x-1)^2</code>) so the second criteria above might need to be restated in terms of the last two iterates, <span class="math inline">\(x_n\)</span> and <span class="math inline">\(x_{n-1}\)</span>. Calling this difference <span class="math inline">\(\Delta = |x_n - x_{n-1}|\)</span>, we might stop if <span class="math inline">\(\Delta\)</span> is small enough. As there are scenarios where this can happen, but the function is not at a zero, a check on the size of <span class="math inline">\(f\)</span> is needed.</p>
<p>However, there may be no floating point value where <span class="math inline">\(f\)</span> is exactly <code>0.0</code> so checking the size of <code>f(x_n)</code> requires some agreement.</p>
<p>First if <code>f(x_n)</code> is <code>0.0</code> then it makes sense to call <code>x_n</code> an <em>exact zero</em> of <span class="math inline">\(f\)</span>, even though this may hold even if <code>x_n</code>, a floating point value, is not mathematically an <em>exact</em> zero of <span class="math inline">\(f\)</span>. (Consider <code>f(x) = x^2 - 2x + 1</code>. Mathematically, this is identical to <code>g(x) = (x-1)^2</code>, but <code>f(1 + eps())</code> is zero, while <code>g(1+eps())</code> is <code>4.930380657631324e-32</code>.</p>
<p>However, there may never be a value with <code>f(x_n)</code> exactly <code>0.0</code>. (The value of <code>sin(pi)</code> is not zero, for example, as <code>pi</code> is an approximation to <span class="math inline">\(\pi\)</span>, as well the <code>sin</code> of values adjacent to <code>float(pi)</code> do not produce <code>0.0</code> exactly.)</p>
<p>Suppose <code>x_n</code> is the closest floating number to <span class="math inline">\(\alpha\)</span>, the zero. Then the relative rounding error, <span class="math inline">\((\)</span> <code>x_n</code> <span class="math inline">\(- \alpha)/\alpha\)</span>, will be a value <span class="math inline">\((1 + \delta)\)</span> with <span class="math inline">\(\delta\)</span> less than <code>eps()</code>.</p>
<p>How far then can <code>f(x_n)</code> be from <span class="math inline">\(0 = f(\alpha)\)</span>?</p>
<p><span class="math display">\[
f(x_n) = f(x_n - \alpha + \alpha) = f(\alpha + \alpha \cdot \delta) = f(\alpha \cdot (1 + \delta)),
\]</span></p>
<p>Assuming <span class="math inline">\(f\)</span> has a derivative, the linear approximation gives:</p>
<p><span class="math display">\[
f(x_n) \approx f(\alpha) + f'(\alpha) \cdot (\alpha\delta) = f'(\alpha) \cdot \alpha \delta
\]</span></p>
<p>So we should consider <code>f(x_n)</code> an <em>approximate zero</em> when it is on the scale of <span class="math inline">\(f'(\alpha) \cdot \alpha \delta\)</span>.</p>
<p>That <span class="math inline">\(\alpha\)</span> factor means we consider a <em>relative</em> tolerance for <code>f</code>. Also important when <code>x_n</code> is close to <code>0</code>, is the need for an <em>absolute</em> tolerance, one not dependent on the size of <code>x</code>. So a good condition to check if <code>f(x_n)</code> is small is</p>
<p><code>abs(f(x_n)) &lt;= abs(x_n) * rtol + atol</code>, or <code>abs(f(x_n)) &lt;= max(abs(x_n) * rtol, atol)</code></p>
<p>where the relative tolerance, <code>rtol</code>, would absorb an estimate for <span class="math inline">\(f'(\alpha)\)</span>.</p>
<p>Now, in Newtons method the update step is <span class="math inline">\(f(x_n)/f'(x_n)\)</span>. Naturally when <span class="math inline">\(f(x_n)\)</span> is close to <span class="math inline">\(0\)</span>, the update step is small and <span class="math inline">\(\Delta\)</span> will be close to <span class="math inline">\(0\)</span>. <em>However</em>, should <span class="math inline">\(f'(x_n)\)</span> be large, then <span class="math inline">\(\Delta\)</span> can also be small and the algorithm will possibly stop, as <span class="math inline">\(x_{n+1} \approx x_n\)</span> but not necessarily <span class="math inline">\(x_{n+1} \approx \alpha\)</span>. So termination on <span class="math inline">\(\Delta\)</span> alone can be off. Checking if <span class="math inline">\(f(x_{n+1})\)</span> is an approximate zero is also useful to include in a stopping criteria.</p>
<p>One thing to keep in mind is that the right-hand side of the rule <code>abs(f(x_n)) &lt;= abs(x_n) * rtol + atol</code>, as a function of <code>x_n</code>, goes to <code>Inf</code> as <code>x_n</code> increases. So if <code>f</code> has <code>0</code> as an asymptote (like <code>e^(-x)</code>) for large enough <code>x_n</code>, the rule will be <code>true</code> and <code>x_n</code> could be counted as an approximate zero, despite it not being one.</p>
<p>So a modified criteria for convergence might look like:</p>
<ul>
<li>stop if <span class="math inline">\(\Delta\)</span> is small and <code>f</code> is an approximate zero with some tolerances</li>
<li>stop if <code>f</code> is an approximate zero with some tolerances, but be mindful that this rule can identify mathematically erroneous answers.</li>
</ul>
<p>It is not uncommon to assign <code>rtol</code> to have a value like <code>sqrt(eps())</code> to account for accumulated floating point errors and the factor of <span class="math inline">\(f'(\alpha)\)</span>, though in the <code>Roots</code> package it is set smaller by default.</p>
</section>
<section id="questions" class="level2" data-number="31.5">
<h2 data-number="31.5" class="anchored" data-anchor-id="questions"><span class="header-section-number">31.5</span> Questions</h2>
<section id="question" class="level6">
<h6 class="anchored" data-anchor-id="question">Question</h6>
<p>Let <code>f(x) = tanh(x)</code> (the hyperbolic tangent) and <code>fp(x) = sech(x)^2</code>, its derivative.</p>
<p>Does <em>Newtons</em> method (using <code>Roots.Newton()</code>) converge starting at <code>1.0</code>?</p>
<div class="cell" data-hold="true" data-execution_count="18">
<div class="cell-output cell-output-display" data-execution_count="19">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="11371602144363402754" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_11371602144363402754">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_11371602144363402754_1">
<input class="form-check-input" type="radio" name="radio_11371602144363402754" id="radio_11371602144363402754_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_11371602144363402754_2">
<input class="form-check-input" type="radio" name="radio_11371602144363402754" id="radio_11371602144363402754_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="11371602144363402754_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_11371602144363402754"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('11371602144363402754_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_11371602144363402754")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_11371602144363402754")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Does <em>Newtons</em> method (using <code>Roots.Newton()</code>) converge starting at <code>1.3</code>?</p>
<div class="cell" data-hold="true" data-execution_count="19">
<div class="cell-output cell-output-display" data-execution_count="20">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="6060012710597836987" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_6060012710597836987">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_6060012710597836987_1">
<input class="form-check-input" type="radio" name="radio_6060012710597836987" id="radio_6060012710597836987_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6060012710597836987_2">
<input class="form-check-input" type="radio" name="radio_6060012710597836987" id="radio_6060012710597836987_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="6060012710597836987_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_6060012710597836987"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('6060012710597836987_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_6060012710597836987")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_6060012710597836987")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Does the secant method (using <code>Roots.Secant()</code>) converge starting at <code>1.3</code>? (a second starting value will automatically be chosen, if not directly passed in.)</p>
<div class="cell" data-hold="true" data-execution_count="20">
<div class="cell-output cell-output-display" data-execution_count="21">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="9179962295818497011" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_9179962295818497011">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_9179962295818497011_1">
<input class="form-check-input" type="radio" name="radio_9179962295818497011" id="radio_9179962295818497011_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_9179962295818497011_2">
<input class="form-check-input" type="radio" name="radio_9179962295818497011" id="radio_9179962295818497011_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="9179962295818497011_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_9179962295818497011"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('9179962295818497011_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_9179962295818497011")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_9179962295818497011")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-1" class="level6">
<h6 class="anchored" data-anchor-id="question-1">Question</h6>
<p>For the function <code>f(x) = x^5 - x - 1</code> both Newtons method and the secant method will converge to the one root when started from <code>1.0</code>. Using <code>verbose=true</code> as an argument to <code>find_zero</code>, (e.g., <code>find_zero(f, x0, Roots.Secant(), verbose=true)</code>) how many <em>more</em> steps does the secant method need to converge?</p>
<div class="cell" data-hold="true" data-execution_count="21">
<div class="cell-output cell-output-display" data-execution_count="22">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="1540853211064619286" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_1540853211064619286">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="1540853211064619286" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="1540853211064619286_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("1540853211064619286").addEventListener("change", function() {
var correct = (Math.abs(this.value - 2) <= 0);
var msgBox = document.getElementById('1540853211064619286_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_1540853211064619286")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_1540853211064619286")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>Do the two methods converge to the exact same value?</p>
<div class="cell" data-hold="true" data-execution_count="22">
<div class="cell-output cell-output-display" data-execution_count="23">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="9748856647403496577" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_9748856647403496577">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_9748856647403496577_1">
<input class="form-check-input" type="radio" name="radio_9748856647403496577" id="radio_9748856647403496577_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_9748856647403496577_2">
<input class="form-check-input" type="radio" name="radio_9748856647403496577" id="radio_9748856647403496577_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="9748856647403496577_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_9748856647403496577"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('9748856647403496577_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_9748856647403496577")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_9748856647403496577")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-2" class="level6">
<h6 class="anchored" data-anchor-id="question-2">Question</h6>
<p>Let <code>f(x) = exp(x) - x^4</code> and <code>x0=8.0</code>. How many steps (iterations) does it take for the secant method to converge using the default tolerances?</p>
<div class="cell" data-hold="true" data-execution_count="23">
<div class="cell-output cell-output-display" data-execution_count="24">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="14585497194002695485" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_14585497194002695485">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="14585497194002695485" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="14585497194002695485_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("14585497194002695485").addEventListener("change", function() {
var correct = (Math.abs(this.value - 10) <= 1);
var msgBox = document.getElementById('14585497194002695485_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_14585497194002695485")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_14585497194002695485")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
</section>
<section id="question-3" class="level6">
<h6 class="anchored" data-anchor-id="question-3">Question</h6>
<p>Let <code>f(x) = exp(x) - x^4</code> and a starting bracket be <code>x0 = [8.9]</code>. Then calling <code>find_zero(f,x0, verbose=true)</code> will show that 49 steps are needed for exact bisection to converge. What about with the <code>Roots.Brent()</code> algorithm, which uses inverse quadratic steps when it can?</p>
<p>It takes how many steps?</p>
<div class="cell" data-hold="true" data-execution_count="24">
<div class="cell-output cell-output-display" data-execution_count="25">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="11765006178499981915" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_11765006178499981915">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="11765006178499981915" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="11765006178499981915_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("11765006178499981915").addEventListener("change", function() {
var correct = (Math.abs(this.value - 36) <= 1);
var msgBox = document.getElementById('11765006178499981915_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_11765006178499981915")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_11765006178499981915")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>The <code>Roots.A42()</code> method uses inverse cubic interpolation, as possible, how many steps does this method take to converge?</p>
<div class="cell" data-hold="true" data-execution_count="25">
<div class="cell-output cell-output-display" data-execution_count="26">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="5079333651225182582" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_5079333651225182582">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="5079333651225182582" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="5079333651225182582_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("5079333651225182582").addEventListener("change", function() {
var correct = (Math.abs(this.value - 3) <= 1);
var msgBox = document.getElementById('5079333651225182582_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_5079333651225182582")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_5079333651225182582")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>The large difference is due to how the tolerances are set within <code>Roots</code>. The `Brent method gets pretty close in a few steps, but takes a much longer time to get close enough for the default tolerances</p>
</section>
<section id="question-4" class="level6">
<h6 class="anchored" data-anchor-id="question-4">Question</h6>
<p>Consider this crazy function defined by:</p>
<div class="sourceCode cell-code" id="cb28"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x) <span class="op">=</span> <span class="fu">cos</span>(<span class="fl">100</span><span class="op">*</span>x)<span class="fu">-4*erf</span>(<span class="fl">30</span><span class="op">*</span>x<span class="op">-</span><span class="fl">10</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>(The <code>erf</code> function is the (error function](https://en.wikipedia.org/wiki/Error_function) and is in the <code>SpecialFunctions</code> package loaded with <code>CalculusWithJulia</code>.)</p>
<p>Make a plot over the interval <span class="math inline">\([-3,3]\)</span> to see why it is called “crazy”.</p>
<p>Does <code>find_zero</code> find a zero to this function starting from <span class="math inline">\(0\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="27">
<div class="cell-output cell-output-display" data-execution_count="27">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12360102401741982395" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_12360102401741982395">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_12360102401741982395_1">
<input class="form-check-input" type="radio" name="radio_12360102401741982395" id="radio_12360102401741982395_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12360102401741982395_2">
<input class="form-check-input" type="radio" name="radio_12360102401741982395" id="radio_12360102401741982395_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="12360102401741982395_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_12360102401741982395"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('12360102401741982395_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_12360102401741982395")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_12360102401741982395")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>If so, what is the value?</p>
<div class="cell" data-hold="true" data-execution_count="28">
<div class="cell-output cell-output-display" data-execution_count="28">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15108058063098564890" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_15108058063098564890">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="15108058063098564890" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="15108058063098564890_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("15108058063098564890").addEventListener("change", function() {
var correct = (Math.abs(this.value - 0.3318660335745625) <= 0.001);
var msgBox = document.getElementById('15108058063098564890_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_15108058063098564890")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_15108058063098564890")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>If not, what is the reason?</p>
<div class="cell" data-hold="true" data-execution_count="29">
<div class="cell-output cell-output-display" data-execution_count="29">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="3570793413642086069" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_3570793413642086069">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_3570793413642086069_1">
<input class="form-check-input" type="radio" name="radio_3570793413642086069" id="radio_3570793413642086069_1" value="1">
<span class="label-body px-1">
The zero is a simple zero
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_3570793413642086069_2">
<input class="form-check-input" type="radio" name="radio_3570793413642086069" id="radio_3570793413642086069_2" value="2">
<span class="label-body px-1">
The zero is not a simple zero
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_3570793413642086069_3">
<input class="form-check-input" type="radio" name="radio_3570793413642086069" id="radio_3570793413642086069_3" value="3">
<span class="label-body px-1">
The function oscillates too much to rely on the tangent line approximation far from the zero
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_3570793413642086069_4">
<input class="form-check-input" type="radio" name="radio_3570793413642086069" id="radio_3570793413642086069_4" value="4">
<span class="label-body px-1">
We can find an answer
</span>
</label>
</div>
</div>
</div>
<div id="3570793413642086069_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_3570793413642086069"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 4;
var msgBox = document.getElementById('3570793413642086069_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_3570793413642086069")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_3570793413642086069")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Does <code>find_zero</code> find a zero to this function starting from <span class="math inline">\(1\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="30">
<div class="cell-output cell-output-display" data-execution_count="30">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="16948019199106596956" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_16948019199106596956">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_16948019199106596956_1">
<input class="form-check-input" type="radio" name="radio_16948019199106596956" id="radio_16948019199106596956_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_16948019199106596956_2">
<input class="form-check-input" type="radio" name="radio_16948019199106596956" id="radio_16948019199106596956_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="16948019199106596956_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_16948019199106596956"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('16948019199106596956_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_16948019199106596956")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_16948019199106596956")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>If so, what is the value?</p>
<div class="cell" data-hold="true" data-execution_count="31">
<div class="cell-output cell-output-display" data-execution_count="31">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15382145660030370545" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_15382145660030370545">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="15382145660030370545" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="15382145660030370545_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("15382145660030370545").addEventListener("change", function() {
var correct = (Math.abs(this.value - -999.999) <= 0.001);
var msgBox = document.getElementById('15382145660030370545_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_15382145660030370545")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_15382145660030370545")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>If not, what is the reason?</p>
<div class="cell" data-hold="true" data-execution_count="32">
<div class="cell-output cell-output-display" data-execution_count="32">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="13832928819023075169" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_13832928819023075169">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_13832928819023075169_1">
<input class="form-check-input" type="radio" name="radio_13832928819023075169" id="radio_13832928819023075169_1" value="1">
<span class="label-body px-1">
The zero is a simple zero
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13832928819023075169_2">
<input class="form-check-input" type="radio" name="radio_13832928819023075169" id="radio_13832928819023075169_2" value="2">
<span class="label-body px-1">
The zero is not a simple zero
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13832928819023075169_3">
<input class="form-check-input" type="radio" name="radio_13832928819023075169" id="radio_13832928819023075169_3" value="3">
<span class="label-body px-1">
The function oscillates too much to rely on the tangent line approximations far from the zero
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13832928819023075169_4">
<input class="form-check-input" type="radio" name="radio_13832928819023075169" id="radio_13832928819023075169_4" value="4">
<span class="label-body px-1">
We can find an answer
</span>
</label>
</div>
</div>
</div>
<div id="13832928819023075169_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_13832928819023075169"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('13832928819023075169_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_13832928819023075169")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_13832928819023075169")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
</section>
</main> <!-- /main -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const clipboard = new window.ClipboardJS('.code-copy-button', {
target: function(trigger) {
return trigger.previousElementSibling;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
setTimeout(function() {
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
});
function tippyHover(el, contentFn) {
const config = {
allowHTML: true,
content: contentFn,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start'
};
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
let href = ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
return note.innerHTML;
});
}
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const cites = ref.parentNode.getAttribute('data-cites').split(' ');
tippyHover(ref, function() {
var popup = window.document.createElement('div');
cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
var filterRegex = new RegExp('/' + window.location.host + '/');
var isInternal = (href) => {
return filterRegex.test(href) || localhostRegex.test(href);
}
// Inspect non-navigation links and adorn them if external
var links = window.document.querySelectorAll('a:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external)');
for (var i=0; i<links.length; i++) {
const link = links[i];
if (!isInternal(link.href)) {
// target, if specified
link.setAttribute("target", "_blank");
}
}
});
</script>
<nav class="page-navigation">
<div class="nav-page nav-page-previous">
<a href="../derivatives/newtons_method.html" class="pagination-link">
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">30</span>&nbsp; <span class="chapter-title">Newtons method</span></span>
</a>
</div>
<div class="nav-page nav-page-next">
<a href="../derivatives/lhospitals_rule.html" class="pagination-link">
<span class="nav-page-text"><span class="chapter-number">32</span>&nbsp; <span class="chapter-title">LHospitals Rule</span></span> <i class="bi bi-arrow-right-short"></i>
</a>
</div>
</nav>
</div> <!-- /content -->
<footer class="footer">
<div class="nav-footer">
<div class="nav-footer-center">Copyright 2022, John Verzani</div>
</div>
</footer>
</body></html>