CalculusWithJuliaNotes.jl/quarto/0e7f54ed/derivatives/optimization.html

3340 lines
237 KiB
HTML
Raw Normal View History

2022-08-11 19:15:19 +02:00
<!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 - 26&nbsp; Optimization</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/first_second_derivatives.html" rel="next">
<link href="../derivatives/mean_value_theorem.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">26</span>&nbsp; <span class="chapter-title">Optimization</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 active"><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"><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="#fixed-perimeter-and-area" id="toc-fixed-perimeter-and-area" class="nav-link active" data-scroll-target="#fixed-perimeter-and-area"> <span class="header-section-number">26.1</span> Fixed perimeter and area</a>
<ul class="collapse">
<li><a href="#exploiting-polymorphism" id="toc-exploiting-polymorphism" class="nav-link" data-scroll-target="#exploiting-polymorphism"> <span class="header-section-number">26.1.1</span> Exploiting polymorphism</a></li>
<li><a href="#using-argmax-to-identify-where-a-function-is-maximized" id="toc-using-argmax-to-identify-where-a-function-is-maximized" class="nav-link" data-scroll-target="#using-argmax-to-identify-where-a-function-is-maximized"> <span class="header-section-number">26.1.2</span> Using <code>argmax</code> to identify where a function is maximized</a></li>
</ul></li>
<li><a href="#trigonometry-problems" id="toc-trigonometry-problems" class="nav-link" data-scroll-target="#trigonometry-problems"> <span class="header-section-number">26.2</span> Trigonometry problems</a></li>
<li><a href="#rate-times-time-problems" id="toc-rate-times-time-problems" class="nav-link" data-scroll-target="#rate-times-time-problems"> <span class="header-section-number">26.3</span> Rate times time problems</a>
<ul class="collapse">
<li><a href="#rate-times-time-the-origin-story" id="toc-rate-times-time-the-origin-story" class="nav-link" data-scroll-target="#rate-times-time-the-origin-story"> <span class="header-section-number">26.3.1</span> Rate times time … the origin story</a></li>
</ul></li>
<li><a href="#unbounded-domains" id="toc-unbounded-domains" class="nav-link" data-scroll-target="#unbounded-domains"> <span class="header-section-number">26.4</span> Unbounded domains</a></li>
<li><a href="#questions" id="toc-questions" class="nav-link" data-scroll-target="#questions"> <span class="header-section-number">26.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/optimization.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">26</span>&nbsp; <span class="chapter-title">Optimization</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">Roots</span></span>
<span id="cb1-4"><a href="#cb1-4" 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>A basic application of calculus is to answer questions which relate to the largest or smallest a function can be given some constraints.</p>
<p>For example,</p>
<blockquote class="blockquote">
<p>Of all rectangles with perimeter <span class="math inline">\(20\)</span>, which has of the largest area?</p>
</blockquote>
<p>The main tool is the extreme value theorem of Bolzano and Fermats theorem about critical points, which combined say:</p>
<blockquote class="blockquote">
<p>If the function <span class="math inline">\(f(x)\)</span> is continuous on <span class="math inline">\([a,b]\)</span> and differentiable on <span class="math inline">\((a,b)\)</span>, then the extrema exist and must occur at either an end point or a critical point.</p>
</blockquote>
<p>Though not all of our problems lend themselves to a description of a continuous function on a closed interval, if they do, we have an algorithmic prescription to find the absolute extrema of a function:</p>
<ol type="1">
<li>Find the critical points. For this we can use a root-finding algorithm like <code>find_zero</code>.</li>
<li>Evaluate the function values at the critical points and at the end points.</li>
<li>Identify the largest and smallest values.</li>
</ol>
<p>With the computer we can take some shortcuts, as we will be able to graph our function to see where the extreme values will be, and in particular if they occur at end points or critical points.</p>
<section id="fixed-perimeter-and-area" class="level2" data-number="26.1">
<h2 data-number="26.1" class="anchored" data-anchor-id="fixed-perimeter-and-area"><span class="header-section-number">26.1</span> Fixed perimeter and area</h2>
<p>The simplest way to investigate the maximum or minimum value of a function over a closed interval is to just graph it and look.</p>
<p>We began with the question of which rectangles of perimeter <span class="math inline">\(20\)</span> have the largest area? The figure shows a few different rectangles with this perimeter and their respective areas.</p>
<div class="cell" data-cache="true" data-hold="true" data-execution_count="4">
<div class="cell-output cell-output-display" data-execution_count="5">
<div class="d-flex justify-content-center"> <figure class="figure"> <img src="data:image/gif;base64,R0lGODlhAANAAvcBAAAAAAD/AAEBAQMDAgQEBAZTggcGBQgICAhTgQo+XAsLCwtTgAuf+g0NDQ4LBg4ODg8PDw8yRw9XhBAQEBB/wxCh+RERERFbiRGi+hMQChMTExQUFBSJ0RVgjhYUEBYWFhdhjhd7uBgYGBkZGRlTdxlxpxoaGhpWehqa6RsWCxul+hwcHBxdhRxlkxym+x2Jyx8fHyAcFCBrmCBrmSEhISFpliFtnCIiIiJUciMdEiMjIyN8syQkJCYlJSYmJigmICh4qSkpKSoeCSomHyoqKitzoCwsLCx0oS0tLS5miS8vLzAkCzAwMDGt+TIyMjKBsTMzMzOu+TOv+zQxLDQ0NDU1NTVsjjWw+zg4ODhHUTopCTo6OjwrCzw8PD46Mz4+Pj88Nj8/P0BAP0EuCkFBQUI/OUNAOkNDQ0RBOkRBPEW1+UYwB0ZGRke3+0hISEhdaUpKSktIQ0xMTE1+nE9PT1FRUVNTU1RUVFU5BlW8/FZWVVdXV1paWlqFoVtbW1w+BVxcXF1bV15eXmJiYmVCA2VlZWhoaGtra2xsbG5IA25ubnFxcXNzcnOGknV1dXd3d3hPAnh4eHjI+Hl4dnl5eXpPAHp5d3p6enrK+nx8fHzM/H9/f4FUAYODg4WFhYeHh4mJiYnO+YqKiorP+oyMjI3S/Y5cAI6OjpGRkZOTk5RgAZVgAJWVlZdiAJeXl5iYmJi1x5qampycnJ2stJ6enp9nAJ+fn6GhoaSkpKZrAKenp6mpqaurq62tra+vr7CwsLS0tLe3t7m5ubu7u7vk/ry8vL29vb6+vsB8AMDAwMDT3cLn/sPDw8V/AMXFxcbl+cfHx8nJycvLy8zp/M3Nzc3n987o+NKIANLS0tTu/tXV1dXq9tfX19jY2Nvb29zc3N3d3d3y/t6PAN/f3+Hh4eTk5Obm5ubx+Ojo6OmWAOrq6uzs7O3t7e34/+6aAO74/+/v7/Hx8fPz8/T09PX19fb29vf39/j4+Pn5+fqhAPr6+vz8/P39/f7///+lAP///yH/C05FVFNDQVBFMi4wAwEAAAAh+QQFZAABACwAAAAAAANAAocAAAAA/wABAQEDAwIEBAQGU4IHBgUICAgIU4EKPlwLCwsLU4ALn/oNDQ0OCwYODg4PDw8PMkcPV4QQEBAQf8MQofkRERERW4kRovoTEAoTExMUFBQUidEVYI4WFBAWFhYXYY4Xe7gYGBgZGRkZU3cZcacaGhoaVnoamukbFgsbpfocHBwcXYUcZZMcpvsdicsfHx8gHBQga5gga5khISEhaZYhbZwiIiIiVHIjHRIjIyMjfLMkJCQmJSUmJiYoJiAoeKkpKSkqHgkqJh8qKiorc6AsLCwsdKEtLS0uZokvLy8wJAswMDAxrfkyMjIygbEzMzMzrvkzr/s0MSw0NDQ1NTU1bI41sPs4ODg4R1E6KQk6Ojo8Kws8PDw+OjM+Pj4/PDY/Pz9AQD9BLgpBQUFCPzlDQDpDQ0NEQTpEQTxFtflGMAdGRkZHt/tISEhIXWlKSkpLSENMTExNfpxPT09RUVFTU1NUVFRVOQZVvPxWVlVXV1daWlpahaFbW1tcPgVcXFxdW1deXl5iYmJlQgNlZWVoaGhra2tsbGxuSANubm5xcXFzc3JzhpJ1dXV3d3d4TwJ4eHh4yPh5eHZ5eXl6TwB6eXd6enp6yvp8fHx8zPx/f3+BVAGDg4OFhYWHh4eJiYmJzvmKioqKz/qMjIyN0v2OXACOjo6RkZGTk5OUYAGVYACVlZWXYgCXl5eYmJiYtceampqcnJydrLSenp6fZwCfn5+hoaGkpKSmawCnp6epqamrq6utra2vr6+wsLC0tLS3t7e5ubm7u7u75P68vLy9vb2+vr7AfADAwMDA093C5/7Dw8PFfwDFxcXG5fnHx8fJycnLy8vM6fzNzc3N5/fO6PjSiADS0tLU7v7V1dXV6vbX19fY2Njb29vc3Nzd3d3d8v7ejwDf39/h4eHk5OTm5ubm8fjo6OjplgDq6urs7Ozt7e3t+P/umgDu+P/v7+/x8fHz8/P09PT19fX29vb39/f4+Pj5+fn6oQD6+vr8/Pz9/f3+////pQD///8I/wD/CRxIsKDBgwgTKlzIsKHDhxAjSpxIsaLFixgzatzIsaPHjyBDihxJsqTJkyhTqlzJsqXLlzBjypxJs6bNmzhz6tzJs6fPn0CDCh1KtKjRo0iTKl3KtKnTp1CjSp1KtarVq1izat3KtavXr2DDih1LtqzZsx917aHya+A+RiZo2EJLt67du3jzHox1qwqtgbKowNOmQZvew4gTK17MlM1fgVtwCTREibHly5gza0bpeKAIaQJR6VloDpzpcptTq17NenFngQoM/4vlRqE3J0xy75HHu7fv38CDCx9OvLjx48iTK++9brnz59CjS5/OPB7169izazcej9327+DDR/9vLr68+fO/Mb7+R8OZQFCCFEb70vqhvPoO6fHDz3BfPf4M3QegQvio99g/d4giEB2oyEffgAkJCOFB+k14kH8WHiRhhgMVWFExn/RwxyeoMbPBLZ+IAI+DHBa0YYsVtigQhjIK9CKHHlIE4ic8ovbPMYUw4s1C89Voo5H/xCgjjTXemGGOKhVppJMWKtkikzJSOSGUKUnZJJJWcohli1pCyCVKXmYJ5n41jslhmQOeeVKaZK5ppJsZwgmgnCbR+aadbf43JZJ8luRnnoAuKeiXRhZK0qEW6slfmBniGSmhLUE6oaT4UWqhpZtiypKmEHJan6cTglqqqCuROqCpraH/CqGqr7Ia5YOM1ijrgLQCCCtrjo7kqq+JXrmomo1miiuyurKpKJK/rhasSMPyF61quwLYq7W2drlsnUZmy9+2+F2b2rQhVVtusWIeC26N6IKkbn3mbiYufuTS2y2a3/4ZrrPGQrvvnP0i+u+d7voLr7ICHxxowwuPWvClDj87aLISQyzjvfXl21q9msX70bwfs1tpwgZH3OrEoVYc8MUq36oxjAC3OzOODMO8cc0n3/xkzrnujLDPForsEcmsgZwZx615nPTAfbK8qss269yi0R0hvZrSmDHNmtNbQ22o1LVS3bPVOGeMdoZerwa2alxfhjVHWsNt8qcoUxyzt0RP/9i2am+nFrdlc29Ut+B3p5p3y3vz2zeEf6cW+GaDM1a4RodTnvisi0/dOMGPDxj5ZpNrVvlil2eUuemb89p52Z9HHTqAo2tWemanK5Y6Rqvj3rq2rxOL8cqzT8oz3sXjt/tFvWOWe2K1Z3a782I/SrbwzQ69dtFAMyv0w9tv2f2731sc9NXjK1z+y+enTXz4kB+vePL1LW9R85c9j1j0mE2ff/XCuh63zIY8+MUpfSlbX9Xa9zO1MbBK8uMc/Vpjv4rgzzL6Owz/LuM/DAKQWgJcFwHnZ8A9IVBvCjzbA8XnQO/RTHsrNNMJGZfCAsbwgC0k3wvBd0MT5lB9OzSfC//dJ7MSGg+GQ2zg+3p4RB4mkXs/TGAQ2fdEFi6xivFDog6JyDcjdiqCrpsgsGbouRqSkInKIyPszChBL9ZPjdhjYxjdSEE4DjB7TtyiEouIxlOBEXhilJYdRYhHIeoRilc8pN/+OK7g3VFGFaTIBRmTQb1s0DIdpOQH0xVCfY2wjX2sYxRROMUFYhGHiQQihy7JmEwuppJ5ieREJvnK3zUykKqRpURoqRhY4oWVi3FlLzcpr06W7JNzDOUYR0nDUqrwlD5MpRRXyUh8OZKQkBykJwtJRUXKkJlldKYNockfXUaEl4nx5V2AqRhhppOYIzPm05AJSDouU5qkpKYWVbn/xy4qczXsTIw7EaNOu5gTIugkqC2tictzafOY3DSlN1HJR3J+cZ/T7Kfj7AnQanbsmtvMJjjXKM4zWvSNI41jSUF5UlHis5n6zCM/EVnRidLOo00DKURF+tJwxtSQM7ViTYOaRZlmlKb+bClrAoqYgR6moHU56D/wsQ+GJPSpC
<figcaption class="figure-caption"><div class="markdown"><p>Some possible rectangles that satisfy the constraint on the perimeter and their area.</p>
</div> </figcaption>
</figure>
</div>
</div>
</div>
<p>The basic mathematical approach is to find a function of a single variable to maximize or minimize. In this case we have two variables describing a rectangle: a base <span class="math inline">\(b\)</span> and height <span class="math inline">\(h\)</span>. Our formulas are the area of a rectangle:</p>
<p><span class="math display">\[
A = bh,
\]</span></p>
<p>and the formula for the perimeter of a rectangle:</p>
<p><span class="math display">\[
P = 2b + 2h = 20.
\]</span></p>
<p>From this last one, we see that <span class="math inline">\(b\)</span> can be no bigger than <span class="math inline">\(10\)</span> and no smaller than <span class="math inline">\(0\)</span> from the restriction put in place through the perimeter. Solving for <span class="math inline">\(h\)</span> in terms of <span class="math inline">\(b\)</span> then yields this restatement of the problem:</p>
<p>Maximize <span class="math inline">\(A(b) = b \cdot (10 - b)\)</span> over the interval <span class="math inline">\([0,10]\)</span>.</p>
<p>This is exactly the form needed to apply our theorem about the existence of extrema (a continuous function on a closed interval). Rather than solve analytically by taking a derivative, we simply graph to find the value:</p>
<div class="cell" data-execution_count="5">
<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">Area</span>(b) <span class="op">=</span> b <span class="op">*</span> (<span class="fl">10</span> <span class="op">-</span> b)</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(Area, <span class="fl">0</span>, <span class="fl">10</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">
<p><img src="optimization_files/figure-html/cell-6-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>You should see the maximum occurs at <span class="math inline">\(b=5\)</span> by symmetry, so <span class="math inline">\(h=5\)</span> as well, and the maximum area is then <span class="math inline">\(25\)</span>. This gives the satisfying answer that among all rectangles of fixed perimeter, that with the largest area is a square. As well, this indicates a common result: there is often some underlying symmetry in the answer.</p>
<section id="exploiting-polymorphism" class="level3" data-number="26.1.1">
<h3 data-number="26.1.1" class="anchored" data-anchor-id="exploiting-polymorphism"><span class="header-section-number">26.1.1</span> Exploiting polymorphism</h3>
<p>Before moving on, lets see a slightly different way to do this problem with <code>Julia</code>, where we trade off some algebra for a bit of abstraction. This technique was discussed in the section on <a href="../precalc/functions.html">functions</a>.</p>
<p>Lets first write area as a function of both base and height:</p>
<div class="cell" data-execution_count="6">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fu">A</span>(b, h) <span class="op">=</span> b <span class="op">*</span> h</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>A (generic function with 1 method)</code></pre>
</div>
</div>
<p>From the constraint given by the perimeter being a fixed value we can solve for <code>h</code> in terms of <code>b</code>. We write this as a function:</p>
<div class="cell" data-execution_count="7">
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="fu">h</span>(b) <span class="op">=</span> (<span class="fl">20</span> <span class="op">-</span> <span class="fl">2</span>b) <span class="op">/</span> <span class="fl">2</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="8">
<pre><code>h (generic function with 1 method)</code></pre>
</div>
</div>
<p>To get <code>A(b)</code> we simply need to substitute <code>h(b)</code> into our formula for the area, <code>A</code>. However, instead of doing the substitution ourselves using algebra we let <code>Julia</code> do it through composition of functions:</p>
<div class="cell" data-execution_count="8">
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="fu">A</span>(b) <span class="op">=</span> <span class="fu">A</span>(b, <span class="fu">h</span>(b))</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>A (generic function with 2 methods)</code></pre>
</div>
</div>
<p>Now we can solve graphically as before, or numerically, such as here where we search for zeros of the derivative:</p>
<div class="cell" data-execution_count="9">
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="fu">find_zeros</span>(A<span class="op">'</span>, <span class="fl">0</span>, <span class="fl">10</span>) <span class="co"># find_zeros in `Roots`,</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="10">
<pre><code>1-element Vector{Float64}:
5.0</code></pre>
</div>
</div>
<p>(As a reminder, the notation <code>A'</code> is defined in <code>CalculusWithJulia</code> using the <code>derivative</code> function from the <code>ForwardDiff</code> package.)</p>
<div class="callout-note callout callout-style-default callout-captioned">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-caption-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>Look at the last definition of <code>A</code>. The function <code>A</code> appears on both sides, though on the left side with one argument and on the right with two. These are two “methods” of a <em>generic</em> function, <code>A</code>. <code>Julia</code> allows multiple definitions for the same name as long as the arguments (their number and type) can disambiguate which to use. In this instance, when one argument is passed in then the last defintion is used (<code>A(b,h(b))</code>), whereas if two are passed in, then the method that multiplies both arguments is used. The advantage of multiple dispatch is illustrated: the same concept - area - has one function name, though there may be different ways to compute the area, so there is more than one implementation.</p>
</div>
</div>
<section id="example-norman-windows" class="level4">
<h4 class="anchored" data-anchor-id="example-norman-windows">Example: Norman windows</h4>
<p>Here is a similar, though more complicated, example where the analytic approach can be a bit more tedious, but the graphical one mostly satisfying, though we do use a numerical algorithm to find an exact final answer.</p>
<p>Let a “<a href="https://en.wikipedia.org/wiki/Norman_architecture">Norman</a>” window consist of a rectangular window of top length <span class="math inline">\(x\)</span> and side length <span class="math inline">\(y\)</span> and a half circle on top. The goal is to maximize the area for a fixed value of the perimeter. Again, assume this perimeter is <span class="math inline">\(20\)</span> units.</p>
<p>This figure shows two such windows, one with base length given by <span class="math inline">\(x=3\)</span>, the other with base length given by <span class="math inline">\(x=4\)</span>. The one with base length <span class="math inline">\(4\)</span> seems to have much bigger area, what value of <span class="math inline">\(x\)</span> will lead to the largest area?</p>
<div class="cell" data-hold="true" data-execution_count="10">
<div class="cell-output cell-output-display" data-execution_count="11">
<p><img src="optimization_files/figure-html/cell-11-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>For this problem, we have two equations.</p>
<p>The area is the area of the rectangle plus the area of the half circle (<span class="math inline">\(\pi r^2/2\)</span> with <span class="math inline">\(r=x/2\)</span>).</p>
<p><span class="math display">\[
A = xy + \pi(x/2)^2/2
\]</span></p>
<p>In <code>Julia</code> this is</p>
<div class="cell" data-execution_count="11">
<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">Aᵣ</span>(x, y) <span class="op">=</span> x<span class="op">*</span>y <span class="op">+</span> <span class="fu">pi*</span>(x<span class="op">/</span><span class="fl">2</span>)<span class="op">^</span><span class="fl">2</span> <span class="op">/</span> <span class="fl">2</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">
<pre><code>Aᵣ (generic function with 1 method)</code></pre>
</div>
</div>
<p>The perimeter consists of <span class="math inline">\(3\)</span> sides of the rectangle and the perimeter of half a circle (<span class="math inline">\(\pi r\)</span>, with <span class="math inline">\(r=x/2\)</span>):</p>
<p><span class="math display">\[
P = 2y + x + \pi(x/2) = 20
\]</span></p>
<p>We solve for <span class="math inline">\(y\)</span> in the first with <span class="math inline">\(y = (20 - x - \pi(x/2))/2\)</span> so that in <code>Julia</code> we have:</p>
<div class="cell" data-execution_count="12">
<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="fu">y</span>(x) <span class="op">=</span> (<span class="fl">20</span> <span class="op">-</span> x <span class="op">-</span> <span class="cn">pi</span> <span class="op">*</span> x<span class="op">/</span><span class="fl">2</span>) <span class="op">/</span> <span class="fl">2</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>y (generic function with 1 method)</code></pre>
</div>
</div>
<p>And then we substitute in <code>y(x)</code> for <code>y</code> in the area formula through:</p>
<div class="cell" data-execution_count="13">
<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="fu">Aᵣ</span>(x) <span class="op">=</span> <span class="fu">Aᵣ</span>(x, <span class="fu">y</span>(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="14">
<pre><code>Aᵣ (generic function with 2 methods)</code></pre>
</div>
</div>
<p>Of course both <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span> are non-negative. The latter forces <span class="math inline">\(x\)</span> to be no more than <span class="math inline">\(x=20/(1+\pi/2)\)</span>.</p>
<p>This leaves us the calculus problem of finding an absolute maximum of a continuous function over the closed interval <span class="math inline">\([0, 20/(1+\pi/2)]\)</span>. Our theorem tells us this maximum must occur, we now proceed to find it.</p>
<p>We begin by simply graphing and estimating the values of the maximum and where it occurs.</p>
<div class="cell" data-execution_count="14">
<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="fu">plot</span>(Aᵣ, <span class="fl">0</span>, <span class="fl">20</span><span class="op">/</span>(<span class="fl">1</span><span class="op">+</span><span class="cn">pi</span><span class="op">/</span><span class="fl">2</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="15">
<p><img src="optimization_files/figure-html/cell-15-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The naked eye sees that maximum value is somewhere around <span class="math inline">\(27\)</span> and occurs at <span class="math inline">\(x\approx 5.6\)</span>. Clearly from the graph, we know the maximum value happens at the critical point and there is only one such critical point.</p>
<p>As reading the maximum from the graph is more difficult than reading a <span class="math inline">\(0\)</span> of a function, we plot the derivative using our approximate derivative.</p>
<div class="cell" data-execution_count="15">
<div class="sourceCode cell-code" id="cb18"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(Aᵣ<span class="op">'</span>, <span class="fl">5.5</span>, <span class="fl">5.7</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="optimization_files/figure-html/cell-16-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>We confirm that the critical point is around <span class="math inline">\(5.6\)</span>.</p>
</section>
<section id="using-find_zero-to-locate-critical-points." class="level4">
<h4 class="anchored" data-anchor-id="using-find_zero-to-locate-critical-points.">Using <code>find_zero</code> to locate critical points.</h4>
<p>Rather than zoom in graphically, we now use a root-finding algorithm, to find a more precise value of the zero of <span class="math inline">\(A'\)</span>. We know that the maximum will occur at a critical point, a zero of the derivative. The <code>find_zero</code> function from the <code>Roots</code> package provides a non-linear root-finding algorithm based on the bisection method. The only thing to keep track of is that solving <span class="math inline">\(f'(x) = 0\)</span> means we use the derivative and not the original function.</p>
<p>We see from the graph that <span class="math inline">\([0, 20/(1+\pi/2)]\)</span> will provide a bracket, as there is only one relative maximum:</p>
<div class="cell" data-execution_count="16">
<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>x <span class="op">=</span> <span class="fu">find_zero</span>(Aᵣ<span class="op">'</span>, (<span class="fl">0</span>, <span class="fl">20</span><span class="op">/</span>(<span class="fl">1</span><span class="op">+</span><span class="cn">pi</span><span class="op">/</span><span class="fl">2</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">
<pre><code>5.600991535115574</code></pre>
</div>
</div>
<p>This value is the lone critical point, and in this case gives the position of the value that will maximize the function. The value and maximum area are then given by:</p>
<div class="cell" data-execution_count="17">
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a>(x, <span class="fu">Aᵣ</span>(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="18">
<pre><code>(5.600991535115574, 28.004957675577867)</code></pre>
</div>
</div>
<p>(Compare this answer to the previous, is the square the figure of greatest area for a fixed perimeter, or just the figure amongst all rectangles? See <a href="https://en.wikipedia.org/wiki/Isoperimetric_inequality">Isoperimetric inequality</a> for an answer.)</p>
</section>
</section>
<section id="using-argmax-to-identify-where-a-function-is-maximized" class="level3" data-number="26.1.2">
<h3 data-number="26.1.2" class="anchored" data-anchor-id="using-argmax-to-identify-where-a-function-is-maximized"><span class="header-section-number">26.1.2</span> Using <code>argmax</code> to identify where a function is maximized</h3>
<p>This value that maximizes a function is sometimes referred to as the <em>argmax</em>, or argument which maximizes the function. In <code>Julia</code> the <code>argmax(f,domain)</code> function is defined to “Return a value <span class="math inline">\(x\)</span> in the domain of <span class="math inline">\(f\)</span> for which <span class="math inline">\(f(x)\)</span> is maximized. If there are multiple maximal values for <span class="math inline">\(f(x)\)</span> then the first one will be found.” The domain is some iterable collection. In the mathematical world this would be an interval <span class="math inline">\([a,b]\)</span>, but on the computer it is an approximation, such as is returned by <code>range</code> below. Without out having to take a derivative, as above, but sacrificing some accuracy, the task of identifying <code>x</code> for where <code>A</code> is maximum, could be done with</p>
<div class="cell" data-execution_count="18">
<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">argmax</span>(Aᵣ, <span class="fu">range</span>(<span class="fl">0</span>, <span class="fl">20</span><span class="op">/</span>(<span class="fl">1</span><span class="op">+</span><span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>), length<span class="op">=</span><span class="fl">10000</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="19">
<pre><code>5.6011593738142205</code></pre>
</div>
</div>
<section id="a-symbolic-approach" class="level4">
<h4 class="anchored" data-anchor-id="a-symbolic-approach">A symbolic approach</h4>
<p>We could also do the above problem symbolically with the aid of <code>SymPy</code>. Here are the steps:</p>
<div class="cell" data-execution_count="19">
<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="pp">@syms</span> 𝒘<span class="op">::</span><span class="dt">real </span>𝒉<span class="op">::</span><span class="dt">real</span></span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a>𝑨₀ <span class="op">=</span> 𝒘 <span class="op">*</span> 𝒉 <span class="op">+</span> <span class="cn">pi</span> <span class="op">*</span> (𝒘<span class="op">/</span><span class="fl">2</span>)<span class="op">^</span><span class="fl">2</span> <span class="op">/</span> <span class="fl">2</span></span>
<span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a>𝑷erim <span class="op">=</span> <span class="fl">2</span><span class="op">*</span>𝒉 <span class="op">+</span> 𝒘 <span class="op">+</span> <span class="cn">pi</span> <span class="op">*</span> 𝒘<span class="op">/</span><span class="fl">2</span></span>
<span id="cb25-5"><a href="#cb25-5" aria-hidden="true" tabindex="-1"></a>𝒉₀ <span class="op">=</span> <span class="fu">solve</span>(𝑷erim <span class="op">-</span> <span class="fl">20</span>, 𝒉)[<span class="fl">1</span>]</span>
<span id="cb25-6"><a href="#cb25-6" aria-hidden="true" tabindex="-1"></a>𝑨₁ <span class="op">=</span> <span class="fu">𝑨₀</span>(𝒉 <span class="op">=&gt;</span> 𝒉₀)</span>
<span id="cb25-7"><a href="#cb25-7" aria-hidden="true" tabindex="-1"></a>𝒘₀ <span class="op">=</span> <span class="fu">solve</span>(<span class="fu">diff</span>(𝑨₁,𝒘), 𝒘)[<span class="fl">1</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="20">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
\frac{40}{\pi + 4}
\]
</span>
</div>
</div>
<p>We know that <code>𝒘₀</code> is the maximum in this example from our previous work. We shall see soon, that just knowing that the second derivative is negative at <code>𝒘₀</code> would suffice to know this. Here we check that condition:</p>
<div class="cell" data-execution_count="20">
<div class="sourceCode cell-code" id="cb26"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a><span class="fu">diff</span>(𝑨₁, 𝒘, 𝒘)(𝒘 <span class="op">=&gt;</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="21">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
- (\frac{\pi}{4} + 1)
\]
</span>
</div>
</div>
<p>As an aside, compare the steps involved above for a symbolic solution to those of previous work for a numeric solution:</p>
<div class="cell" data-hold="true" data-execution_count="21">
<div class="sourceCode cell-code" id="cb27"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a><span class="fu">Aᵣ</span>(w, h) <span class="op">=</span> w<span class="op">*</span>h <span class="op">+</span> <span class="fu">pi*</span>(w<span class="op">/</span><span class="fl">2</span>)<span class="op">^</span><span class="fl">2</span> <span class="op">/</span> <span class="fl">2</span></span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a><span class="fu">h</span>(w) <span class="op">=</span> (<span class="fl">20</span> <span class="op">-</span> w <span class="op">-</span> <span class="cn">pi</span> <span class="op">*</span> w<span class="op">/</span><span class="fl">2</span>) <span class="op">/</span> <span class="fl">2</span></span>
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true" tabindex="-1"></a><span class="fu">Aᵣ</span>(w) <span class="op">=</span> <span class="fu">A</span>(w, <span class="fu">h</span>(w))</span>
<span id="cb27-4"><a href="#cb27-4" aria-hidden="true" tabindex="-1"></a><span class="fu">find_zero</span>(A<span class="op">'</span>, (<span class="fl">0</span>, <span class="fl">20</span><span class="op">/</span>(<span class="fl">1</span><span class="op">+</span><span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>))) <span class="co"># 40 / (pi + 4)</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="22">
<pre><code>3.8898452964834274</code></pre>
</div>
</div>
<p>They are similar, except we solved for <code>h0</code> symbolically, rather than by hand, when we solved for <code>h(w)</code>.</p>
<section id="example" class="level5">
<h5 class="anchored" data-anchor-id="example">Example</h5>
<div class="cell" data-hold="true" data-execution_count="23">
<div class="cell-output cell-output-display" data-execution_count="24">
<p><img src="optimization_files/figure-html/cell-24-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>A trapezoid is <em>inscribed</em> in the upper-half circle of radius <span class="math inline">\(r\)</span>. The trapezoid is found be connecting the points <span class="math inline">\((x,y)\)</span> (in the first quadrant) with <span class="math inline">\((r, 0)\)</span>, <span class="math inline">\((-r,0)\)</span>, and <span class="math inline">\((-x, y)\)</span>. Find the maximum area. (The above figure has <span class="math inline">\(x=0.75\)</span> and <span class="math inline">\(r=1\)</span>.)</p>
<p>Here the constraint is simply <span class="math inline">\(r^2 = x^2 + y^2\)</span> with <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span> being non-negative. The area is then found through the average of the two lengths times the height. Using <code>height</code> for <code>y</code>, we have:</p>
<div class="cell" data-execution_count="24">
<div class="sourceCode cell-code" id="cb29"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> x<span class="op">::</span><span class="dt">positive </span>r<span class="op">::</span><span class="dt">positive</span></span>
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a>hₜ <span class="op">=</span> <span class="fu">sqrt</span>(r<span class="op">^</span><span class="fl">2</span> <span class="op">-</span> x<span class="op">^</span><span class="fl">2</span>)</span>
<span id="cb29-3"><a href="#cb29-3" aria-hidden="true" tabindex="-1"></a>aₜ <span class="op">=</span> (<span class="fl">2</span>x <span class="op">+</span> <span class="fl">2</span>r)<span class="op">/</span><span class="fl">2</span> <span class="op">*</span> hₜ</span>
<span id="cb29-4"><a href="#cb29-4" aria-hidden="true" tabindex="-1"></a>possible_sols <span class="op">=</span> <span class="fu">solve</span>(<span class="fu">diff</span>(aₜ, x) <span class="op">~</span> <span class="fl">0</span>, x) <span class="co"># possibly many solutions</span></span>
<span id="cb29-5"><a href="#cb29-5" aria-hidden="true" tabindex="-1"></a>x0 <span class="op">=</span> <span class="fu">first</span>(possible_sols) <span class="co"># only solution is also found from first or [1] indexing</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="25">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
\frac{r}{2}
\]
</span>
</div>
</div>
<p>The other values of interest can be found through substitution. For example:</p>
<div class="cell" data-execution_count="25">
<div class="sourceCode cell-code" id="cb30"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a><span class="fu">hₜ</span>(x <span class="op">=&gt;</span> x0)</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="26">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
\frac{\sqrt{3} r}{2}
\]
</span>
</div>
</div>
</section>
</section>
</section>
</section>
<section id="trigonometry-problems" class="level2" data-number="26.2">
<h2 data-number="26.2" class="anchored" data-anchor-id="trigonometry-problems"><span class="header-section-number">26.2</span> Trigonometry problems</h2>
<p>Many maximization and minimization problems involve triangles, which in turn use trigonometry in their description. Here is an example, the “ladder corner problem.” (There are many other <a href="http://www.mathematische-basteleien.de/ladder.htm">ladder</a> problems.)</p>
<p>A ladder is to be moved through a two-dimensional hallway which has a bend and gets narrower after the bend. The hallway is <span class="math inline">\(8\)</span> feet wide then <span class="math inline">\(5\)</span> feet wide. What is the longest such ladder that can be navigated around the corner?</p>
<p>The figure shows a ladder of length <span class="math inline">\(l_1 + l_2\)</span> that got stuck - it was too long.</p>
<div class="cell" data-hold="true" data-execution_count="26">
<div class="cell-output cell-output-display" data-execution_count="27">
<p><img src="optimization_files/figure-html/cell-27-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>We approach this problem in reverse. It is easy to see when a ladder is too long. It gets stuck at some angle <span class="math inline">\(\theta\)</span>. So for each <span class="math inline">\(\theta\)</span> we find that ladder length that is just too long. Then we find the minimum length of all these ladders that are too long. If a ladder is this length or more it will get stuck for some angle. However, if it is less than this length it will not get stuck. So to maximize a ladder length, we minimize a different function. Neat.</p>
<p>Now, to find the length <span class="math inline">\(l = l_1 + l_2\)</span> as a function of <span class="math inline">\(\theta\)</span>.</p>
<p>We need to brush off our trigonometry, in particular right triangle trigonometry. We see from the figure that <span class="math inline">\(l_1\)</span> is the hypotenuse of a right triangle with opposite side <span class="math inline">\(8\)</span> and <span class="math inline">\(l_2\)</span> is the hypotenuse of a right triangle with adjacent side <span class="math inline">\(5\)</span>. So, <span class="math inline">\(8/l_1 = \sin\theta\)</span> and <span class="math inline">\(5/l_2 = \cos\theta\)</span>.</p>
<p>That is, we have</p>
<div class="cell" data-execution_count="27">
<div class="sourceCode cell-code" id="cb31"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a><span class="fu">l</span>(l1, l2) <span class="op">=</span> l1 <span class="op">+</span> l2</span>
<span id="cb31-2"><a href="#cb31-2" aria-hidden="true" tabindex="-1"></a><span class="fu">l1</span>(t) <span class="op">=</span> <span class="fl">8</span><span class="op">/</span><span class="fu">sin</span>(t)</span>
<span id="cb31-3"><a href="#cb31-3" aria-hidden="true" tabindex="-1"></a><span class="fu">l2</span>(t) <span class="op">=</span> <span class="fl">5</span><span class="op">/</span><span class="fu">cos</span>(t)</span>
<span id="cb31-4"><a href="#cb31-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb31-5"><a href="#cb31-5" aria-hidden="true" tabindex="-1"></a><span class="fu">l</span>(t) <span class="op">=</span> <span class="fu">l</span>(<span class="fu">l1</span>(t), <span class="fu">l2</span>(t)) <span class="co"># or simply l(t) = 8/sin(t) + 5/cos(t)</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="28">
<pre><code>l (generic function with 2 methods)</code></pre>
</div>
</div>
<p>Our goal is to minimize this function for all angles between <span class="math inline">\(0\)</span> and <span class="math inline">\(90\)</span> degrees, or <span class="math inline">\(0\)</span> and <span class="math inline">\(\pi/2\)</span> radians.</p>
<p>This is not a continuous function on a closed interval - it is undefined at the endpoints. That being said, a quick plot will convince us that the minimum occurs at a critical point and there is only one critical point in <span class="math inline">\((0, \pi/2)\)</span>.</p>
<div class="cell" data-execution_count="28">
<div class="sourceCode cell-code" id="cb33"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a>delta <span class="op">=</span> <span class="fl">0.2</span></span>
<span id="cb33-2"><a href="#cb33-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(l, delta, <span class="cn">pi</span><span class="op">/</span><span class="fl">2</span> <span class="op">-</span> delta)</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="29">
<p><img src="optimization_files/figure-html/cell-29-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The graph shows the minimum occurs between <span class="math inline">\(0.50\)</span> and <span class="math inline">\(1.00\)</span> radians, a bracket for the derivative. Here we find <span class="math inline">\(x\)</span> and the minimum value:</p>
<div class="cell" data-hold="true" data-execution_count="29">
<div class="sourceCode cell-code" id="cb34"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a>x <span class="op">=</span> <span class="fu">find_zero</span>(l<span class="op">'</span>, (<span class="fl">0.5</span>, <span class="fl">1.0</span>))</span>
<span id="cb34-2"><a href="#cb34-2" aria-hidden="true" tabindex="-1"></a>x, <span class="fu">l</span>(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="30">
<pre><code>(0.8634136052517809, 18.219533699708656)</code></pre>
</div>
</div>
<p>That is, any ladder less than this length can get around the hallway.</p>
</section>
<section id="rate-times-time-problems" class="level2" data-number="26.3">
<h2 data-number="26.3" class="anchored" data-anchor-id="rate-times-time-problems"><span class="header-section-number">26.3</span> Rate times time problems</h2>
<p>Ethan Hunt, a top secret spy, has a mission to chase a bad guy. Here is what we know:</p>
<ul>
<li>Ethan likes to run. He can run at <span class="math inline">\(10\)</span> miles per hour.</li>
<li>He can drive a car - usually some concept car by BMW - at <span class="math inline">\(30\)</span> miles per hour, but only on the road.</li>
</ul>
<p>For his mission, he needs to go <span class="math inline">\(10\)</span> miles west and <span class="math inline">\(5\)</span> `miles north. He can do this by:</p>
<ul>
<li>just driving <span class="math inline">\(8.310\)</span> miles west then <span class="math inline">\(5\)</span> miles north, or</li>
<li>just running the diagonal distance, or</li>
<li>driving <span class="math inline">\(0 &lt; x &lt; 10\)</span> miles west, then running on the diagonal</li>
</ul>
<p>A quick analysis says:</p>
<ul>
<li>It would take <span class="math inline">\((10+5)/30\)</span> hours to just drive</li>
<li>It would take <span class="math inline">\(\sqrt{10^2 + 5^2}/10\)</span> hours to just run</li>
</ul>
<p>Now, if he drives <span class="math inline">\(x\)</span> miles west (<span class="math inline">\(0 &lt; x &lt; 10\)</span>) he would run an amount given by the hypotenuse of a triangle with lengths <span class="math inline">\(5\)</span> and <span class="math inline">\(10-x\)</span>. His time driving would be <span class="math inline">\(x/30\)</span> and his time running would be <span class="math inline">\(\sqrt{5^2+(10-x)^2}/10\)</span> for a total of:</p>
<p><span class="math display">\[
T(x) = x/30 + \sqrt{5^2 + (10-x)^2}/10, \quad 0 &lt; x &lt; 10
\]</span></p>
<p>With the endpoints given by <span class="math inline">\(T(0) = \sqrt{10^2 + 5^2}/10\)</span> and <span class="math inline">\(T(10) = (10 + 5)/30\)</span>.</p>
<p>Lets plot <span class="math inline">\(T(x)\)</span> over the interval <span class="math inline">\((0,10)\)</span> and look:</p>
<div class="cell" data-execution_count="30">
<div class="sourceCode cell-code" id="cb36"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a><span class="fu">T</span>(x) <span class="op">=</span> x<span class="op">/</span><span class="fl">30</span> <span class="op">+</span> <span class="fu">sqrt</span>(<span class="fl">5</span><span class="op">^</span><span class="fl">2</span> <span class="op">+</span> (<span class="fl">10</span><span class="op">-</span>x)<span class="op">^</span><span class="fl">2</span>)<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>
<div class="cell-output cell-output-display" data-execution_count="31">
<pre><code>T (generic function with 1 method)</code></pre>
</div>
</div>
<div class="cell" data-execution_count="31">
<div class="sourceCode cell-code" id="cb38"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb38-1"><a href="#cb38-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(T, <span class="fl">0</span>, <span class="fl">10</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="32">
<p><img src="optimization_files/figure-html/cell-32-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The minimum happens way out near 8. We zoom in a bit:</p>
<div class="cell" data-execution_count="32">
<div class="sourceCode cell-code" id="cb39"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb39-1"><a href="#cb39-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(T, <span class="fl">7</span>, <span class="fl">9</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="33">
<p><img src="optimization_files/figure-html/cell-33-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>It appears to be around <span class="math inline">\(8.3\)</span>. We now use <code>find_zero</code> to refine our guess at the critical point using <span class="math inline">\([7,9]\)</span>:</p>
<div class="cell" data-execution_count="33">
<div class="sourceCode cell-code" id="cb40"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb40-1"><a href="#cb40-1" aria-hidden="true" tabindex="-1"></a>α <span class="op">=</span> <span class="fu">find_zero</span>(T<span class="op">'</span>, (<span class="fl">7</span>, <span class="fl">9</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="34">
<pre><code>8.232233047033631</code></pre>
</div>
</div>
<p>Okay, got it. Around<span class="math inline">\(8.23\)</span>. So is our minimum time</p>
<div class="cell" data-execution_count="34">
<div class="sourceCode cell-code" id="cb42"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb42-1"><a href="#cb42-1" aria-hidden="true" tabindex="-1"></a><span class="fu">T</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="35">
<pre><code>0.804737854124365</code></pre>
</div>
</div>
<p>We know this is a relative minimum, but not that it is the global minimum over the closed time interlal. For that we must also check the endpoints:</p>
<div class="cell" data-execution_count="35">
<div class="sourceCode cell-code" id="cb44"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb44-1"><a href="#cb44-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sqrt</span>(<span class="fl">10</span><span class="op">^</span><span class="fl">2</span> <span class="op">+</span> <span class="fl">5</span><span class="op">^</span><span class="fl">2</span>)<span class="op">/</span><span class="fl">10</span>, <span class="fu">T</span>(α), (<span class="fl">10</span><span class="op">+</span><span class="fl">5</span>)<span class="op">/</span><span class="fl">30</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="36">
<pre><code>(1.118033988749895, 0.804737854124365, 0.5)</code></pre>
</div>
</div>
<p>Ahh, we see that <span class="math inline">\(T(x)\)</span> is not continuous on <span class="math inline">\([0, 10]\)</span>, as it jumps at <span class="math inline">\(x=10\)</span> down to an even smaller amount of <span class="math inline">\(1/2\)</span>. It may not look as impressive as a miles-long sprint, but Mr.&nbsp;Hunt is advised by Benji to drive the whole way.</p>
<section id="rate-times-time-the-origin-story" class="level3" data-number="26.3.1">
<h3 data-number="26.3.1" class="anchored" data-anchor-id="rate-times-time-the-origin-story"><span class="header-section-number">26.3.1</span> Rate times time … the origin story</h3>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../derivatives/figures/fcarc-may2016-fig43-250.gif" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Image number <span class="math inline">\(43\)</span> from lHospitals calculus book (the first). A traveler leaving location <span class="math inline">\(C\)</span> to go to location <span class="math inline">\(F\)</span> must cross two regions separated by the straight line <span class="math inline">\(AEB\)</span>. We suppose that in the region on the side of <span class="math inline">\(C\)</span>, he covers distance <span class="math inline">\(a\)</span> in time <span class="math inline">\(c\)</span>, and that on the other, on the side of <span class="math inline">\(F\)</span>, distance <span class="math inline">\(b\)</span> in the same time <span class="math inline">\(c\)</span>. We ask through which point <span class="math inline">\(E\)</span> on the line <span class="math inline">\(AEB\)</span> he should pass, so as to take the least possible time to get from <span class="math inline">\(C\)</span> to <span class="math inline">\(F\)</span>? (From http://www.ams.org/samplings/feature-column/fc-2016-05.)</figcaption><p></p>
</figure>
</div>
<p>The last example is a modern day illustration of a problem of calculus dating back to lHospital. His parameterization is a bit different. Lets change his by taking two points <span class="math inline">\((0, a)\)</span> and <span class="math inline">\((L,-b)\)</span>, with <span class="math inline">\(a,b,L\)</span> positive values. Above the <span class="math inline">\(x\)</span> axis travel happens at rate <span class="math inline">\(r_0\)</span>, and below, travel happens at rate <span class="math inline">\(r_1\)</span>, again, both positive. What value <span class="math inline">\(x\)</span> in <span class="math inline">\([0,L]\)</span> will minimize the total travel time?</p>
<p>We approach this symbolically with <code>SymPy</code>:</p>
<div class="cell" data-execution_count="37">
<div class="sourceCode cell-code" id="cb46"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb46-1"><a href="#cb46-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> x<span class="op">::</span><span class="dt">positive </span>a<span class="op">::</span><span class="dt">positive </span>b<span class="op">::</span><span class="dt">positive </span>L<span class="op">::</span><span class="dt">positive </span>r0<span class="op">::</span><span class="dt">positive </span>r1<span class="op">::</span><span class="dt">positive</span></span>
<span id="cb46-2"><a href="#cb46-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb46-3"><a href="#cb46-3" aria-hidden="true" tabindex="-1"></a>d0 <span class="op">=</span> <span class="fu">sqrt</span>(x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> a<span class="op">^</span><span class="fl">2</span>)</span>
<span id="cb46-4"><a href="#cb46-4" aria-hidden="true" tabindex="-1"></a>d1 <span class="op">=</span> <span class="fu">sqrt</span>((L<span class="op">-</span>x)<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> b<span class="op">^</span><span class="fl">2</span>)</span>
<span id="cb46-5"><a href="#cb46-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb46-6"><a href="#cb46-6" aria-hidden="true" tabindex="-1"></a>t <span class="op">=</span> d0<span class="op">/</span>r0 <span class="op">+</span> d1<span class="op">/</span>r1 <span class="co"># time = distance/rate</span></span>
<span id="cb46-7"><a href="#cb46-7" aria-hidden="true" tabindex="-1"></a>dt <span class="op">=</span> <span class="fu">diff</span>(t, x) <span class="co"># look for critical points</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="38">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
\frac{- L + x}{r_{1} \sqrt{b^{2} + \left(L - x\right)^{2}}} + \frac{x}{r_{0} \sqrt{a^{2} + x^{2}}}
\]
</span>
</div>
</div>
<p>The answer will occur at a critical point or an endpoint, either <span class="math inline">\(x=0\)</span> or <span class="math inline">\(x=L\)</span>.</p>
<p>The structure of <code>dt</code> is too complicated for simply calling <code>solve</code> to find the critical points. Instead we help <code>SymPy</code> out a bit. We are solving an equation of the form <span class="math inline">\(a/b + c/d = 0\)</span>. These solutions will also be solutions of <span class="math inline">\((a/b)^2 - (c/d)^2=0\)</span> or even <span class="math inline">\(a^2d^2 - c^2b^2 = 0\)</span>. This follows as solutions to <span class="math inline">\(u+v=0\)</span>, also solve <span class="math inline">\((u+v)\cdot(u-v)=0\)</span>, or <span class="math inline">\(u^2 - v^2=0\)</span>. Setting <span class="math inline">\(u=a/b\)</span> and <span class="math inline">\(v=c/d\)</span> completes the comparison.</p>
<p>We can get these terms - <span class="math inline">\(a\)</span>, <span class="math inline">\(b\)</span>, <span class="math inline">\(c\)</span>, and <span class="math inline">\(d\)</span> - as follows:</p>
<div class="cell" data-execution_count="38">
<div class="sourceCode cell-code" id="cb47"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb47-1"><a href="#cb47-1" aria-hidden="true" tabindex="-1"></a>t1, t2 <span class="op">=</span> dt.args <span class="co"># the `args` property returns the arguments to the outer function (+ in this case)</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="39">
<pre><code>(x/(r0*sqrt(a^2 + x^2)), (-L + x)/(r1*sqrt(b^2 + (L - x)^2)))</code></pre>
</div>
</div>
<p>The equivalent of <span class="math inline">\(a^2d^2 - c^2 b^2\)</span> is found using the generic functions <code>numerator</code> and <code>denominator</code> to access the numerator and denominator of the fractions:</p>
<div class="cell" data-execution_count="39">
<div class="sourceCode cell-code" id="cb49"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb49-1"><a href="#cb49-1" aria-hidden="true" tabindex="-1"></a>ex <span class="op">=</span> <span class="fu">numerator</span>(t1<span class="op">^</span><span class="fl">2</span>)<span class="fu">*denominator</span>(t2<span class="op">^</span><span class="fl">2</span>) <span class="op">-</span> <span class="fu">denominator</span>(t1<span class="op">^</span><span class="fl">2</span>)<span class="fu">*numerator</span>(t2<span class="op">^</span><span class="fl">2</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="40">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
- r_{0}^{2} \left(- L + x\right)^{2} \left(a^{2} + x^{2}\right) + r_{1}^{2} x^{2} \left(b^{2} + \left(L - x\right)^{2}\right)
\]
</span>
</div>
</div>
<p>This is a polynomial in the <code>x</code> variable of degree <span class="math inline">\(4\)</span>, as seen here where the <code>sympy.Poly</code> function is used to identify the symbols of the polynomial from the parameters:</p>
<div class="cell" data-execution_count="40">
<div class="sourceCode cell-code" id="cb50"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb50-1"><a href="#cb50-1" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> sympy.<span class="fu">Poly</span>(ex, x) <span class="co"># a0 + a1⋅x + a2⋅x^2 + a3⋅x^3 + a4⋅x^4</span></span>
<span id="cb50-2"><a href="#cb50-2" aria-hidden="true" tabindex="-1"></a>p.<span class="fu">coeffs</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="41">
<pre><code>5-element Vector{Sym}:
-r0^2 + r1^2
2*L*r0^2 - 2*L*r1^2
-L^2*r0^2 + L^2*r1^2 - a^2*r0^2 + b^2*r1^2
2*L*a^2*r0^2
-L^2*a^2*r0^2</code></pre>
</div>
</div>
<p>Fourth degree polynomials can be solved. The critical points of the original equation will be among the <span class="math inline">\(4\)</span> solutions given. However, the result is complicated. The <a href="http://www.ams.org/samplings/feature-column/fc-2016-05">article</a> from which the figure came states that “In todays textbooks the problem, usually involving a river, involves walking along one bank and then swimming across; this corresponds to setting <span class="math inline">\(g=0\)</span> in lHospitals example, and leads to a quadratic equation.” Lets see that case, which we can get in our notation by taking <span class="math inline">\(b=0\)</span>:</p>
<div class="cell" data-execution_count="41">
<div class="sourceCode cell-code" id="cb52"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb52-1"><a href="#cb52-1" aria-hidden="true" tabindex="-1"></a>q <span class="op">=</span> <span class="fu">ex</span>(b<span class="op">=&gt;</span><span class="fl">0</span>)</span>
<span id="cb52-2"><a href="#cb52-2" aria-hidden="true" tabindex="-1"></a><span class="fu">factor</span>(q)</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="42">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
- \left(- L + x\right)^{2} \left(a^{2} r_{0}^{2} + r_{0}^{2} x^{2} - r_{1}^{2} x^{2}\right)
\]
</span>
</div>
</div>
<p>We see two terms: one with <span class="math inline">\(x=L\)</span> and another quadratic. For the simple case <span class="math inline">\(r_0=r_1\)</span>, a straight line is the best solution, and this corresponds to <span class="math inline">\(x=L\)</span>, which is clear from the formula above, as we only have one solution to the following:</p>
<div class="cell" data-execution_count="42">
<div class="sourceCode cell-code" id="cb53"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb53-1"><a href="#cb53-1" aria-hidden="true" tabindex="-1"></a><span class="fu">solve</span>(<span class="fu">q</span>(r1<span class="op">=&gt;</span>r0), 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="43">
<pre><code>1-element Vector{Sym}:
L</code></pre>
</div>
</div>
<p>Well, not so fast. We need to check the other endpoint, <span class="math inline">\(x=0\)</span>:</p>
<div class="cell" data-execution_count="43">
<div class="sourceCode cell-code" id="cb55"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb55-1"><a href="#cb55-1" aria-hidden="true" tabindex="-1"></a>ta <span class="op">=</span> <span class="fu">t</span>(b<span class="op">=&gt;</span><span class="fl">0</span>, r1<span class="op">=&gt;</span>r0)</span>
<span id="cb55-2"><a href="#cb55-2" aria-hidden="true" tabindex="-1"></a><span class="fu">ta</span>(x<span class="op">=&gt;</span><span class="fl">0</span>), <span class="fu">ta</span>(x<span class="op">=&gt;</span>L)</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="44">
<pre><code>(L/r0 + a/r0, sqrt(L^2 + a^2)/r0)</code></pre>
</div>
</div>
<p>The value at <span class="math inline">\(x=L\)</span> is smaller, as <span class="math inline">\(L^2 + a^2 \leq (L+a)^2\)</span>. (Well, that was a bit pedantic. The travel rates being identical means the fastest path will also be the shortest path and that is clearly <span class="math inline">\(x=L\)</span> and not <span class="math inline">\(x=0\)</span>.)</p>
<p>Now, if, say, travel above the line is half as slow as travel along, then <span class="math inline">\(2r_0 = r_1\)</span>, and the critical points will be:</p>
<div class="cell" data-execution_count="44">
<div class="sourceCode cell-code" id="cb57"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb57-1"><a href="#cb57-1" aria-hidden="true" tabindex="-1"></a>out <span class="op">=</span> <span class="fu">solve</span>(<span class="fu">q</span>(r1 <span class="op">=&gt;</span> <span class="fl">2</span>r0), 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="45">
<pre><code>2-element Vector{Sym}:
L
sqrt(3)*a/3</code></pre>
</div>
</div>
<p>It is hard to tell which would minimize time without more work. To check a case (<span class="math inline">\(a=1, L=2, r_0=1\)</span>) we might have</p>
<div class="cell" data-execution_count="45">
<div class="sourceCode cell-code" id="cb59"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb59-1"><a href="#cb59-1" aria-hidden="true" tabindex="-1"></a>x_straight <span class="op">=</span> <span class="fu">t</span>(r1 <span class="op">=&gt;</span><span class="fl">2</span>r0, b<span class="op">=&gt;</span><span class="fl">0</span>, x<span class="op">=&gt;</span>out[<span class="fl">1</span>], a<span class="op">=&gt;</span><span class="fl">1</span>, L<span class="op">=&gt;</span><span class="fl">2</span>, r0 <span class="op">=&gt;</span> <span class="fl">1</span>) <span class="co"># for x=L</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="46">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
\sqrt{5}
\]
</span>
</div>
</div>
<p>Compared to the smaller (<span class="math inline">\(x=\sqrt{3}a/3\)</span>):</p>
<div class="cell" data-execution_count="46">
<div class="sourceCode cell-code" id="cb60"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb60-1"><a href="#cb60-1" aria-hidden="true" tabindex="-1"></a>x_angle <span class="op">=</span> <span class="fu">t</span>(r1 <span class="op">=&gt;</span><span class="fl">2</span>r0, b<span class="op">=&gt;</span><span class="fl">0</span>, x<span class="op">=&gt;</span>out[<span class="fl">2</span>], a<span class="op">=&gt;</span><span class="fl">1</span>, L<span class="op">=&gt;</span><span class="fl">2</span>, r0 <span class="op">=&gt;</span> <span class="fl">1</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="47">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
\frac{\sqrt{3}}{2} + 1
\]
</span>
</div>
</div>
<p>What about <span class="math inline">\(x=0\)</span>?</p>
<div class="cell" data-execution_count="47">
<div class="sourceCode cell-code" id="cb61"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb61-1"><a href="#cb61-1" aria-hidden="true" tabindex="-1"></a>x_bent <span class="op">=</span> <span class="fu">t</span>(r1 <span class="op">=&gt;</span><span class="fl">2</span>r0, b<span class="op">=&gt;</span><span class="fl">0</span>, x<span class="op">=&gt;</span><span class="fl">0</span>, a<span class="op">=&gt;</span><span class="fl">1</span>, L<span class="op">=&gt;</span><span class="fl">2</span>, r0 <span class="op">=&gt;</span> <span class="fl">1</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="48">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
2
\]
</span>
</div>
</div>
<p>The value of <span class="math inline">\(x=\sqrt{3}a/3\)</span> minimizes time:</p>
<div class="cell" data-execution_count="48">
<div class="sourceCode cell-code" id="cb62"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb62-1"><a href="#cb62-1" aria-hidden="true" tabindex="-1"></a><span class="fu">min</span>(x_straight, x_angle, x_bent)</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="49">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
\frac{\sqrt{3}}{2} + 1
\]
</span>
</div>
</div>
<p>The traveler in this case is advised to head to the <span class="math inline">\(x\)</span> axis at <span class="math inline">\(x=\sqrt{3}a/3\)</span> and then travel along the <span class="math inline">\(x\)</span> axis.</p>
<p>Will this approach always be true? Consider different parameters, say we switch the values of <span class="math inline">\(a\)</span> and <span class="math inline">\(L\)</span> so <span class="math inline">\(a &gt; L\)</span>:</p>
<div class="cell" data-execution_count="49">
<div class="sourceCode cell-code" id="cb63"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb63-1"><a href="#cb63-1" aria-hidden="true" tabindex="-1"></a>pts <span class="op">=</span> [<span class="fl">0</span>, out<span class="op">...</span>]</span>
<span id="cb63-2"><a href="#cb63-2" aria-hidden="true" tabindex="-1"></a>m,i <span class="op">=</span> <span class="fu">findmin</span>([<span class="fu">t</span>(r1 <span class="op">=&gt;</span><span class="fl">2</span>r0, b<span class="op">=&gt;</span><span class="fl">0</span>, x<span class="op">=&gt;</span>u, a<span class="op">=&gt;</span><span class="fl">2</span>, L<span class="op">=&gt;</span><span class="fl">1</span>, r0 <span class="op">=&gt;</span> <span class="fl">1</span>) for u <span class="kw">in</span> pts]) <span class="co"># min, index</span></span>
<span id="cb63-3"><a href="#cb63-3" aria-hidden="true" tabindex="-1"></a>m, pts[i]</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="50">
<pre><code>(sqrt(5), L)</code></pre>
</div>
</div>
<p>Here traveling directly to the point <span class="math inline">\((L,0)\)</span> is fastest. Though travel is slower, the route is more direct and there is no time saved by taking the longer route with faster travel for part of it.</p>
</section>
</section>
<section id="unbounded-domains" class="level2" data-number="26.4">
<h2 data-number="26.4" class="anchored" data-anchor-id="unbounded-domains"><span class="header-section-number">26.4</span> Unbounded domains</h2>
<p>Maximize the function <span class="math inline">\(xe^{-(1/2) x^2}\)</span> over the interval <span class="math inline">\([0, \infty)\)</span>.</p>
<p>Here the extreme value theorem doesnt technically apply, as we dont have a closed interval. However, <strong>if</strong> we can eliminate the endpoints as candidates, then we should be able to convince ourselves the maximum must occur at a critical point of <span class="math inline">\(f(x)\)</span>. (If not, then convince yourself for all sufficiently large <span class="math inline">\(M\)</span> the maximum over <span class="math inline">\([0,M]\)</span> occurs at a critical point, not an endpoint. Then let <span class="math inline">\(M\)</span> go to infinity. In general, for an optimization problem of a continuous function on the interval <span class="math inline">\((a,b)\)</span> if the right limit at <span class="math inline">\(a\)</span> and left limit at <span class="math inline">\(b\)</span> can be ruled out as candidates, the optimal value must occur at a critical point.)</p>
<p>So to approach this problem we first graph it over a wide interval.</p>
<div class="cell" data-execution_count="50">
<div class="sourceCode cell-code" id="cb65"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb65-1"><a href="#cb65-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x) <span class="op">=</span> x <span class="op">*</span> <span class="fu">exp</span>(<span class="op">-</span>x<span class="op">^</span><span class="fl">2</span>)</span>
<span id="cb65-2"><a href="#cb65-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(f, <span class="fl">0</span>, <span class="fl">100</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="51">
<p><img src="optimization_files/figure-html/cell-51-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Clearly the action is nearer to <span class="math inline">\(1\)</span> than <span class="math inline">\(100\)</span>. We try graphing the derivative near that area:</p>
<div class="cell" data-execution_count="51">
<div class="sourceCode cell-code" id="cb66"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb66-1"><a href="#cb66-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(f<span class="op">'</span>, <span class="fl">0</span>, <span class="fl">5</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="52">
<p><img src="optimization_files/figure-html/cell-52-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>This shows the value of interest near <span class="math inline">\(0.7\)</span> for a critical point. We use <code>find_zero</code> with <span class="math inline">\([0,1]\)</span> as a bracket</p>
<div class="cell" data-execution_count="52">
<div class="sourceCode cell-code" id="cb67"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb67-1"><a href="#cb67-1" aria-hidden="true" tabindex="-1"></a>c <span class="op">=</span> <span class="fu">find_zero</span>(f<span class="op">'</span>, (<span class="fl">0</span>, <span class="fl">1</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="53">
<pre><code>0.7071067811865476</code></pre>
</div>
</div>
<p>The maximum is then at</p>
<div class="cell" data-execution_count="53">
<div class="sourceCode cell-code" id="cb69"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb69-1"><a href="#cb69-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(c)</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="54">
<pre><code>0.42888194248035333</code></pre>
</div>
</div>
<section id="example-minimize-the-surface-area-of-a-can" class="level5">
<h5 class="anchored" data-anchor-id="example-minimize-the-surface-area-of-a-can">Example: Minimize the surface area of a can</h5>
<p>For a more applied problem of this type (infinite domain), consider a can of some soft drink that is to contain <span class="math inline">\(355\)</span>ml which is <span class="math inline">\(355\)</span> cubic centimeters. We use metric units, as the relationship between volume (cubic centimeters) and fluid amount (ml) is clear. A can to hold this amount is produced in the shape of cylinder with radius <span class="math inline">\(r\)</span> and height <span class="math inline">\(h\)</span>. The materials involved give the surface area, which would be:</p>
<p><span class="math display">\[
SA = h \cdot 2\pi r + 2 \cdot \pi r^2.
\]</span></p>
<p>The volume satisfies:</p>
<p><span class="math display">\[
V = 355 = h \cdot \pi r^2.
\]</span></p>
<p>Find the values of <span class="math inline">\(r\)</span> and <span class="math inline">\(h\)</span> which minimize the surface area.</p>
<p>First the surface area in both variables is given by</p>
<div class="cell" data-execution_count="54">
<div class="sourceCode cell-code" id="cb71"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb71-1"><a href="#cb71-1" aria-hidden="true" tabindex="-1"></a><span class="fu">SA</span>(h, r) <span class="op">=</span> h <span class="op">*</span> <span class="fl">2</span>pi <span class="op">*</span> r <span class="op">+</span> <span class="fl">2</span>pi <span class="op">*</span> r<span class="op">^</span><span class="fl">2</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="55">
<pre><code>SA (generic function with 1 method)</code></pre>
</div>
</div>
<p>Solving from the constraint on the volume for <code>h</code> in terms of <code>r</code> yields:</p>
<div class="cell" data-execution_count="55">
<div class="sourceCode cell-code" id="cb73"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb73-1"><a href="#cb73-1" aria-hidden="true" tabindex="-1"></a><span class="fu">canheight</span>(r) <span class="op">=</span> <span class="fl">355</span> <span class="op">/</span> (<span class="cn">pi</span> <span class="op">*</span> r<span class="op">^</span><span class="fl">2</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="56">
<pre><code>canheight (generic function with 1 method)</code></pre>
</div>
</div>
<p>Composing gives a function of <code>r</code> alone:</p>
<div class="cell" data-execution_count="56">
<div class="sourceCode cell-code" id="cb75"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb75-1"><a href="#cb75-1" aria-hidden="true" tabindex="-1"></a><span class="fu">SA</span>(r) <span class="op">=</span> <span class="fu">SA</span>(<span class="fu">canheight</span>(r), r)</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="57">
<pre><code>SA (generic function with 2 methods)</code></pre>
</div>
</div>
<p>This is minimized subject to the constraint that <span class="math inline">\(r \geq 0\)</span>. A quick glance shows that as <span class="math inline">\(r\)</span> gets close to <span class="math inline">\(0\)</span>, the can must get infinitely tall to contain that fixed volume, and would have infinite surface area as the <span class="math inline">\(1/r^2\)</span> in the first term implies. On the other hand, as <span class="math inline">\(r\)</span> goes to infinity, the height must go to <span class="math inline">\(0\)</span> to make a really flat can. Again, we would have infinite surface area, as the <span class="math inline">\(r^2\)</span> term at the end indicates. With this observation, we can rule out the endpoints as possible minima, so any minima must occur at a critical point.</p>
<p>We start by making a graph, making an educated guess that the answer is somewhere near a real life answer, or around <span class="math inline">\(3\)</span>-<span class="math inline">\(5\)</span> cms in radius:</p>
<div class="cell" data-execution_count="57">
<div class="sourceCode cell-code" id="cb77"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb77-1"><a href="#cb77-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(SA, <span class="fl">2</span>, <span class="fl">10</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="58">
<p><img src="optimization_files/figure-html/cell-58-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The minimum looks to be around <span class="math inline">\(4\)</span>cm and is clearly between <span class="math inline">\(2\)</span>cm and <span class="math inline">\(6\)</span>cm. We can use <code>find_zero</code> to zero in on the value of the critical point:</p>
<div class="cell" data-execution_count="58">
<div class="sourceCode cell-code" id="cb78"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb78-1"><a href="#cb78-1" aria-hidden="true" tabindex="-1"></a>rₛₐ <span class="op">=</span> <span class="fu">find_zero</span>(SA<span class="op">'</span>, (<span class="fl">2</span>, <span class="fl">6</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="59">
<pre><code>3.8372152480156734</code></pre>
</div>
</div>
<p>Okay, <span class="math inline">\(3.837...\)</span> is our answer for <span class="math inline">\(r\)</span>. Use this to get <span class="math inline">\(h\)</span>:</p>
<div class="cell" data-execution_count="59">
<div class="sourceCode cell-code" id="cb80"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb80-1"><a href="#cb80-1" aria-hidden="true" tabindex="-1"></a><span class="fu">canheight</span>(rₛₐ)</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="60">
<pre><code>7.674430496031345</code></pre>
</div>
</div>
<p>This produces a can which is about square in profile. This is not how most cans look though. Perhaps our model is too simple, or the cans are optimized for some other purpose than minimizing materials.</p>
</section>
</section>
<section id="questions" class="level2" data-number="26.5">
<h2 data-number="26.5" class="anchored" data-anchor-id="questions"><span class="header-section-number">26.5</span> Questions</h2>
<section id="question" class="level6">
<h6 class="anchored" data-anchor-id="question">Question</h6>
<p>A geometric figure has area given in terms of two measurements by <span class="math inline">\(A=\pi a b\)</span> and perimeter <span class="math inline">\(P = \pi (a + b)\)</span>. If the perimeter is fixed to be 20 units long, what is the maximal area the figure can be?</p>
<div class="cell" data-hold="true" data-execution_count="60">
<div class="cell-output cell-output-display" data-execution_count="61">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="14410026343440980595" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_14410026343440980595">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="14410026343440980595" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="14410026343440980595_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("14410026343440980595").addEventListener("change", function() {
var correct = (Math.abs(this.value - 31.83098861837907) <= 0.001);
var msgBox = document.getElementById('14410026343440980595_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_14410026343440980595")
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_14410026343440980595")
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>A geometric figure has area given in terms of two measurements by <span class="math inline">\(A=\pi a b\)</span> and perimeter <span class="math inline">\(P=\pi \cdot \sqrt{a^2 + b^2}/2\)</span>. If the perimeter is 20 units long, what is the maximal area?</p>
<div class="cell" data-hold="true" data-execution_count="61">
<div class="cell-output cell-output-display" data-execution_count="62">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="4238723021423998893" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_4238723021423998893">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="4238723021423998893" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="4238723021423998893_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("4238723021423998893").addEventListener("change", function() {
var correct = (Math.abs(this.value - 254.64790894703262) <= 0.001);
var msgBox = document.getElementById('4238723021423998893_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_4238723021423998893")
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_4238723021423998893")
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>A rancher with <span class="math inline">\(10\)</span> meters of fence wishes to make a pen adjacent to an existing fence. The pen will be a rectangle with one edge using the existing fence. Say that has length <span class="math inline">\(x\)</span>, then <span class="math inline">\(10 = 2y + x\)</span>, with <span class="math inline">\(y\)</span> the other dimension of the pen. What is the maximum area that can be made?</p>
<div class="cell" data-hold="true" data-execution_count="62">
<div class="cell-output cell-output-display" data-execution_count="63">
<p><img src="optimization_files/figure-html/cell-63-output-1.svg" class="img-fluid"></p>
</div>
</div>
<div class="cell" data-hold="true" data-execution_count="63">
<div class="cell-output cell-output-display" data-execution_count="64">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="13208432303360697487" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_13208432303360697487">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="13208432303360697487" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="13208432303360697487_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("13208432303360697487").addEventListener("change", function() {
var correct = (Math.abs(this.value - 12.5) <= 0.001);
var msgBox = document.getElementById('13208432303360697487_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_13208432303360697487")
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_13208432303360697487")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>Is there “symmetry” in the answer between <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="64">
<div class="cell-output cell-output-display" data-execution_count="65">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="1036416324436824696" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_1036416324436824696">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_1036416324436824696_1">
<input class="form-check-input" type="radio" name="radio_1036416324436824696" id="radio_1036416324436824696_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1036416324436824696_2">
<input class="form-check-input" type="radio" name="radio_1036416324436824696" id="radio_1036416324436824696_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="1036416324436824696_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_1036416324436824696"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('1036416324436824696_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_1036416324436824696")
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_1036416324436824696")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>What is you were do do two pens like this back to back, then the answer would involve a rectangle. Is there symmetry in the answer now?</p>
<div class="cell" data-hold="true" data-execution_count="65">
<div class="cell-output cell-output-display" data-execution_count="66">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="7388943100715285629" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_7388943100715285629">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_7388943100715285629_1">
<input class="form-check-input" type="radio" name="radio_7388943100715285629" id="radio_7388943100715285629_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7388943100715285629_2">
<input class="form-check-input" type="radio" name="radio_7388943100715285629" id="radio_7388943100715285629_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="7388943100715285629_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_7388943100715285629"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('7388943100715285629_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_7388943100715285629")
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_7388943100715285629")
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>A rectangle of sides <span class="math inline">\(w\)</span> and <span class="math inline">\(h\)</span> has fixed area <span class="math inline">\(20\)</span>. What is the <em>smallest</em> perimeter it can have?</p>
<div class="cell" data-hold="true" data-execution_count="66">
<div class="cell-output cell-output-display" data-execution_count="67">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="14287542307063268678" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_14287542307063268678">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="14287542307063268678" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="14287542307063268678_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("14287542307063268678").addEventListener("change", function() {
var correct = (Math.abs(this.value - 17.88854381999832) <= 0.001);
var msgBox = document.getElementById('14287542307063268678_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_14287542307063268678")
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_14287542307063268678")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
</section>
<section id="question-4" class="level6">
<h6 class="anchored" data-anchor-id="question-4">Question</h6>
<p>A rectangle of sides <span class="math inline">\(w\)</span> and <span class="math inline">\(h\)</span> has fixed area <span class="math inline">\(20\)</span>. What is the <em>largest</em> perimeter it can have?</p>
<div class="cell" data-hold="true" data-execution_count="67">
<div class="cell-output cell-output-display" data-execution_count="68">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="13019763125264887210" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_13019763125264887210">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_13019763125264887210_1">
<input class="form-check-input" type="radio" name="radio_13019763125264887210" id="radio_13019763125264887210_1" value="1">
<span class="label-body px-1">
It can be infinite
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13019763125264887210_2">
<input class="form-check-input" type="radio" name="radio_13019763125264887210" id="radio_13019763125264887210_2" value="2">
<span class="label-body px-1">
It is also 20
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13019763125264887210_3">
<input class="form-check-input" type="radio" name="radio_13019763125264887210" id="radio_13019763125264887210_3" value="3">
<span class="label-body px-1">
\(17.888\)
</span>
</label>
</div>
</div>
</div>
<div id="13019763125264887210_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_13019763125264887210"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('13019763125264887210_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_13019763125264887210")
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_13019763125264887210")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-5" class="level6">
<h6 class="anchored" data-anchor-id="question-5">Question</h6>
<p>A cardboard box is to be designed with a square base and an open top holding a fixed volume <span class="math inline">\(V\)</span>. What dimensions yield the minimal surface area?</p>
<p>If this problem were approached symbolically, we might see the following code. First:</p>
<div class="sourceCode cell-code" id="cb82"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb82-1"><a href="#cb82-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> V<span class="op">::</span><span class="dt">positive </span>x<span class="op">::</span><span class="dt">positive </span>z<span class="op">::</span><span class="dt">positive</span></span>
<span id="cb82-2"><a href="#cb82-2" aria-hidden="true" tabindex="-1"></a>SA <span class="op">=</span> <span class="fl">1</span> <span class="op">*</span> x <span class="op">*</span> x <span class="op">+</span> <span class="fl">4</span> <span class="op">*</span> x <span class="op">*</span> z</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>What does this express?</p>
<div class="cell" data-hold="true" data-execution_count="69">
<div class="cell-output cell-output-display" data-execution_count="69">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="746970759183802381" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_746970759183802381">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_746970759183802381_1">
<input class="form-check-input" type="radio" name="radio_746970759183802381" id="radio_746970759183802381_1" value="1">
<span class="label-body px-1">
The box has a square base with open top, so <code>x*x</code> is the amount of material in the base; the 4 sides each have <code>x*z</code> area.
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_746970759183802381_2">
<input class="form-check-input" type="radio" name="radio_746970759183802381" id="radio_746970759183802381_2" value="2">
<span class="label-body px-1">
The surface area of a box is <code>6x*x</code>, so this is wrong.
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_746970759183802381_3">
<input class="form-check-input" type="radio" name="radio_746970759183802381" id="radio_746970759183802381_3" value="3">
<span class="label-body px-1">
The volume is a fixed amount, so is <code>x*x*z</code>, with sides suitably labeled
</span>
</label>
</div>
</div>
</div>
<div id="746970759183802381_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_746970759183802381"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('746970759183802381_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_746970759183802381")
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_746970759183802381")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>What does this command express?</p>
<div class="sourceCode cell-code" id="cb83"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb83-1"><a href="#cb83-1" aria-hidden="true" tabindex="-1"></a>SA <span class="op">=</span> <span class="fu">subs</span>(SA, z <span class="op">=&gt;</span> V <span class="op">/</span> x<span class="op">^</span><span class="fl">2</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell" data-hold="true" data-execution_count="71">
<div class="cell-output cell-output-display" data-execution_count="70">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="18441017924815697983" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_18441017924815697983">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_18441017924815697983_1">
<input class="form-check-input" type="radio" name="radio_18441017924815697983" id="radio_18441017924815697983_1" value="1">
<span class="label-body px-1">
This command replaces <code>z</code>, reparameterizing in <code>V</code> instead.
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_18441017924815697983_2">
<input class="form-check-input" type="radio" name="radio_18441017924815697983" id="radio_18441017924815697983_2" value="2">
<span class="label-body px-1">
This command replaces <code>z</code> with an expression in <code>x</code> using the constraint of fixed volume <code>V</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_18441017924815697983_3">
<input class="form-check-input" type="radio" name="radio_18441017924815697983" id="radio_18441017924815697983_3" value="3">
<span class="label-body px-1">
This command is merely algebraic simplification
</span>
</label>
</div>
</div>
</div>
<div id="18441017924815697983_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_18441017924815697983"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('18441017924815697983_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_18441017924815697983")
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_18441017924815697983")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>What does this command find?</p>
<div class="sourceCode cell-code" id="cb84"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb84-1"><a href="#cb84-1" aria-hidden="true" tabindex="-1"></a><span class="fu">solve</span>(<span class="fu">diff</span>(SA, x) <span class="op">~</span> <span class="fl">0</span>, x)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell" data-hold="true" data-execution_count="73">
<div class="cell-output cell-output-display" data-execution_count="71">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="6420101803047130942" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_6420101803047130942">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_6420101803047130942_1">
<input class="form-check-input" type="radio" name="radio_6420101803047130942" id="radio_6420101803047130942_1" value="1">
<span class="label-body px-1">
This solves \(SA'=0\), that is it find critical points of a continuously differentiable function
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6420101803047130942_2">
<input class="form-check-input" type="radio" name="radio_6420101803047130942" id="radio_6420101803047130942_2" value="2">
<span class="label-body px-1">
This solves for \(V\) the fixed, but unknown volume
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6420101803047130942_3">
<input class="form-check-input" type="radio" name="radio_6420101803047130942" id="radio_6420101803047130942_3" value="3">
<span class="label-body px-1">
This checks the values of <code>SA</code> at the end points of the domain
</span>
</label>
</div>
</div>
</div>
<div id="6420101803047130942_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_6420101803047130942"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('6420101803047130942_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_6420101803047130942")
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_6420101803047130942")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>What do these commands do?</p>
<div class="sourceCode cell-code" id="cb85"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb85-1"><a href="#cb85-1" aria-hidden="true" tabindex="-1"></a>cps <span class="op">=</span> <span class="fu">solve</span>(<span class="fu">diff</span>(SA, x) <span class="op">~</span> <span class="fl">0</span>, x)</span>
<span id="cb85-2"><a href="#cb85-2" aria-hidden="true" tabindex="-1"></a>xx <span class="op">=</span> <span class="fu">filter</span>(isreal, cps)[<span class="fl">1</span>]</span>
<span id="cb85-3"><a href="#cb85-3" aria-hidden="true" tabindex="-1"></a><span class="fu">diff</span>(SA, x, x)(xx) <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" data-hold="true" data-execution_count="75">
<div class="cell-output cell-output-display" data-execution_count="72">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="6657013094529428218" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_6657013094529428218">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_6657013094529428218_1">
<input class="form-check-input" type="radio" name="radio_6657013094529428218" id="radio_6657013094529428218_1" value="1">
<span class="label-body px-1">
This applies the first derivative test to the lone <em>real</em> critical point showing there is a local minimum at that point.
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6657013094529428218_2">
<input class="form-check-input" type="radio" name="radio_6657013094529428218" id="radio_6657013094529428218_2" value="2">
<span class="label-body px-1">
This finds the `<code>4</code>th derivative of <code>SA</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6657013094529428218_3">
<input class="form-check-input" type="radio" name="radio_6657013094529428218" id="radio_6657013094529428218_3" value="3">
<span class="label-body px-1">
This applies the second derivative test to the lone <em>real</em> critical point showing there is a local minimum at that point.
</span>
</label>
</div>
</div>
</div>
<div id="6657013094529428218_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_6657013094529428218"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('6657013094529428218_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_6657013094529428218")
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_6657013094529428218")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-6" class="level6">
<h6 class="anchored" data-anchor-id="question-6">Question</h6>
<p>A rain gutter is constructed from a 30” wide sheet of tin by bending it into thirds. If the sides are bent 90 degrees, then the cross-sectional area would be <span class="math inline">\(100 = 10^2\)</span>. This is not the largest possible amount. For example, if the sides are bent by 45 degrees, the cross sectional area is:</p>
<div class="cell" data-hold="true" data-execution_count="76">
<div class="cell-output cell-output-display" data-execution_count="73">
<pre><code>120.71067811865474</code></pre>
</div>
</div>
<p>Find a value in degrees that gives the maximum. (The first task is to write the area in terms of <span class="math inline">\(\theta\)</span>.</p>
<div class="cell" data-hold="true" data-execution_count="77">
<div class="cell-output cell-output-display" data-execution_count="74">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="9147017952071217698" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_9147017952071217698">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="9147017952071217698" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="9147017952071217698_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("9147017952071217698").addEventListener("change", function() {
var correct = (Math.abs(this.value - 60.00000000000001) <= 0.001);
var msgBox = document.getElementById('9147017952071217698_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_9147017952071217698")
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_9147017952071217698")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
</section>
<section id="question-non-norman-windows" class="level6">
<h6 class="anchored" data-anchor-id="question-non-norman-windows">Question Non-Norman windows</h6>
<p>Suppose our new “Norman” window has half circular tops at the top and bottom? If the perimeter is fixed at <span class="math inline">\(20\)</span> and the dimensions of the rectangle are <span class="math inline">\(x\)</span> for the width and <span class="math inline">\(y\)</span> for the height.</p>
<p>What is the value of <span class="math inline">\(y\)</span> that maximizes the area?</p>
<div class="cell" data-hold="true" data-execution_count="78">
<div class="cell-output cell-output-display" data-execution_count="75">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="8649951940268082728" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_8649951940268082728">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="8649951940268082728" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="8649951940268082728_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("8649951940268082728").addEventListener("change", function() {
var correct = (Math.abs(this.value - 0.0) <= 0.001);
var msgBox = document.getElementById('8649951940268082728_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_8649951940268082728")
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_8649951940268082728")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
</section>
<section id="question-thanks-httpswww.math.ucdavis.edukouba" class="level6">
<h6 class="anchored" data-anchor-id="question-thanks-httpswww.math.ucdavis.edukouba">Question (Thanks https://www.math.ucdavis.edu/~kouba)</h6>
<p>A movie screen projects on a wall 20 feet high beginning 10 feet above the floor. This figure shows <span class="math inline">\(\theta\)</span> for <span class="math inline">\(x=30\)</span>:</p>
<div class="cell" data-hold="true" data-execution_count="79">
<div class="cell-output cell-output-display" data-execution_count="76">
<p><img src="optimization_files/figure-html/cell-80-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>What value of <span class="math inline">\(x\)</span> gives the largest angle <span class="math inline">\(\theta\)</span>? (In degrees.)</p>
<div class="cell" data-hold="true" data-execution_count="80">
<div class="cell-output cell-output-display" data-execution_count="77">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="5558061039647112731" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_5558061039647112731">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="5558061039647112731" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="5558061039647112731_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("5558061039647112731").addEventListener("change", function() {
var correct = (Math.abs(this.value - 30.000000000000004) <= 0.1);
var msgBox = document.getElementById('5558061039647112731_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_5558061039647112731")
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_5558061039647112731")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
</section>
<section id="question-7" class="level6">
<h6 class="anchored" data-anchor-id="question-7">Question</h6>
<p>A maximum likelihood estimator is a value derived by maximizing a function. For example, if</p>
<div class="cell" data-execution_count="81">
<div class="sourceCode cell-code" id="cb87"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb87-1"><a href="#cb87-1" aria-hidden="true" tabindex="-1"></a><span class="fu">Likhood</span>(t) <span class="op">=</span> t<span class="op">^</span><span class="fl">3</span> <span class="op">*</span> <span class="fu">exp</span>(<span class="op">-</span><span class="fl">3</span>t) <span class="op">*</span> <span class="fu">exp</span>(<span class="op">-</span><span class="fl">2</span>t) <span class="op">*</span> <span class="fu">exp</span>(<span class="op">-</span><span class="fl">4</span>t) <span class="co">## 0 &lt;= t &lt;= 10</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="78">
<pre><code>Likhood (generic function with 1 method)</code></pre>
</div>
</div>
<p>Then <code>Likhood(t)</code> is continuous and has single peak, so the maximum occurs at the lone critical point. It turns out that this problem is bit sensitive to an initial condition, so we bracket</p>
<div class="cell" data-execution_count="82">
<div class="sourceCode cell-code" id="cb89"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb89-1"><a href="#cb89-1" aria-hidden="true" tabindex="-1"></a><span class="fu">find_zero</span>(Likhood<span class="op">'</span>, (<span class="fl">0.1</span>, <span class="fl">0.5</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="79">
<pre><code>0.3333333333333333</code></pre>
</div>
</div>
<p>Now if <span class="math inline">\(Likhood(t) = \exp(-3t) \cdot \exp(-2t) \cdot \exp(-4t), \quad 0 \leq t \leq 10\)</span>, by graphing, explain why the same approach wont work:</p>
<div class="cell" data-hold="true" data-execution_count="83">
<div class="cell-output cell-output-display" data-execution_count="80">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="6469700976523781378" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_6469700976523781378">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_6469700976523781378_1">
<input class="form-check-input" type="radio" name="radio_6469700976523781378" id="radio_6469700976523781378_1" value="1">
<span class="label-body px-1">
\(Likhood(t)\) is not continuous on \(0\) to \(10\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6469700976523781378_2">
<input class="form-check-input" type="radio" name="radio_6469700976523781378" id="radio_6469700976523781378_2" value="2">
<span class="label-body px-1">
It does work and the answer is x = 2.27...
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6469700976523781378_3">
<input class="form-check-input" type="radio" name="radio_6469700976523781378" id="radio_6469700976523781378_3" value="3">
<span class="label-body px-1">
\(Likhood(t)\) takes its maximum at a boundary point - not a critical point
</span>
</label>
</div>
</div>
</div>
<div id="6469700976523781378_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_6469700976523781378"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('6469700976523781378_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_6469700976523781378")
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_6469700976523781378")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-8" class="level5">
<h5 class="anchored" data-anchor-id="question-8">Question</h5>
<p>Let <span class="math inline">\(x_1\)</span>, <span class="math inline">\(x_2\)</span>, <span class="math inline">\(x_n\)</span> be a set of unspecified numbers in a data set. Form the expression <span class="math inline">\(s(x) = (x-x_1)^2 + \cdots (x-x_n)^2\)</span>. What is the smallest this can be (in <span class="math inline">\(x\)</span>)?</p>
<p>We approach this using <code>SymPy</code> and <span class="math inline">\(n=10\)</span></p>
<div class="sourceCode cell-code" id="cb91"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb91-1"><a href="#cb91-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> s xs[<span class="fl">1</span><span class="op">:</span><span class="fl">10</span>]</span>
<span id="cb91-2"><a href="#cb91-2" aria-hidden="true" tabindex="-1"></a><span class="fu">s</span>(x) <span class="op">=</span> <span class="fu">sum</span>((x<span class="op">-</span>xi)<span class="op">^</span><span class="fl">2</span> <span class="cf">for</span> xi <span class="kw">in</span> xs)</span>
<span id="cb91-3"><a href="#cb91-3" aria-hidden="true" tabindex="-1"></a>cps <span class="op">=</span> <span class="fu">solve</span>(<span class="fu">diff</span>(<span class="fu">s</span>(x), x), x)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>Run the above code. Baseed on the critical points found, what do you guess will be the minimum value in terms of the values <span class="math inline">\(x_1\)</span>, <span class="math inline">\(x_2, \dots\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="85">
<div class="cell-output cell-output-display" data-execution_count="81">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="6874417312423664729" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_6874417312423664729">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_6874417312423664729_1">
<input class="form-check-input" type="radio" name="radio_6874417312423664729" id="radio_6874417312423664729_1" value="1">
<span class="label-body px-1">
The square roots of the values squared, \((x_1^2 + \cdots x_n^2)^2\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6874417312423664729_2">
<input class="form-check-input" type="radio" name="radio_6874417312423664729" id="radio_6874417312423664729_2" value="2">
<span class="label-body px-1">
The median, or middle number, of the values
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6874417312423664729_3">
<input class="form-check-input" type="radio" name="radio_6874417312423664729" id="radio_6874417312423664729_3" value="3">
<span class="label-body px-1">
The mean, or average, of the values
</span>
</label>
</div>
</div>
</div>
<div id="6874417312423664729_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_6874417312423664729"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('6874417312423664729_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_6874417312423664729")
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_6874417312423664729")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<section id="question-9" class="level6">
<h6 class="anchored" data-anchor-id="question-9">Question</h6>
<p>Minimize the function <span class="math inline">\(f(x) = 2x + 3/x\)</span> over <span class="math inline">\((0, \infty)\)</span>.</p>
<div class="cell" data-hold="true" data-execution_count="86">
<div class="cell-output cell-output-display" data-execution_count="82">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="7261566816956016652" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_7261566816956016652">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="7261566816956016652" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="7261566816956016652_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("7261566816956016652").addEventListener("change", function() {
var correct = (Math.abs(this.value - 1.2247448713915892) <= 0.001);
var msgBox = document.getElementById('7261566816956016652_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_7261566816956016652")
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_7261566816956016652")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
</section>
<section id="question-10" class="level6">
<h6 class="anchored" data-anchor-id="question-10">Question</h6>
<p>Of all rectangles of area 4, find the one with smallest perimeter. What is the perimeter?</p>
<div class="cell" data-hold="true" data-execution_count="87">
<div class="cell-output cell-output-display" data-execution_count="83">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="3670977864314057190" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_3670977864314057190">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="3670977864314057190" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="3670977864314057190_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("3670977864314057190").addEventListener("change", function() {
var correct = (Math.abs(this.value - 8.0) <= 0.001);
var msgBox = document.getElementById('3670977864314057190_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_3670977864314057190")
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_3670977864314057190")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
</section>
<section id="question-11" class="level6">
<h6 class="anchored" data-anchor-id="question-11">Question</h6>
<p>A running track is in the shape of two straight aways and two half circles. The total distance (perimeter) is 400 meters. Suppose <span class="math inline">\(w\)</span> is the width (twice the radius of the circles) and <span class="math inline">\(h\)</span> is the height. What dimensions minimize the sum <span class="math inline">\(w + h\)</span>?</p>
<p>You have <span class="math inline">\(P(w, h) = 2\pi \cdot (w/2) + 2\cdot(h-w)\)</span>.</p>
<div class="cell" data-hold="true" data-execution_count="88">
<div class="cell-output cell-output-display" data-execution_count="84">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="2772112494892335987" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_2772112494892335987">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="2772112494892335987" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="2772112494892335987_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("2772112494892335987").addEventListener("change", function() {
var correct = (Math.abs(this.value - 200.0) <= 0.001);
var msgBox = document.getElementById('2772112494892335987_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_2772112494892335987")
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_2772112494892335987")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
</section>
<section id="question-12" class="level6">
<h6 class="anchored" data-anchor-id="question-12">Question</h6>
<p>A cell phone manufacturer wishes to make a rectangular phone with total surface area of 12,000 <span class="math inline">\(mm^2\)</span> and maximal screen area. The screen is surrounded by bezels with sizes of 8<span class="math inline">\(mm\)</span> on the long sides and 32<span class="math inline">\(mm\)</span> on the short sides. (So, for example, the screen width is shorter by <span class="math inline">\(2\cdot 8\)</span> mm than the phone width.)</p>
<p>What are the dimensions (width and height) that allow the maximum screen area?</p>
<p>The width is:</p>
<div class="cell" data-hold="true" data-execution_count="89">
<div class="cell-output cell-output-display" data-execution_count="85">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15174392563900087518" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_15174392563900087518">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="15174392563900087518" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="15174392563900087518_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("15174392563900087518").addEventListener("change", function() {
var correct = (Math.abs(this.value - 54.772255750516614) <= 0.001);
var msgBox = document.getElementById('15174392563900087518_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_15174392563900087518")
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_15174392563900087518")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>The height is?</p>
<div class="cell" data-hold="true" data-execution_count="90">
<div class="cell-output cell-output-display" data-execution_count="86">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="11826684620644474451" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_11826684620644474451">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="11826684620644474451" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="11826684620644474451_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("11826684620644474451").addEventListener("change", function() {
var correct = (Math.abs(this.value - 219.08902300206643) <= 0.001);
var msgBox = document.getElementById('11826684620644474451_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_11826684620644474451")
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_11826684620644474451")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
</section>
<section id="question-13" class="level6">
<h6 class="anchored" data-anchor-id="question-13">Question</h6>
<p>Find the value <span class="math inline">\(x &gt; 0\)</span> which minimizes the distance from the graph of <span class="math inline">\(f(x) = \log_e(x) - x\)</span> to the origin <span class="math inline">\((0,0)\)</span>.</p>
<div class="cell" data-hold="true" data-execution_count="91">
<div class="cell-output cell-output-display" data-execution_count="87">
<p><img src="optimization_files/figure-html/cell-92-output-1.svg" class="img-fluid"></p>
</div>
</div>
<div class="cell" data-hold="true" data-execution_count="92">
<div class="cell-output cell-output-display" data-execution_count="88">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15954247524079189361" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_15954247524079189361">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="15954247524079189361" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="15954247524079189361_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("15954247524079189361").addEventListener("change", function() {
var correct = (Math.abs(this.value - 1.2607180017701087) <= 0.001);
var msgBox = document.getElementById('15954247524079189361_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_15954247524079189361")
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_15954247524079189361")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
</section>
<section id="question-14" class="level6">
<h6 class="anchored" data-anchor-id="question-14">Question</h6>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../derivatives/figures/fcarc-may2016-fig40-300.gif" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Image number <span class="math inline">\(40\)</span> from lHospitals calculus book (the first calculus book). Among all the cones that can be inscribed in a sphere, determine which one has the largest lateral area. (From http://www.ams.org/samplings/feature-column/fc-2016-05)</figcaption><p></p>
</figure>
</div>
<p>The figure above poses a problem about cones in spheres, which can be reduced to a two-dimensional problem. Take a sphere of radius <span class="math inline">\(r=1\)</span>, and imagine a secant line of length <span class="math inline">\(l\)</span> connecting <span class="math inline">\((-r, 0)\)</span> to another point <span class="math inline">\((x,y)\)</span> with <span class="math inline">\(y&gt;0\)</span>. Rotating that line around the <span class="math inline">\(x\)</span> axis produces a cone and its lateral surface is given by <span class="math inline">\(SA=\pi \cdot y \cdot l\)</span>. Write <span class="math inline">\(SA\)</span> as a function of <span class="math inline">\(x\)</span> and solve.</p>
<p>The largest lateral surface area is:</p>
<div class="cell" data-hold="true" data-execution_count="94">
<div class="cell-output cell-output-display" data-execution_count="90">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="7314002774291021204" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_7314002774291021204">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="7314002774291021204" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="7314002774291021204_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("7314002774291021204").addEventListener("change", function() {
var correct = (Math.abs(this.value - 4.836798304624581) <= 0.001);
var msgBox = document.getElementById('7314002774291021204_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_7314002774291021204")
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_7314002774291021204")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>The surface area of a sphere of radius <span class="math inline">\(1\)</span> is <span class="math inline">\(4\pi r^2 = 4 \pi\)</span>. This is how many times greater than that of the largest cone?</p>
<div class="cell" data-hold="true" data-execution_count="95">
<div class="cell-output cell-output-display" data-execution_count="91">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="2494272360147701227" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_2494272360147701227">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_2494272360147701227_1">
<input class="form-check-input" type="radio" name="radio_2494272360147701227" id="radio_2494272360147701227_1" value="1">
<span class="label-body px-1">
exactly four times
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2494272360147701227_2">
<input class="form-check-input" type="radio" name="radio_2494272360147701227" id="radio_2494272360147701227_2" value="2">
<span class="label-body px-1">
about \(2.6\) times as big
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2494272360147701227_3">
<input class="form-check-input" type="radio" name="radio_2494272360147701227" id="radio_2494272360147701227_3" value="3">
<span class="label-body px-1">
exactly \(\pi\) times
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2494272360147701227_4">
<input class="form-check-input" type="radio" name="radio_2494272360147701227" id="radio_2494272360147701227_4" value="4">
<span class="label-body px-1">
about the same
</span>
</label>
</div>
</div>
</div>
<div id="2494272360147701227_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_2494272360147701227"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('2494272360147701227_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_2494272360147701227")
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_2494272360147701227")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-15" class="level6">
<h6 class="anchored" data-anchor-id="question-15">Question</h6>
<p>In the examples the functions <code>argmax(f, itr)</code> and <code>findmin(collection)</code> were used. These have mathematical analogs. What is <code>argmax(f,itr)</code> in terms of math notation, where <span class="math inline">\(vs\)</span> is the iterable collection of values:</p>
<div class="cell" data-hold="true" data-execution_count="96">
<div class="cell-output cell-output-display" data-execution_count="92">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="4275990076349368874" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_4275990076349368874">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_4275990076349368874_1">
<input class="form-check-input" type="radio" name="radio_4275990076349368874" id="radio_4275990076349368874_1" value="1">
<span class="label-body px-1">
\(\{i \mid v_i \text{ in } vs, f(v_i) = \max(f(vs))\}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4275990076349368874_2">
<input class="form-check-input" type="radio" name="radio_4275990076349368874" id="radio_4275990076349368874_2" value="2">
<span class="label-body px-1">
\(\{f(v) \mid v \text{ in } vs, f(v) = \max(f(vs))\}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4275990076349368874_3">
<input class="form-check-input" type="radio" name="radio_4275990076349368874" id="radio_4275990076349368874_3" value="3">
<span class="label-body px-1">
\(\{v \mid v \text{ in } vs, f(v) = \max(f(vs))\}\)
</span>
</label>
</div>
</div>
</div>
<div id="4275990076349368874_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_4275990076349368874"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('4275990076349368874_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_4275990076349368874")
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_4275990076349368874")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>The functions are related: <code>findmax</code> returns the maximum value and an index in the collection for which the value will be largest; <code>argmax</code> returns an element of the set for which the function is largest, so <code>argmax(identify, itr)</code> should correspond to the index found by <code>findmax</code> (through <code>itr[findmax(itr)[2]</code>)</p>
</section>
<section id="question-16" class="level6">
<h6 class="anchored" data-anchor-id="question-16">Question</h6>
<p>Let <span class="math inline">\(f(x) = (a/x)^x\)</span> for <span class="math inline">\(a,x &gt; 0\)</span>. When is this maximized? The following might be helpful</p>
<div class="cell" data-hold="true" data-execution_count="97">
<div class="sourceCode cell-code" id="cb92"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb92-1"><a href="#cb92-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> x<span class="op">::</span><span class="dt">positive </span>a<span class="op">::</span><span class="dt">postive</span></span>
<span id="cb92-2"><a href="#cb92-2" aria-hidden="true" tabindex="-1"></a><span class="fu">diff</span>((a<span class="op">/</span>x)<span class="op">^</span>x, 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="93">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
\left(\frac{a}{x}\right)^{x} \left(\log{\left(\frac{a}{x} \right)} - 1\right)
\]
</span>
</div>
</div>
<p>This can be <code>solve</code>d to discover the answer.</p>
<div class="cell" data-hold="true" data-execution_count="98">
<div class="cell-output cell-output-display" data-execution_count="94">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="2900001479542526707" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_2900001479542526707">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_2900001479542526707_1">
<input class="form-check-input" type="radio" name="radio_2900001479542526707" id="radio_2900001479542526707_1" value="1">
<span class="label-body px-1">
\(a/e\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2900001479542526707_2">
<input class="form-check-input" type="radio" name="radio_2900001479542526707" id="radio_2900001479542526707_2" value="2">
<span class="label-body px-1">
\(e/a\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2900001479542526707_3">
<input class="form-check-input" type="radio" name="radio_2900001479542526707" id="radio_2900001479542526707_3" value="3">
<span class="label-body px-1">
\(e\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2900001479542526707_4">
<input class="form-check-input" type="radio" name="radio_2900001479542526707" id="radio_2900001479542526707_4" value="4">
<span class="label-body px-1">
\(a \cdot e\)
</span>
</label>
</div>
</div>
</div>
<div id="2900001479542526707_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_2900001479542526707"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('2900001479542526707_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_2900001479542526707")
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_2900001479542526707")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-17" class="level6">
<h6 class="anchored" data-anchor-id="question-17">Question</h6>
<p>The ladder problem has an trigonometry-free solution. We show one attributed to <a href="http://www.mathematische-basteleien.de/ladder.htm">Asma</a>.</p>
<div class="cell" data-hold="true" data-execution_count="99">
<div class="cell-output cell-output-display" data-execution_count="95">
<p><img src="optimization_files/figure-html/cell-100-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Introducing a variable <span class="math inline">\(p\)</span>, we get, following the above figure, the ladder of length <span class="math inline">\(c\)</span> touching the wall at <span class="math inline">\(b+bp\)</span> and <span class="math inline">\(a + x\)</span>.</p>
<p>Using similar triangles, we have:</p>
<div class="cell" data-hold="true" data-execution_count="100">
<div class="sourceCode cell-code" id="cb93"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb93-1"><a href="#cb93-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> a<span class="op">::</span><span class="dt">positive </span>b<span class="op">::</span><span class="dt">positive </span>p<span class="op">::</span><span class="dt">positive </span>x<span class="op">::</span><span class="dt">positive</span></span>
<span id="cb93-2"><a href="#cb93-2" aria-hidden="true" tabindex="-1"></a><span class="fu">solve</span>(x<span class="op">/</span>b <span class="op">~</span> (x<span class="op">+</span>a)<span class="op">/</span>(b <span class="op">+</span> b<span class="op">*</span>p), 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="96">
<pre><code>1-element Vector{Sym}:
a/p</code></pre>
</div>
</div>
<p>With <span class="math inline">\(x = a/p\)</span> we get by Pythagoreans theorem that</p>
<p><span class="math display">\[
\begin{align*}
c^2 &amp;= (a + a/p)^2 + (b + bp)^2 \\
&amp;= a^2(1 + \frac{1}{p})^2 + b^2(1+p)^2.
\end{align*}
\]</span></p>
<p>The ladder problem minimizes <span class="math inline">\(c\)</span> or equivalently <span class="math inline">\(c^2\)</span>.</p>
<p>Why is the following set of commands useful in this task:</p>
<div class="sourceCode cell-code" id="cb95"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb95-1"><a href="#cb95-1" aria-hidden="true" tabindex="-1"></a>c2 <span class="op">=</span> a<span class="op">^</span><span class="fl">2</span><span class="fu">*</span>(<span class="fl">1</span> <span class="op">+</span> <span class="fl">1</span><span class="op">/</span>p)<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> b<span class="op">^</span><span class="fl">2</span><span class="fu">*</span>(<span class="fl">1</span><span class="op">+</span>p)<span class="op">^</span><span class="fl">2</span></span>
<span id="cb95-2"><a href="#cb95-2" aria-hidden="true" tabindex="-1"></a>c2p <span class="op">=</span> <span class="fu">diff</span>(c2, p)</span>
<span id="cb95-3"><a href="#cb95-3" aria-hidden="true" tabindex="-1"></a>eq <span class="op">=</span> <span class="fu">numer</span>(<span class="fu">together</span>(c2p))</span>
<span id="cb95-4"><a href="#cb95-4" aria-hidden="true" tabindex="-1"></a><span class="fu">solve</span>(eq <span class="op">~</span> <span class="fl">0</span>, p)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell" data-hold="true" data-execution_count="102">
<div class="cell-output cell-output-display" data-execution_count="97">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="16667848741121653462" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_16667848741121653462">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_16667848741121653462_1">
<input class="form-check-input" type="radio" name="radio_16667848741121653462" id="radio_16667848741121653462_1" value="1">
<span class="label-body px-1">
It finds the critical points
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_16667848741121653462_2">
<input class="form-check-input" type="radio" name="radio_16667848741121653462" id="radio_16667848741121653462_2" value="2">
<span class="label-body px-1">
It finds the minimal value of <code>p</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_16667848741121653462_3">
<input class="form-check-input" type="radio" name="radio_16667848741121653462" id="radio_16667848741121653462_3" value="3">
<span class="label-body px-1">
It finds the minimal value of <code>c</code>
</span>
</label>
</div>
</div>
</div>
<div id="16667848741121653462_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_16667848741121653462"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('16667848741121653462_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_16667848741121653462")
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_16667848741121653462")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>The polynomial <code>nu</code> is what degree in <code>p</code>?</p>
<div class="cell" data-hold="true" data-execution_count="103">
<div class="cell-output cell-output-display" data-execution_count="98">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="3363536479898455844" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_3363536479898455844">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="3363536479898455844" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="3363536479898455844_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("3363536479898455844").addEventListener("change", function() {
var correct = (Math.abs(this.value - 4) <= 0);
var msgBox = document.getElementById('3363536479898455844_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_3363536479898455844")
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_3363536479898455844")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>The only positive real solution for <span class="math inline">\(p\)</span> from <span class="math inline">\(nu\)</span> is</p>
<div class="cell" data-hold="true" data-execution_count="104">
<div class="cell-output cell-output-display" data-execution_count="99">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="427612891768514364" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_427612891768514364">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_427612891768514364_1">
<input class="form-check-input" type="radio" name="radio_427612891768514364" id="radio_427612891768514364_1" value="1">
<span class="label-body px-1">
\(1\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_427612891768514364_2">
<input class="form-check-input" type="radio" name="radio_427612891768514364" id="radio_427612891768514364_2" value="2">
<span class="label-body px-1">
\((a/b)^{2/3}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_427612891768514364_3">
<input class="form-check-input" type="radio" name="radio_427612891768514364" id="radio_427612891768514364_3" value="3">
<span class="label-body px-1">
\(\sqrt{3}/2 \cdot (a/b)^{2/3}\)
</span>
</label>
</div>
</div>
</div>
<div id="427612891768514364_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_427612891768514364"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('427612891768514364_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_427612891768514364")
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_427612891768514364")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-18" class="level6">
<h6 class="anchored" data-anchor-id="question-18">Question</h6>
<p>In <a href="https://www.maa.org/sites/default/files/hall03010308158.pdf">Hall</a> we can find a dozen optimization problems related to the following figure of the parabola <span class="math inline">\(y=x^2\)</span> a point <span class="math inline">\(P=(a,a^2)\)</span>, <span class="math inline">\(a &gt; 0\)</span>, and its normal line. We will do two.</p>
<div class="cell" data-hold="true, echo" data-execution_count="105">
<div class="sourceCode cell-code" id="cb96"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb96-1"><a href="#cb96-1" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> <span class="fu">plot</span>(; legend<span class="op">=</span><span class="cn">false</span>, aspect_ratio<span class="op">=:</span>equal, axis<span class="op">=</span><span class="cn">nothing</span>, border<span class="op">=:</span>none)</span>
<span id="cb96-2"><a href="#cb96-2" aria-hidden="true" tabindex="-1"></a> b <span class="op">=</span> <span class="fl">2</span>.</span>
<span id="cb96-3"><a href="#cb96-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">plot!</span>(p, x <span class="op">-&gt;</span> x<span class="op">^</span><span class="fl">2</span>, <span class="op">-</span>b, b)</span>
<span id="cb96-4"><a href="#cb96-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">plot!</span>(p, [<span class="op">-</span>b,b], [<span class="fl">0</span>,<span class="fl">0</span>])</span>
<span id="cb96-5"><a href="#cb96-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">plot!</span>(p, [<span class="fl">0</span>,<span class="fl">0</span>], [<span class="fl">0</span>, b<span class="op">^</span><span class="fl">2</span>])</span>
<span id="cb96-6"><a href="#cb96-6" aria-hidden="true" tabindex="-1"></a> a <span class="op">=</span> <span class="fl">1</span></span>
<span id="cb96-7"><a href="#cb96-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">scatter!</span>(p, [a],[a<span class="op">^</span><span class="fl">2</span>])</span>
<span id="cb96-8"><a href="#cb96-8" aria-hidden="true" tabindex="-1"></a> m <span class="op">=</span> <span class="fl">2</span>a</span>
<span id="cb96-9"><a href="#cb96-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">plot!</span>(p, x <span class="op">-&gt;</span> a<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> <span class="fu">m*</span>(x<span class="op">-</span>a), <span class="fl">1</span><span class="op">/</span><span class="fl">2</span>, b)</span>
<span id="cb96-10"><a href="#cb96-10" aria-hidden="true" tabindex="-1"></a> mₚ <span class="op">=</span> <span class="op">-</span><span class="fl">1</span><span class="op">/</span>m</span>
<span id="cb96-11"><a href="#cb96-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">plot!</span>(p, x <span class="op">-&gt;</span> a<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> <span class="fu">mₚ*</span>(x<span class="op">-</span>a))</span>
<span id="cb96-12"><a href="#cb96-12" aria-hidden="true" tabindex="-1"></a> <span class="fu">scatter!</span>(p, [<span class="op">-</span><span class="fl">3</span><span class="op">/</span><span class="fl">2</span>], [(<span class="fl">3</span><span class="op">/</span><span class="fl">2</span>)<span class="op">^</span><span class="fl">2</span>])</span>
<span id="cb96-13"><a href="#cb96-13" aria-hidden="true" tabindex="-1"></a> <span class="fu">annotate!</span>(p, [(<span class="fl">1</span><span class="op">+</span><span class="fl">1</span><span class="op">/</span><span class="fl">4</span>, <span class="fl">1</span><span class="op">+</span><span class="fl">1</span><span class="op">/</span><span class="fl">8</span>, <span class="st">"P"</span>), (<span class="op">-</span><span class="fl">3</span><span class="op">/</span><span class="fl">2</span><span class="op">-</span><span class="fl">1</span><span class="op">/</span><span class="fl">4</span>, (<span class="op">-</span><span class="fl">3</span><span class="op">/</span><span class="fl">2</span>)<span class="op">^</span><span class="fl">2</span><span class="op">-</span><span class="fl">1</span><span class="op">/</span><span class="fl">4</span>, <span class="st">"Q"</span>)])</span>
<span id="cb96-14"><a href="#cb96-14" aria-hidden="true" tabindex="-1"></a>p</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="100">
<p><img src="optimization_files/figure-html/cell-106-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>What do these commands do?</p>
<div class="cell" data-hold="true" data-execution_count="106">
<div class="sourceCode cell-code" id="cb97"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb97-1"><a href="#cb97-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> x<span class="op">::</span><span class="dt">real</span>, a<span class="op">::</span><span class="dt">real</span></span>
<span id="cb97-2"><a href="#cb97-2" aria-hidden="true" tabindex="-1"></a>mₚ <span class="op">=</span> <span class="op">-</span> <span class="fl">1</span> <span class="op">/</span> <span class="fu">diff</span>(x<span class="op">^</span><span class="fl">2</span>, x)(a)</span>
<span id="cb97-3"><a href="#cb97-3" aria-hidden="true" tabindex="-1"></a><span class="fu">solve</span>(x<span class="op">^</span><span class="fl">2</span> <span class="op">-</span> (a<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> <span class="fu">mₚ*</span>(x<span class="op">-</span>a)) <span class="op">~</span> <span class="fl">0</span>, 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="101">
<pre><code>2-element Vector{Sym}:
a
-a - 1/(2*a)</code></pre>
</div>
</div>
<div class="cell" data-hold="true" data-execution_count="107">
<div class="cell-output cell-output-display" data-execution_count="102">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="2209974711139371570" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_2209974711139371570">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_2209974711139371570_1">
<input class="form-check-input" type="radio" name="radio_2209974711139371570" id="radio_2209974711139371570_1" value="1">
<span class="label-body px-1">
It finds the tangent line
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2209974711139371570_2">
<input class="form-check-input" type="radio" name="radio_2209974711139371570" id="radio_2209974711139371570_2" value="2">
<span class="label-body px-1">
It finds the point \(P\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2209974711139371570_3">
<input class="form-check-input" type="radio" name="radio_2209974711139371570" id="radio_2209974711139371570_3" value="3">
<span class="label-body px-1">
It finds the \(x\) value of the intersection points of the normal line and the parabola
</span>
</label>
</div>
</div>
</div>
<div id="2209974711139371570_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_2209974711139371570"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('2209974711139371570_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_2209974711139371570")
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_2209974711139371570")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Numerically, find the value of <span class="math inline">\(a\)</span> that minimizes the <span class="math inline">\(y\)</span> coordinate of <span class="math inline">\(Q\)</span>.</p>
<div class="cell" data-hold="true" data-execution_count="108">
<div class="cell-output cell-output-display" data-execution_count="103">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="7771735743217274760" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_7771735743217274760">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="7771735743217274760" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="7771735743217274760_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("7771735743217274760").addEventListener("change", function() {
var correct = (Math.abs(this.value - 0.7071067811865476) <= 0.001);
var msgBox = document.getElementById('7771735743217274760_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_7771735743217274760")
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_7771735743217274760")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>Numerically find the value of <span class="math inline">\(a\)</span> that minimizes the length of the line seqment <span class="math inline">\(PQ\)</span>.</p>
<pre class="{juila}"><code>#| hold: true
#| echo: false
x(a) = -a - 1/(2a)
d(a) = (a-x(a))^2 + (a^2 - x(a)^2)^2
a = find_zero(d', 1)
numericq(a)</code></pre>
</section>
</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/mean_value_theorem.html" class="pagination-link">
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">25</span>&nbsp; <span class="chapter-title">The mean value theorem for differentiable functions.</span></span>
</a>
</div>
<div class="nav-page nav-page-next">
<a href="../derivatives/first_second_derivatives.html" class="pagination-link">
<span class="nav-page-text"><span class="chapter-number">27</span>&nbsp; <span class="chapter-title">The first and second derivatives</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>