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

2387 lines
154 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

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

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.0.32">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>Calculus with Julia - 33&nbsp; Implicit Differentiation</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/related_rates.html" rel="next">
<link href="../derivatives/lhospitals_rule.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">33</span>&nbsp; <span class="chapter-title">Implicit Differentiation</span></h1>
<button type="button" class="quarto-btn-toggle btn" aria-label="Show secondary navigation">
<i class="bi bi-chevron-right"></i>
</button>
</div>
</nav>
</header>
<!-- content -->
<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar">
<!-- sidebar -->
<nav id="quarto-sidebar" class="sidebar collapse sidebar-navigation floating overflow-auto">
<div class="mt-2 flex-shrink-0 align-items-center">
<div class="sidebar-search">
<div id="quarto-search" class="" title="Search"></div>
</div>
</div>
<div class="sidebar-menu-container">
<ul class="list-unstyled mt-1">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../index.html" class="sidebar-item-text sidebar-link">Preface</a>
</div>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="false">Precalculus Concepts</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/calculator.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">From calculator to computer</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/variables.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Variables</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/numbers_types.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Number systems</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/logical_expressions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Inequalities, Logical expressions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/vectors.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Vectors</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/ranges.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">6</span>&nbsp; <span class="chapter-title">Ranges and Sets</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">7</span>&nbsp; <span class="chapter-title">Functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">The Graph of a Function</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/transformations.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Function manipulations</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/inversefunctions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">The Inverse of a Function</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/polynomial.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Polynomials</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/polynomial_roots.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">12</span>&nbsp; <span class="chapter-title">Roots of a polynomial</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/polynomials_package.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">13</span>&nbsp; <span class="chapter-title">The Polynomials package</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/rational_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">14</span>&nbsp; <span class="chapter-title">Rational functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/exp_log_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">15</span>&nbsp; <span class="chapter-title">Exponential and logarithmic functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/trig_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">16</span>&nbsp; <span class="chapter-title">Trigonometric functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/julia_overview.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">17</span>&nbsp; <span class="chapter-title">Overview of Julia commands</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" aria-expanded="false">Limits</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-2" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/limits.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">18</span>&nbsp; <span class="chapter-title">Limits</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/limits_extensions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">19</span>&nbsp; <span class="chapter-title">Limits, issues, extensions of the concept</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/continuity.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">20</span>&nbsp; <span class="chapter-title">Continuity</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/intermediate_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">21</span>&nbsp; <span class="chapter-title">Implications of continuity</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="true">Derivatives</a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="true">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-3" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">22</span>&nbsp; <span class="chapter-title">Derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/numeric_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">23</span>&nbsp; <span class="chapter-title">Numeric derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/symbolic_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">24</span>&nbsp; <span class="chapter-title">Symbolic derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/mean_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">25</span>&nbsp; <span class="chapter-title">The mean value theorem for differentiable functions.</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/optimization.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">26</span>&nbsp; <span class="chapter-title">Optimization</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/first_second_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">27</span>&nbsp; <span class="chapter-title">The first and second derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/curve_sketching.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">28</span>&nbsp; <span class="chapter-title">Curve Sketching</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/linearization.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">29</span>&nbsp; <span class="chapter-title">Linearization</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/newtons_method.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">30</span>&nbsp; <span class="chapter-title">Newtons method</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/more_zeros.html" class="sidebar-item-text sidebar-link"><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 active"><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="#graphs-of-equations" id="toc-graphs-of-equations" class="nav-link active" data-scroll-target="#graphs-of-equations"> <span class="header-section-number">33.1</span> Graphs of equations</a></li>
<li><a href="#tangent-lines-implicit-differentiation" id="toc-tangent-lines-implicit-differentiation" class="nav-link" data-scroll-target="#tangent-lines-implicit-differentiation"> <span class="header-section-number">33.2</span> Tangent lines, implicit differentiation</a></li>
<li><a href="#using-sympy-for-computation" id="toc-using-sympy-for-computation" class="nav-link" data-scroll-target="#using-sympy-for-computation"> <span class="header-section-number">33.3</span> Using SymPy for computation</a></li>
<li><a href="#higher-order-derivatives" id="toc-higher-order-derivatives" class="nav-link" data-scroll-target="#higher-order-derivatives"> <span class="header-section-number">33.4</span> Higher order derivatives</a></li>
<li><a href="#inverse-functions" id="toc-inverse-functions" class="nav-link" data-scroll-target="#inverse-functions"> <span class="header-section-number">33.5</span> Inverse functions</a></li>
<li><a href="#questions" id="toc-questions" class="nav-link" data-scroll-target="#questions"> <span class="header-section-number">33.6</span> Questions</a></li>
<li><a href="#appendix" id="toc-appendix" class="nav-link" data-scroll-target="#appendix"> <span class="header-section-number">33.7</span> Appendix</a>
<ul class="collapse">
<li><a href="#the-implicitequations-package" id="toc-the-implicitequations-package" class="nav-link" data-scroll-target="#the-implicitequations-package"> <span class="header-section-number">33.7.1</span> The ImplicitEquations package</a></li>
<li><a href="#the-intervalconstraintprogramming-package" id="toc-the-intervalconstraintprogramming-package" class="nav-link" data-scroll-target="#the-intervalconstraintprogramming-package"> <span class="header-section-number">33.7.2</span> The IntervalConstraintProgramming package</a></li>
</ul></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/implicit_differentiation.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">33</span>&nbsp; <span class="chapter-title">Implicit Differentiation</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">ImplicitPlots</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">Roots</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">SymPy</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<hr>
<section id="graphs-of-equations" class="level2" data-number="33.1">
<h2 data-number="33.1" class="anchored" data-anchor-id="graphs-of-equations"><span class="header-section-number">33.1</span> Graphs of equations</h2>
<p>An <strong>equation</strong> in <span class="math inline">\(y\)</span> and <span class="math inline">\(x\)</span> is an algebraic expression involving an equality with two (or more) variables. An example might be <span class="math inline">\(x^2 + y^2 = 1\)</span>.</p>
<p>The <strong>solutions</strong> to an equation in the variables <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span> are all points <span class="math inline">\((x,y)\)</span> which satisfy the equation.</p>
<p>The <strong>graph</strong> of an equation is just the set of solutions to the equation represented in the Cartesian plane.</p>
<p>With this definition, the graph of a function <span class="math inline">\(f(x)\)</span> is just the graph of the equation <span class="math inline">\(y = f(x)\)</span>. In general, graphing an equation is more complicated than graphing a function. For a function, we know for a given value of <span class="math inline">\(x\)</span> what the corresponding value of <span class="math inline">\(f(x)\)</span> is through evaluation of the function. For equations, we may have <span class="math inline">\(0\)</span>, <span class="math inline">\(1\)</span> or more <span class="math inline">\(y\)</span> values for a given <span class="math inline">\(x\)</span> and even more problematic is we may have no rule to find these values.</p>
<p>There are a few options for plotting equations in <code>Julia</code>. We will use <code>ImplicitPlots</code> in this section, but note both <code>ImplicitEquations</code> and <code>IntervalConstraintProgramming</code> offer alternatives that are a bit more flexible.</p>
<p>To plot an implicit equation using <code>ImplicitPlots</code> requires expressing the relationship in terms of a function, and then plotting the equation <code>f(x,y) = 0</code>. In practice this simply requires all the terms be moved to one side of an equals sign.</p>
<p>To plot the circle of radius <span class="math inline">\(2\)</span>, or the equations <span class="math inline">\(x^2 + y^2 = 2^2\)</span> we would move all terms to one side <span class="math inline">\(x^2 + y^2 - 2^2 = 0\)</span> and then express the left hand side through a function:</p>
<div class="cell" data-execution_count="4">
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<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="5">
<pre><code>f (generic function with 1 method)</code></pre>
</div>
</div>
<p>This function is then is passed to the <code>implicit_plot</code> function, which works with <code>Plots</code> to render the graphic:</p>
<div class="cell" data-execution_count="5">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="fu">implicit_plot</span>(f)</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="implicit_differentiation_files/figure-html/cell-6-output-1.svg" class="img-fluid"></p>
</div>
</div>
<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>The <code>f</code> is a function of <em>two</em> variables, used here to express one side of an equation. <code>Julia</code> makes this easy to do - just make sure two variables are in the signature of <code>f</code> when it is defined. Using functions like this, we can express our equation in the form <span class="math inline">\(f(x,y) = c\)</span> or, more generally, as <span class="math inline">\(f(x,y) = g(x,y)\)</span>. The latter of which can be expressed as <span class="math inline">\(h(x,y) = f(x,y) - g(x,y) = 0\)</span>. That is, only the form <span class="math inline">\(f(x,y)=0\)</span> is needed to represent an equation.</p>
</div>
</div>
<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>There are two different styles in <code>Julia</code> to add simple plot recipes. <code>ImplicitPlots</code> adds a new plotting function (<code>implicit_plot</code>); alternatively many packages add a new recipe for the generic <code>plot</code> method using new types. (For example, <code>SymPy</code> has a plot recipe for symbolic types.</p>
</div>
</div>
<p>Of course, more complicated equations are possible and the steps are similar - only the function definition is more involved. For example, the <a href="http://www-groups.dcs.st-and.ac.uk/~history/Curves/Devils.html">Devils curve</a> has the form</p>
<p><span class="math display">\[
y^4 - x^4 + ay^2 + bx^2 = 0
\]</span></p>
<p>Here we draw the curve for a particular choice of <span class="math inline">\(a\)</span> and <span class="math inline">\(b\)</span>. For illustration purposes, a narrower viewing window is specified below using <code>xlims</code> and <code>ylims</code>:</p>
<div class="cell" data-hold="true" data-execution_count="6">
<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>a,b <span class="op">=</span> <span class="op">-</span><span class="fl">1</span>,<span class="fl">2</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> y<span class="op">^</span><span class="fl">4</span> <span class="op">-</span> x<span class="op">^</span><span class="fl">4</span> <span class="op">+</span> a<span class="op">*</span>y<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> b<span class="op">*</span>x<span class="op">^</span><span class="fl">2</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a><span class="fu">implicit_plot</span>(f; xlims<span class="op">=</span>(<span class="op">-</span><span class="fl">3</span>,<span class="fl">3</span>), ylims<span class="op">=</span>(<span class="op">-</span><span class="fl">3</span>,<span class="fl">3</span>), legend<span class="op">=</span><span class="cn">false</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="7">
<p><img src="implicit_differentiation_files/figure-html/cell-7-output-1.svg" class="img-fluid"></p>
</div>
</div>
</section>
<section id="tangent-lines-implicit-differentiation" class="level2" data-number="33.2">
<h2 data-number="33.2" class="anchored" data-anchor-id="tangent-lines-implicit-differentiation"><span class="header-section-number">33.2</span> Tangent lines, implicit differentiation</h2>
<p>The graph <span class="math inline">\(x^2 + y^2 = 1\)</span> has well-defined tangent lines at all points except <span class="math inline">\((-1,0)\)</span> and <span class="math inline">\((0, 1)\)</span> and even at these two points, we could call the vertical lines <span class="math inline">\(x=-1\)</span> and <span class="math inline">\(x=1\)</span> tangent lines. However, to recover the slope of these tangent lines would need us to express <span class="math inline">\(y\)</span> as a function of <span class="math inline">\(x\)</span> and then differentiate that function. Of course, in this example, we would need two functions: <span class="math inline">\(f(x) = \sqrt{1-x^2}\)</span> and <span class="math inline">\(g(x) = - \sqrt{1-x^2}\)</span> to do this completely.</p>
<p>In general though, we may not be able to solve for <span class="math inline">\(y\)</span> in terms of <span class="math inline">\(x\)</span>. What then?</p>
<p>The idea is to <em>assume</em> that <span class="math inline">\(y\)</span> is representable by some function of <span class="math inline">\(x\)</span>. This makes sense, moving on the curve from <span class="math inline">\((x,y)\)</span> to some nearby point, means changing <span class="math inline">\(x\)</span> will cause some change in <span class="math inline">\(y\)</span>. This assumption is only made <em>locally</em> - basically meaning a complicated graph is reduced to just a small, well-behaved, section of its graph.</p>
<p>With this assumption, asking what <span class="math inline">\(dy/dx\)</span> is has an obvious meaning - what is the slope of the tangent line to the graph at <span class="math inline">\((x,y)\)</span>. (The assumption eliminates the question of what a tangent line would mean when a graph self intersects.)</p>
<p>The method of implicit differentiation allows this question to be investigated. It begins by differentiating both sides of the equation assuming <span class="math inline">\(y\)</span> is a function of <span class="math inline">\(x\)</span> to derive a new equation involving <span class="math inline">\(dy/dx\)</span>.</p>
<p>For example, starting with <span class="math inline">\(x^2 + y^2 = 1\)</span>, differentiating both sides in <span class="math inline">\(x\)</span> gives:</p>
<p><span class="math display">\[
2x + 2y\cdot \frac{dy}{dx} = 0.
\]</span></p>
<p>The chain rule was used to find <span class="math inline">\((d/dx)(y^2) = [y(x)^2]' = 2y \cdot dy/dx\)</span>. From this we can solve for <span class="math inline">\(dy/dx\)</span> (the resulting equations are linear in <span class="math inline">\(dy/dx\)</span>, so can always be solved explicitly):</p>
<p><span class="math display">\[
\frac{dy}{dx} = -\frac{x}{y}.
\]</span></p>
<p>This says the slope of the tangent line depends on the point <span class="math inline">\((x,y)\)</span> through the formula <span class="math inline">\(-x/y\)</span>.</p>
<p>As a check, we compare to what we would have found had we solved for <span class="math inline">\(y= \sqrt{1 - x^2}\)</span> (for <span class="math inline">\((x,y)\)</span> with <span class="math inline">\(y \geq 0\)</span>). We would have found: <span class="math inline">\(dy/dx = 1/2 \cdot 1/\sqrt{1 - x^2} \cdot (-2x)\)</span>. Which can be simplified to <span class="math inline">\(-x/y\)</span>. This should show that the method above - assuming <span class="math inline">\(y\)</span> is a function of <span class="math inline">\(x\)</span> and differentiating - is not only more general, but can even be easier.</p>
<p>The name - <em>implicit differentiation</em> - comes from the assumption that <span class="math inline">\(y\)</span> is implicitly defined in terms of <span class="math inline">\(x\)</span>. According to the <a href="http://en.wikipedia.org/wiki/Implicit_function_theorem">Implicit Function Theorem</a> the above method will work provided the curve has sufficient smoothness near the point <span class="math inline">\((x,y)\)</span>.</p>
<section id="examples" class="level5">
<h5 class="anchored" data-anchor-id="examples">Examples</h5>
<p>Consider the <a href="http://www-history.mcs.st-and.ac.uk/Curves/Serpentine.html">serpentine</a> equation</p>
<p><span class="math display">\[
x^2y + a\cdot b \cdot y - a^2 \cdot x = 0, \quad a\cdot b &gt; 0.
\]</span></p>
<p>For <span class="math inline">\(a = 2, b=1\)</span> we have the graph:</p>
<div class="cell" data-hold="true" data-execution_count="7">
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>a, b <span class="op">=</span> <span class="fl">2</span>, <span class="fl">1</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> x<span class="op">^</span><span class="fl">2</span><span class="op">*</span>y <span class="op">+</span> a <span class="op">*</span> b <span class="op">*</span> y <span class="op">-</span> a<span class="op">^</span><span class="fl">2</span> <span class="op">*</span> x</span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a><span class="fu">implicit_plot</span>(f)</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">
<p><img src="implicit_differentiation_files/figure-html/cell-8-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>We can see that at each point in the viewing window the tangent line exists due to the smoothness of the curve. Moreover, at a point <span class="math inline">\((x,y)\)</span> the tangent will have slope <span class="math inline">\(dy/dx\)</span> satisfying:</p>
<p><span class="math display">\[
2xy + x^2 \frac{dy}{dx} + a\cdot b \frac{dy}{dx} - a^2 = 0.
\]</span></p>
<p>Solving, yields:</p>
<p><span class="math display">\[
\frac{dy}{dx} = \frac{a^2 - 2xy}{ab + x^2}.
\]</span></p>
<p>In particular, the point <span class="math inline">\((0,0)\)</span> is always on this graph, and the tangent line will have positive slope <span class="math inline">\(a^2/(ab) = a/b\)</span>.</p>
<hr>
<p>The <a href="http://www-history.mcs.st-and.ac.uk/Curves/Eight.html">eight</a> curve has representation</p>
<p><span class="math display">\[
x^4 = a^2(x^2-y^2), \quad a \neq 0.
\]</span></p>
<p>A graph for <span class="math inline">\(a=3\)</span> shows why it has the name it does:</p>
<div class="cell" data-hold="true" 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>a <span class="op">=</span> <span class="fl">3</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> x<span class="op">^</span><span class="fl">4</span> <span class="op">-</span> a<span class="op">^</span><span class="fl">2</span><span class="fu">*</span>(x<span class="op">^</span><span class="fl">2</span> <span class="op">-</span> y<span class="op">^</span><span class="fl">2</span>)</span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a><span class="fu">implicit_plot</span>(f)</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">
<p><img src="implicit_differentiation_files/figure-html/cell-9-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The tangent line at <span class="math inline">\((x,y)\)</span> will have slope, <span class="math inline">\(dy/dx\)</span> satisfying:</p>
<p><span class="math display">\[
4x^3 = a^2 \cdot (2x - 2y \frac{dy}{dx}).
\]</span></p>
<p>Solving gives:</p>
<p><span class="math display">\[
\frac{dy}{dx} = -\frac{4x^3 - a^2 \cdot 2x}{a^2 \cdot 2y}.
\]</span></p>
<p>The point <span class="math inline">\((3,0)\)</span> can be seen to be a solution to the equation and should have a vertical tangent line. This also is reflected in the formula, as the denominator is <span class="math inline">\(a^2\cdot 2 y\)</span>, which is <span class="math inline">\(0\)</span> at this point, whereas the numerator is not.</p>
</section>
<section id="example" class="level5">
<h5 class="anchored" data-anchor-id="example">Example</h5>
<p>The quotient rule can be hard to remember, unlike the product rule. No reason to despair, the product rule plus implicit differentiation can be used to recover the quotient rule. Suppose <span class="math inline">\(y=f(x)/g(x)\)</span>, then we could also write <span class="math inline">\(y g(x) = f(x)\)</span>. Differentiating implicitly gives:</p>
<p><span class="math display">\[
\frac{dy}{dx} g(x) + y g'(x) = f'(x).
\]</span></p>
<p>Solving for <span class="math inline">\(dy/dx\)</span> gives:</p>
<p><span class="math display">\[
\frac{dy}{dx} = \frac{f'(x) - y g'(x)}{g(x)}.
\]</span></p>
<p>Not quite what we expect, perhaps, but substituting in <span class="math inline">\(f(x)/g(x)\)</span> for <span class="math inline">\(y\)</span> gives us the usual formula:</p>
<p><span class="math display">\[
\frac{dy}{dx} = \frac{f'(x) - \frac{f(x)}{g(x)} g'(x)}{g(x)} = \frac{f'(x) g(x) - f(x) g'(x)}{g(x)^2}.
\]</span></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>In this example we mix notations using <span class="math inline">\(g'(x)\)</span> to represent a derivative of <span class="math inline">\(g\)</span> with respect to <span class="math inline">\(x\)</span> and <span class="math inline">\(dy/dx\)</span> to represent the derivative of <span class="math inline">\(y\)</span> with respect to <span class="math inline">\(x\)</span>. This is done to emphasize the value that we are solving for. It is just a convention though, we could just as well have used the “prime” notation for each.</p>
</div>
</div>
</section>
<section id="example-graphing-a-tangent-line" class="level5">
<h5 class="anchored" data-anchor-id="example-graphing-a-tangent-line">Example: Graphing a tangent line</h5>
<p>Lets see how to add a graph of a tangent line to the graph of an equation. Tangent lines are tangent at a point, so we need a point to discuss.</p>
<p>Returning to the equation for a circle, <span class="math inline">\(x^2 + y^2 = 1\)</span>, lets look at <span class="math inline">\((\sqrt{2}/2, - \sqrt{2}/2)\)</span>. The derivative is <span class="math inline">\(-y/x\)</span>, so the slope at this point is <span class="math inline">\(1\)</span>. The line itself has equation <span class="math inline">\(y = b + m \cdot (x-a)\)</span>. The following represents this in <code>Julia</code>:</p>
<div class="cell" data-hold="true" data-execution_count="9">
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">F</span>(x,y) <span class="op">=</span> x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">2</span> <span class="op">-</span> <span class="fl">1</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>a,b <span class="op">=</span> <span class="fu">sqrt</span>(<span class="fl">2</span>)<span class="op">/</span><span class="fl">2</span>, <span class="fu">-sqrt</span>(<span class="fl">2</span>)<span class="op">/</span><span class="fl">2</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a>m <span class="op">=</span> <span class="op">-</span>a<span class="op">/</span>b</span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a><span class="fu">tl</span>(x) <span class="op">=</span> b <span class="op">+</span> m <span class="op">*</span> (x<span class="op">-</span>a)</span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a><span class="fu">implicit_plot</span>(F, xlims<span class="op">=</span>(<span class="op">-</span><span class="fl">2</span>, <span class="fl">2</span>), ylims<span class="op">=</span>(<span class="op">-</span><span class="fl">2</span>, <span class="fl">2</span>), aspect_ratio<span class="op">=:</span>equal)</span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(tl)</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">
<p><img src="implicit_differentiation_files/figure-html/cell-10-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>We added <em>both</em> the implicit plot of <span class="math inline">\(F\)</span> and the tangent line to the graph at the given point.</p>
</section>
<section id="example-1" class="level5">
<h5 class="anchored" data-anchor-id="example-1">Example</h5>
<p>When we assume <span class="math inline">\(y\)</span> is a function of <span class="math inline">\(x\)</span>, it may not be feasible to actually find the function algebraically. However, in many cases one can be found numerically. Suppose <span class="math inline">\(G(x,y) = c\)</span> describes the equation. Then for a fixed <span class="math inline">\(x\)</span>, <span class="math inline">\(y(x)\)</span> solves <span class="math inline">\(G(x,y(x))) - c = 0\)</span>, so <span class="math inline">\(y(x)\)</span> is a zero of a known function. As long as we can piece together which <span class="math inline">\(y\)</span> goes with which, we can find the function.</p>
<p>For example, the <a href="http://www-history.mcs.st-and.ac.uk/Curves/Foliumd.html">folium</a> of Descartes has the equation</p>
<p><span class="math display">\[
x^3 + y^3 = 3axy.
\]</span></p>
<p>Setting <span class="math inline">\(a=1\)</span> we have the graph:</p>
<div class="cell" data-execution_count="10">
<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="op">=</span> <span class="fl">1</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a><span class="fu">G</span>(x,y) <span class="op">=</span> x<span class="op">^</span><span class="fl">3</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">3</span> <span class="op">-</span> <span class="fl">3</span><span class="op">*</span>𝒂<span class="op">*</span>x<span class="op">*</span>y</span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a><span class="fu">implicit_plot</span>(G)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="11">
<p><img src="implicit_differentiation_files/figure-html/cell-11-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>We can solve for the lower curve, <span class="math inline">\(y\)</span>, as a function of <span class="math inline">\(x\)</span>, as follows:</p>
<div class="cell" data-execution_count="11">
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="fu">y1</span>(x) <span class="op">=</span> <span class="fu">minimum</span>(<span class="fu">find_zeros</span>(<span class="fu">y-&gt;G</span>(x,y), <span class="op">-</span><span class="fl">10</span>, <span class="fl">10</span>)) <span class="co"># find_zeros from `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="12">
<pre><code>y1 (generic function with 1 method)</code></pre>
</div>
</div>
<p>This gives the lower part of the curve, which we can plot with:</p>
<div class="cell" data-execution_count="12">
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(y1, <span class="op">-</span><span class="fl">5</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="13">
<p><img src="implicit_differentiation_files/figure-html/cell-13-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Though, in this case, the cubic equation would admit a closed-form solution, the approach illustrated applies more generally.</p>
</section>
</section>
<section id="using-sympy-for-computation" class="level2" data-number="33.3">
<h2 data-number="33.3" class="anchored" data-anchor-id="using-sympy-for-computation"><span class="header-section-number">33.3</span> Using SymPy for computation</h2>
<p><code>SymPy</code> can be used to perform implicit differentiation. The three steps are similar: we assume <span class="math inline">\(y\)</span> is a function of <span class="math inline">\(x\)</span>, <em>locally</em>; differentiate both sides; solve the result for <span class="math inline">\(dy/dx\)</span>.</p>
<p>Lets do so for the <a href="http://www-history.mcs.st-and.ac.uk/Curves/Trident.html">Trident of Newton</a>, which is represented in Cartesian form as follows:</p>
<p><span class="math display">\[
xy = cx^3 + dx^2 + ex + h.
\]</span></p>
<p>To approach this task in <code>SymPy</code>, we begin by defining our symbolic expression. For now, we keep the parameters as symbolic values:</p>
<div class="cell" data-execution_count="13">
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> a b c d x y</span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a>ex <span class="op">=</span> x<span class="op">*</span>y <span class="op">-</span> (a<span class="op">*</span>c<span class="op">^</span><span class="fl">3</span> <span class="op">+</span> b<span class="op">*</span>x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> c<span class="op">*</span>x <span class="op">+</span> d)</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">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
- a c^{3} - b x^{2} - c x - d + x y
\]
</span>
</div>
</div>
<p>To express that <code>y</code> is a locally a function of <code>x</code>, we use a “symbolic function” object:</p>
<div class="cell" data-execution_count="14">
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> <span class="fu">u</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">
<pre><code>(u,)</code></pre>
</div>
</div>
<p>The object <code>u</code> is the symbolic function, and <code>u(x)</code> a symbolic expression involving a symbolic function. This is what we will use to refer to <code>y</code>.</p>
<p>Assume <span class="math inline">\(y\)</span> is a function of <span class="math inline">\(x\)</span>, called <code>u(x)</code>, this substitution is just a renaming:</p>
<div class="cell" data-execution_count="15">
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a>ex1 <span class="op">=</span> <span class="fu">ex</span>(y <span class="op">=&gt;</span> <span class="fu">u</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="16">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
- a c^{3} - b x^{2} - c x - d + x u{\left(x \right)}
\]
</span>
</div>
</div>
<p>At this point, we differentiate in <code>x</code>:</p>
<div class="cell" data-execution_count="16">
<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>ex2 <span class="op">=</span> <span class="fu">diff</span>(ex1, 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="17">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
- 2 b x - c + x \frac{d}{d x} u{\left(x \right)} + u{\left(x \right)}
\]
</span>
</div>
</div>
<p>The next step is solve for <span class="math inline">\(dy/dx\)</span> - the lone answer to the linear equation - which is done as follows:</p>
<div class="cell" data-execution_count="17">
<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>dydx <span class="op">=</span> <span class="fu">diff</span>(<span class="fu">u</span>(x), x)</span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a>ex3 <span class="op">=</span> <span class="fu">solve</span>(ex2, dydx)[<span class="fl">1</span>] <span class="co"># pull out lone answer with [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="18">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
\frac{2 b x + c - u{\left(x \right)}}{x}
\]
</span>
</div>
</div>
<p>As this represents an answer in terms of <code>u(x)</code>, we replace that term with the original variable:</p>
<div class="cell" data-execution_count="18">
<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>dydx₁ <span class="op">=</span> <span class="fu">ex3</span>(<span class="fu">u</span>(x) <span class="op">=&gt;</span> y)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="19">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
\frac{2 b x + c - y}{x}
\]
</span>
</div>
</div>
<p>If <code>x</code> and <code>y</code> are the variable names, this function will combine the steps above:</p>
<div class="cell" data-execution_count="19">
<div class="sourceCode cell-code" id="cb20"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span> <span class="fu">dy_dx</span>(eqn, x, y)</span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a> <span class="pp">@syms</span> <span class="fu">u</span>()</span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a> eqn1 <span class="op">=</span> <span class="fu">eqn</span>(y <span class="op">=&gt;</span> <span class="fu">u</span>(x))</span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a> eqn2 <span class="op">=</span> <span class="fu">solve</span>(<span class="fu">diff</span>(eqn1, x), <span class="fu">diff</span>(<span class="fu">u</span>(x), x))[<span class="fl">1</span>]</span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">eqn2</span>(<span class="fu">u</span>(x) <span class="op">=&gt;</span> y)</span>
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="20">
<pre><code>dy_dx (generic function with 1 method)</code></pre>
</div>
</div>
<p>Let <span class="math inline">\(a = b = c = d = 1\)</span>, then <span class="math inline">\((1,4)\)</span> is a point on the curve. We can draw a tangent line to this point with these commands:</p>
<div class="cell" data-execution_count="20">
<div class="sourceCode cell-code" id="cb22"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a>H <span class="op">=</span> <span class="fu">ex</span>(a<span class="op">=&gt;</span><span class="fl">1</span>, b<span class="op">=&gt;</span><span class="fl">1</span>, c<span class="op">=&gt;</span><span class="fl">1</span>, d<span class="op">=&gt;</span><span class="fl">1</span>)</span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a>x0, y0 <span class="op">=</span> <span class="fl">1</span>, <span class="fl">4</span></span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a>𝒎 <span class="op">=</span> <span class="fu">dydx₁</span>(x<span class="op">=&gt;</span><span class="fl">1</span>, y<span class="op">=&gt;</span><span class="fl">4</span>, a<span class="op">=&gt;</span><span class="fl">1</span>, b<span class="op">=&gt;</span><span class="fl">1</span>, c<span class="op">=&gt;</span><span class="fl">1</span>, d<span class="op">=&gt;</span><span class="fl">1</span>)</span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a><span class="fu">implicit_plot</span>(<span class="fu">lambdify</span>(H); xlims<span class="op">=</span>(<span class="op">-</span><span class="fl">5</span>,<span class="fl">5</span>), ylims<span class="op">=</span>(<span class="op">-</span><span class="fl">5</span>,<span class="fl">5</span>), legend<span class="op">=</span><span class="cn">false</span>)</span>
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(y0 <span class="op">+</span> 𝒎 <span class="op">*</span> (x<span class="op">-</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="21">
<p><img src="implicit_differentiation_files/figure-html/cell-21-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Basically this includes all the same steps as if done “by hand.” Some effort could have been saved in plotting, had values for the parameters been substituted initially, but not doing so shows their dependence in the derivative.</p>
<div class="callout-warning 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">
Warning
</div>
</div>
<div class="callout-body-container callout-body">
<p>The use of <code>lambdify(H)</code> is needed to turn the symbolic expression, <code>H</code>, into a function.</p>
</div>
</div>
<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>While <code>SymPy</code> itself has the <code>plot_implicit</code> function for plotting implicit equations, this works only with <code>PyPlot</code>, not <code>Plots</code>, so we use the <code>ImplicitPlots</code> package in these examples.</p>
</div>
</div>
</section>
<section id="higher-order-derivatives" class="level2" data-number="33.4">
<h2 data-number="33.4" class="anchored" data-anchor-id="higher-order-derivatives"><span class="header-section-number">33.4</span> Higher order derivatives</h2>
<p>Implicit differentiation can be used to find <span class="math inline">\(d^2y/dx^2\)</span> or other higher-order derivatives. At each stage, the same technique is applied. The only “trick” is that some simplifications can be made.</p>
<p>For example, consider <span class="math inline">\(x^3 - y^3=3\)</span>. To find <span class="math inline">\(d^2y/dx^2\)</span>, we first find <span class="math inline">\(dy/dx\)</span>:</p>
<p><span class="math display">\[
3x^2 - (3y^2 \frac{dy}{dx}) = 0.
\]</span></p>
<p>We could solve for <span class="math inline">\(dy/dx\)</span> at this point - it always appears as a linear factor - to get:</p>
<p><span class="math display">\[
\frac{dy}{dx} = \frac{3x^2}{3y^2} = \frac{x^2}{y^2}.
\]</span></p>
<p>However, we differentiate the first equation, as we generally try to avoid the quotient rule</p>
<p><span class="math display">\[
6x - (6y \frac{dy}{dx} \cdot \frac{dy}{dx} + 3y^2 \frac{d^2y}{dx^2}) = 0.
\]</span></p>
<p>Again, if must be that <span class="math inline">\(d^2y/dx^2\)</span> appears as a linear factor, so we can solve for it:</p>
<p><span class="math display">\[
\frac{d^2y}{dx^2} = \frac{6x - 6y (\frac{dy}{dx})^2}{3y^2}.
\]</span></p>
<p>One last substitution for <span class="math inline">\(dy/dx\)</span> gives:</p>
<p><span class="math display">\[
\frac{d^2y}{dx^2} = \frac{-6x + 6y (\frac{x^2}{y^2})^2}{3y^2} = -2\frac{x}{y^2} + 2\frac{x^4}{y^5} = 2\frac{x}{y^2}(1 - \frac{x^3}{y^3}) = 2\frac{x}{y^5}(y^3 - x^3) = 2 \frac{x}{y^5}(-3).
\]</span></p>
<p>It isnt so pretty, but thats all it takes.</p>
<p>To visualize, we plot implicitly and notice that:</p>
<ul>
<li>as we change quadrants from the third to the fourth to the first the concavity changes from down to up to down, as the sign of the second derivative changes from negative to positive to negative;</li>
<li>and that at these inflection points, the “tangent” line is vertical when <span class="math inline">\(y=0\)</span> and flat when <span class="math inline">\(x=0\)</span>.</li>
</ul>
<div class="cell" data-execution_count="21">
<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">K</span>(x,y) <span class="op">=</span> x<span class="op">^</span><span class="fl">3</span> <span class="op">-</span> y<span class="op">^</span><span class="fl">3</span> <span class="op">-</span> <span class="fl">3</span></span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a><span class="fu">implicit_plot</span>(K, xlims<span class="op">=</span>(<span class="op">-</span><span class="fl">3</span>, <span class="fl">3</span>), ylims<span class="op">=</span>(<span class="op">-</span><span class="fl">3</span>, <span class="fl">3</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="22">
<p><img src="implicit_differentiation_files/figure-html/cell-22-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The same problem can be done symbolically. The steps are similar, though the last step (replacing <span class="math inline">\(x^3 - y^3\)</span> with <span class="math inline">\(3\)</span>) isnt done without explicitly asking.</p>
<div class="cell" data-hold="true" data-execution_count="22">
<div class="sourceCode cell-code" id="cb24"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> x y <span class="fu">u</span>()</span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a>eqn <span class="op">=</span> <span class="fu">K</span>(x,y) <span class="op">-</span> <span class="fl">3</span></span>
<span id="cb24-4"><a href="#cb24-4" aria-hidden="true" tabindex="-1"></a>eqn1 <span class="op">=</span> <span class="fu">eqn</span>(y <span class="op">=&gt;</span> <span class="fu">u</span>(x))</span>
<span id="cb24-5"><a href="#cb24-5" aria-hidden="true" tabindex="-1"></a>dydx <span class="op">=</span> <span class="fu">solve</span>(<span class="fu">diff</span>(eqn1,x), <span class="fu">diff</span>(<span class="fu">u</span>(x), x))[<span class="fl">1</span>] <span class="co"># 1 solution</span></span>
<span id="cb24-6"><a href="#cb24-6" aria-hidden="true" tabindex="-1"></a>d2ydx2 <span class="op">=</span> <span class="fu">solve</span>(<span class="fu">diff</span>(eqn1, x, <span class="fl">2</span>), <span class="fu">diff</span>(<span class="fu">u</span>(x),x, <span class="fl">2</span>))[<span class="fl">1</span>] <span class="co"># 1 solution</span></span>
<span id="cb24-7"><a href="#cb24-7" aria-hidden="true" tabindex="-1"></a>eqn2 <span class="op">=</span> <span class="fu">d2ydx2</span>(<span class="fu">diff</span>(<span class="fu">u</span>(x), x) <span class="op">=&gt;</span> dydx, <span class="fu">u</span>(x) <span class="op">=&gt;</span> y)</span>
<span id="cb24-8"><a href="#cb24-8" aria-hidden="true" tabindex="-1"></a><span class="fu">simplify</span>(eqn2)</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="23">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
\frac{2 x \left(- x^{3} + y^{3}\right)}{y^{5}}
\]
</span>
</div>
</div>
</section>
<section id="inverse-functions" class="level2" data-number="33.5">
<h2 data-number="33.5" class="anchored" data-anchor-id="inverse-functions"><span class="header-section-number">33.5</span> Inverse functions</h2>
<p>As <a href="../precalc/inversefunctions.html">mentioned</a>, an <a href="http://en.wikipedia.org/wiki/Inverse_function">inverse</a> function for <span class="math inline">\(f(x)\)</span> is a function <span class="math inline">\(g(x)\)</span> satisfying: <span class="math inline">\(y = f(x)\)</span> if and only if <span class="math inline">\(g(y) = x\)</span> for all <span class="math inline">\(x\)</span> in the domain of <span class="math inline">\(f\)</span> and <span class="math inline">\(y\)</span> in the range of <span class="math inline">\(f\)</span>.</p>
<p>In short, both <span class="math inline">\(f \circ g\)</span> and <span class="math inline">\(g \circ f\)</span> are identify functions on their respective domains. As inverses are unique, their notation, <span class="math inline">\(f^{-1}(x)\)</span>, reflects the name of the related function.</p>
<p>The chain rule can be used to give the derivative of an inverse function when applied to <span class="math inline">\(f(f^{-1}(x)) = x\)</span>. Solving gives, <span class="math inline">\([f^{-1}(x)]' = 1 / f'(f^{-1}(x))\)</span>.</p>
<p>This is great - if we can remember the rules. If not, sometimes implicit differentiation can also help.</p>
<p>Consider the inverse function for the tangent, which exists when the domain of the tangent function is restricted to <span class="math inline">\((-\pi/2, \pi/2)\)</span>. The function solves <span class="math inline">\(y = \tan^{-1}(x)\)</span> or <span class="math inline">\(\tan(y) = x\)</span>. Differentiating this yields:</p>
<p><span class="math display">\[
\sec(y)^2 \frac{dy}{dx} = 1.
\]</span></p>
<p>Or <span class="math inline">\(dy/dx = 1/\sec^2(y)\)</span>.</p>
<p>But <span class="math inline">\(\sec(y)^2 = 1 + \tan(y)^2 = 1 + x^2\)</span>, as can be seen by right-triangle trigonometry. This yields the formula <span class="math inline">\(dy/dx = [\tan^{-1}(x)]' = 1 / (1 + x^2)\)</span>.</p>
<section id="example-2" class="level5">
<h5 class="anchored" data-anchor-id="example-2">Example</h5>
<p>For a more complicated example, suppose we have a moving trajectory <span class="math inline">\((x(t), y(t))\)</span>. The angle it makes with the origin satisfies</p>
<p><span class="math display">\[
\tan(\theta(t)) = \frac{y(t)}{x(t)}.
\]</span></p>
<p>Suppose <span class="math inline">\(\theta(t)\)</span> can be defined in terms of the inverse to some function (<span class="math inline">\(\tan^{-1}(x)\)</span>). We can differentiate implicitly to find <span class="math inline">\(\theta'(t)\)</span> in terms of derivatives of <span class="math inline">\(y\)</span> and <span class="math inline">\(x\)</span>:</p>
<p><span class="math display">\[
\sec^2(\theta(t)) \cdot \theta'(t) = \frac{y'(t) x(t) - y(t) x'(t)}{x(t))^2}.
\]</span></p>
<p>But <span class="math inline">\(\sec^2(\theta(t)) = (r(t)/x(t))^2 = (x(t)^2 + y(t)^2) / x(t)^2\)</span>, so moving to the other side the secant term gives an explicit, albeit complicated, expression for the derivative of <span class="math inline">\(\theta\)</span> in terms of the functions <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span>:</p>
<p><span class="math display">\[
\theta'(t) = \frac{x^2}{x^2(t) + y^2(t)} \cdot \frac{y'(t) x(t) - y(t) x'(t)}{x(t))^2} = \frac{y'(t) x(t) - y(t) x'(t)}{x^2(t) + y^2(t)}.
\]</span></p>
<p>This could have been made easier, had we leveraged the result of the previous example.</p>
</section>
<section id="example-from-physics" class="level4">
<h4 class="anchored" data-anchor-id="example-from-physics">Example: from physics</h4>
<p>Many problems are best done with implicit derivatives. A video showing such a problem along with how to do it analytically is <a href="http://ocw.mit.edu/courses/mathematics/18-01sc-single-variable-calculus-fall-2010/unit-2-applications-of-differentiation/part-b-optimization-related-rates-and-newtons-method/session-32-ring-on-a-string/">here</a>.</p>
<p>This video starts with a simple question:</p>
<blockquote class="blockquote">
<p>If you have a rope and heavy ring, where will the ring position itself due to gravity?</p>
</blockquote>
<p>Well, suppose you hold the rope in two places, which we can take to be <span class="math inline">\((0,0)\)</span> and <span class="math inline">\((a,b)\)</span>. Then let <span class="math inline">\((x,y)\)</span> be all the possible positions of the ring that hold the rope taught. Then we have this picture:</p>
<div class="cell" data-hold="true" data-execution_count="23">
<div class="cell-output cell-output-display" data-execution_count="24">
<p><img src="implicit_differentiation_files/figure-html/cell-24-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Since the length of the rope does not change, we must have for any admissible <span class="math inline">\((x,y)\)</span> that:</p>
<p><span class="math display">\[
L = \sqrt{x^2 + y^2} + \sqrt{(a-x)^2 + (b-y)^2},
\]</span></p>
<p>where these terms come from the two hypotenuses in the figure, as computed through Pythagoreans theorem.</p>
<blockquote class="blockquote">
<p>If we assume that the ring will minimize the value of y subject to this constraint, can we solve for y?</p>
</blockquote>
<p>We create a function to represent the equation:</p>
<div class="cell" data-execution_count="24">
<div class="sourceCode cell-code" id="cb25"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="fu">F₀</span>(x, y, a, b) <span class="op">=</span> <span class="fu">sqrt</span>(x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">2</span>) <span class="op">+</span> <span class="fu">sqrt</span>((a<span class="op">-</span>x)<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> (b<span class="op">-</span>y)<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="25">
<pre><code>F₀ (generic function with 1 method)</code></pre>
</div>
</div>
<p>To illustrate, we need specific values of <span class="math inline">\(a\)</span>, <span class="math inline">\(b\)</span>, and <span class="math inline">\(L\)</span>:</p>
<div class="cell" data-execution_count="25">
<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="op">=</span> <span class="fl">3</span>, <span class="fl">3</span>, <span class="fl">10</span> <span class="co"># L &gt; sqrt{a^2 + b^2}</span></span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a><span class="fu">F₀</span>(x, y) <span class="op">=</span> <span class="fu">F₀</span>(x, y, 𝐚, 𝐛)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="26">
<pre><code>F₀ (generic function with 2 methods)</code></pre>
</div>
</div>
<p>Our values <span class="math inline">\((x,y)\)</span> must satisfy <span class="math inline">\(f(x,y) = L\)</span>. Lets graph:</p>
<div class="cell" data-execution_count="26">
<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="fu">implicit_plot</span>((x,y) <span class="op">-&gt;</span> <span class="fu">F₀</span>(x,y) <span class="op">-</span> 𝐋, xlims<span class="op">=</span>(<span class="op">-</span><span class="fl">5</span>, <span class="fl">7</span>), ylims<span class="op">=</span>(<span class="op">-</span><span class="fl">5</span>, <span class="fl">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="27">
<p><img src="implicit_differentiation_files/figure-html/cell-27-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The graph is an ellipse, though slightly tilted.</p>
<p>Okay, now to find the lowest point. This will be when the derivative is <span class="math inline">\(0\)</span>. We solve by assuming <span class="math inline">\(y\)</span> is a function of <span class="math inline">\(x\)</span> called <code>u</code>. We have already defined symbolic variables <code>a</code>, <code>b</code>, <code>x</code>, and <code>y</code>, here we define <code>L</code>:</p>
<div class="cell" data-execution_count="27">
<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="pp">@syms</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="28">
<pre><code>(L,)</code></pre>
</div>
</div>
<p>Then</p>
<div class="cell" data-execution_count="28">
<div class="sourceCode cell-code" id="cb32"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a>eqn <span class="op">=</span> <span class="fu">F₀</span>(x,y,a,b) <span class="op">-</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="29">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
- L + \sqrt{x^{2} + y^{2}} + \sqrt{\left(0.05 - x\right)^{2} + \left(0.25 - y\right)^{2}}
\]
</span>
</div>
</div>
<div class="cell" data-execution_count="29">
<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>eqn_1 <span class="op">=</span> <span class="fu">diff</span>(<span class="fu">eqn</span>(y <span class="op">=&gt;</span> <span class="fu">u</span>(x)), x)</span>
<span id="cb33-2"><a href="#cb33-2" aria-hidden="true" tabindex="-1"></a>eqn_2 <span class="op">=</span> <span class="fu">solve</span>(eqn_1, <span class="fu">diff</span>(<span class="fu">u</span>(x), x))[<span class="fl">1</span>]</span>
<span id="cb33-3"><a href="#cb33-3" aria-hidden="true" tabindex="-1"></a>dydx₂ <span class="op">=</span> <span class="fu">eqn_2</span>(<span class="fu">u</span>(x) <span class="op">=&gt;</span> y)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="30">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
\frac{- 20.0 x \sqrt{x^{2} + y^{2}} - 20.0 x \sqrt{\left(x - 0.05\right)^{2} + \left(y - 0.25\right)^{2}} + \sqrt{x^{2} + y^{2}}}{20.0 y \left(x^{2} + y^{2}\right)^{0.5} + 20.0 y \left(\left(x - 0.05\right)^{2} + \left(y - 0.25\right)^{2}\right)^{0.5} - 5.0 \left(x^{2} + y^{2}\right)^{0.5}}
\]
</span>
</div>
</div>
<p>We are looking for when the tangent line has <span class="math inline">\(0\)</span> slope, or when <code>dydx</code> is <span class="math inline">\(0\)</span>:</p>
<div class="cell" data-execution_count="30">
<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>cps <span class="op">=</span> <span class="fu">solve</span>(dydx₂, 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="31">
<pre><code>2-element Vector{Sym}:
0.2⋅y
0.2*y/(8.0*y - 1.0)</code></pre>
</div>
</div>
<p>There are two answers, as we could guess from the graph, but we want the one for the smallest value of <span class="math inline">\(y\)</span>, which is the second.</p>
<p>The values of <code>dydx</code> depend on any pair <span class="math inline">\((x,y)\)</span>, but our solution must also satisfy the equation. That is for our value of <span class="math inline">\(x\)</span>, we need to find the corresponding <span class="math inline">\(y\)</span>. This should be possible by substituting:</p>
<div class="cell" data-execution_count="31">
<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>eqn1 <span class="op">=</span> <span class="fu">eqn</span>(x <span class="op">=&gt;</span> cps[<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="32">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
- L + \sqrt{y^{2} + \frac{0.000625 y^{2}}{\left(y - 0.125\right)^{2}}} + \sqrt{\left(0.25 - y\right)^{2} + 0.04 \left(- \frac{y}{8.0 y - 1.0} + 0.25\right)^{2}}
\]
</span>
</div>
</div>
<p>We would try to solve <code>eqn1</code> for <code>y</code> with <code>solve(eqn1, y)</code>, but <code>SymPy</code> cant complete this problem. Instead, we will approach this numerically using <code>find_zero</code> from the <code>Roots</code> package. We make the above a function of <code>y</code> alone</p>
<div class="cell" data-execution_count="32">
<div class="sourceCode cell-code" id="cb37"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb37-1"><a href="#cb37-1" aria-hidden="true" tabindex="-1"></a>eqn2 <span class="op">=</span> <span class="fu">eqn1</span>(a<span class="op">=&gt;</span><span class="fl">3</span>, b<span class="op">=&gt;</span><span class="fl">3</span>, L<span class="op">=&gt;</span><span class="fl">10</span>)</span>
<span id="cb37-2"><a href="#cb37-2" aria-hidden="true" tabindex="-1"></a>ystar <span class="op">=</span> <span class="fu">find_zero</span>(eqn2, <span class="op">-</span><span class="fl">3</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="33">
<pre><code>-3.4872035192968935</code></pre>
</div>
</div>
<p>Okay, now we need to put this value back into our expression for the <code>x</code> value and also substitute in for the parameters:</p>
<div class="cell" data-execution_count="33">
<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>xstar <span class="op">=</span> <span class="fu">N</span>(cps[<span class="fl">2</span>](y <span class="op">=&gt;</span> ystar, a <span class="op">=&gt;</span><span class="fl">3</span>, b <span class="op">=&gt;</span> <span class="fl">3</span>, L <span class="op">=&gt;</span> <span class="fl">3</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="34">
<pre><code>0.024134877095571772</code></pre>
</div>
</div>
<p>Our minimum is at <code>(xstar, ystar)</code>, as this graphic shows:</p>
<div class="cell" data-execution_count="34">
<div class="sourceCode cell-code" id="cb41"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb41-1"><a href="#cb41-1" aria-hidden="true" tabindex="-1"></a><span class="fu">tl</span>(x) <span class="op">=</span> ystar <span class="op">+</span> <span class="fl">0</span> <span class="op">*</span> (x<span class="op">-</span> xstar)</span>
<span id="cb41-2"><a href="#cb41-2" aria-hidden="true" tabindex="-1"></a><span class="fu">implicit_plot</span>((x,y) <span class="op">-&gt;</span> <span class="fu">F₀</span>(x,y,<span class="fl">3</span>,<span class="fl">3</span>) <span class="op">-</span> <span class="fl">10</span>, xlims<span class="op">=</span>(<span class="op">-</span><span class="fl">4</span>, <span class="fl">7</span>), ylims<span class="op">=</span>(<span class="op">-</span><span class="fl">10</span>, <span class="fl">10</span>))</span>
<span id="cb41-3"><a href="#cb41-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(tl)</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">
<p><img src="implicit_differentiation_files/figure-html/cell-35-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>If you watch the video linked to above, you will see that the surprising fact here is the resting point is such that the angles formed by the rope are the same. Basically this makes the tension in both parts of the rope equal, so there is a static position (if not static, the ring would move and not end in the final position). We can verify this fact numerically by showing the arctangents of the two triangles are the same up to a sign:</p>
<div class="cell" data-execution_count="35">
<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>a0, b0 <span class="op">=</span> <span class="fl">0</span>,<span class="fl">0</span> <span class="co"># the foci of the ellipse are (0,0) and (3,3)</span></span>
<span id="cb42-2"><a href="#cb42-2" aria-hidden="true" tabindex="-1"></a>a1, b1 <span class="op">=</span> <span class="fl">3</span>, <span class="fl">3</span></span>
<span id="cb42-3"><a href="#cb42-3" aria-hidden="true" tabindex="-1"></a><span class="fu">atan</span>((b0 <span class="op">-</span> ystar)<span class="op">/</span>(a0 <span class="op">-</span> xstar)) <span class="op">+</span> <span class="fu">atan</span>((b1 <span class="op">-</span> ystar)<span class="op">/</span>(a1 <span class="op">-</span> xstar)) <span class="co"># ≈ 0</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="36">
<pre><code>-0.42316792063329345</code></pre>
</div>
</div>
<p>Now, were we lucky and just happened to take <span class="math inline">\(a=3\)</span>, <span class="math inline">\(b = 3\)</span> in such a way to make this work? Well, no. But convince yourself by doing the above for different values of <span class="math inline">\(b\)</span>.</p>
<hr>
<p>In the above, we started with <span class="math inline">\(F(x,y) = L\)</span> and solved symbolically for <span class="math inline">\(y=f(x)\)</span> so that <span class="math inline">\(F(x,f(x)) = L\)</span>. Then we took a derivative of <span class="math inline">\(f(x)\)</span> and set this equal to <span class="math inline">\(0\)</span> to solve for the minimum <span class="math inline">\(y\)</span> values.</p>
<p>Here we try the same problem numerically, using a zero-finding approach to identify <span class="math inline">\(f(x))\)</span>.</p>
<p>Starting with <span class="math inline">\(F(x,y) = \sqrt{x^2 + y^2} + \sqrt{(x-1)^2 + (b-2)^2}\)</span> and <span class="math inline">\(L=3\)</span>, we have:</p>
<div class="cell" data-execution_count="36">
<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">F₁</span>(x,y) <span class="op">=</span> <span class="fu">F₀</span>(x,y, <span class="fl">1</span>, <span class="fl">2</span>) <span class="op">-</span> <span class="fl">3</span> <span class="co"># a,b,L = 1,2,3</span></span>
<span id="cb44-2"><a href="#cb44-2" aria-hidden="true" tabindex="-1"></a><span class="fu">implicit_plot</span>(F₁)</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="37">
<p><img src="implicit_differentiation_files/figure-html/cell-37-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Trying to find the lowest <span class="math inline">\(y\)</span> value we have from the graph it is near <span class="math inline">\(x=0.1\)</span>. We can do better.</p>
<p>First, we could try so solve for the <span class="math inline">\(f\)</span> using <code>find_zero</code>. Here is one way:</p>
<div class="cell" data-execution_count="37">
<div class="sourceCode cell-code" id="cb45"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb45-1"><a href="#cb45-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f₀</span>(x) <span class="op">=</span> <span class="fu">find_zero</span>(y <span class="op">-&gt;</span> <span class="fu">F₁</span>(x, y), <span class="fl">0</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="38">
<pre><code>f₀ (generic function with 1 method)</code></pre>
</div>
</div>
<p>We use <span class="math inline">\(0\)</span> as an initial guess, as the <span class="math inline">\(y\)</span> value is near <span class="math inline">\(0\)</span>. More on this later. We could then just sample many <span class="math inline">\(x\)</span> values between <span class="math inline">\(-0.5\)</span> and <span class="math inline">\(1.5\)</span> and find the one corresponding to the smallest <span class="math inline">\(t\)</span> value:</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><span class="fu">findmin</span>([<span class="fu">f₀</span>(x) for x <span class="op"></span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">0.5</span>, <span class="fl">1.5</span>, length<span class="op">=</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="39">
<pre><code>(-0.4142135621686101, 33)</code></pre>
</div>
</div>
<p>This shows the smallest value is around <span class="math inline">\(-0.414\)</span> and occurs in the <span class="math inline">\(33\)</span>rd position of the sampled <span class="math inline">\(x\)</span> values. Pretty good, but we can do better. We just need to differentiate <span class="math inline">\(f\)</span>, solve for <span class="math inline">\(f'(x) = 0\)</span> and then put that value back into <span class="math inline">\(f\)</span> to find the smallest <span class="math inline">\(y\)</span>.</p>
<p><strong>However</strong> there is one subtle point. Using automatic differentiation, as implemented in <code>ForwardDiff</code>, with <code>find_zero</code> requires the <code>x0</code> initial value to have a certain type. In this case, the same type as the “<code>x</code>” passed into <span class="math inline">\(f(x)\)</span>. So rather than use an initial value of <span class="math inline">\(0\)</span>, we must use an initial value <code>zero(x)</code>! (Otherwise, there will be an error “<code>no method matching Float64(::ForwardDiff.Dual{...</code>”.)</p>
<p>With this slight modification, we have:</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><span class="fu">f₁</span>(x) <span class="op">=</span> <span class="fu">find_zero</span>(y <span class="op">-&gt;</span> <span class="fu">F₁</span>(x, y), <span class="fu">zero</span>(x))</span>
<span id="cb49-2"><a href="#cb49-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(f₁<span class="op">'</span>, <span class="op">-</span><span class="fl">0.5</span>, <span class="fl">1.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="40">
<p><img src="implicit_differentiation_files/figure-html/cell-40-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The zero of <code>f'</code> is a bit to the right of <span class="math inline">\(0\)</span>, say <span class="math inline">\(0.2\)</span>; we use <code>find_zero</code> again to find it:</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>xstar₁ <span class="op">=</span> <span class="fu">find_zero</span>(f₁<span class="op">'</span>, <span class="fl">0.2</span>)</span>
<span id="cb50-2"><a href="#cb50-2" aria-hidden="true" tabindex="-1"></a>xstar₁, <span class="fu">f₁</span>(xstar₁)</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>(0.146446609406726, -0.4142135623730952)</code></pre>
</div>
</div>
<p>It is important to note that the above uses of <code>find_zero</code> required <em>good</em> initial guesses, which we were fortunate enough to identify.</p>
</section>
</section>
<section id="questions" class="level2" data-number="33.6">
<h2 data-number="33.6" class="anchored" data-anchor-id="questions"><span class="header-section-number">33.6</span> Questions</h2>
<section id="question" class="level6">
<h6 class="anchored" data-anchor-id="question">Question</h6>
<p>Is <span class="math inline">\((1,1)\)</span> on the graph of</p>
<p><span class="math display">\[
x^2 - 2xy + y^2 = 1?
\]</span></p>
<div class="cell" data-hold="true" data-execution_count="41">
<div class="cell-output cell-output-display" data-execution_count="42">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="9020955666697264645" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_9020955666697264645">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_9020955666697264645_1">
<input class="form-check-input" type="radio" name="radio_9020955666697264645" id="radio_9020955666697264645_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_9020955666697264645_2">
<input class="form-check-input" type="radio" name="radio_9020955666697264645" id="radio_9020955666697264645_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="9020955666697264645_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_9020955666697264645"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('9020955666697264645_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_9020955666697264645")
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_9020955666697264645")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-1" class="level6">
<h6 class="anchored" data-anchor-id="question-1">Question</h6>
<p>For the equation</p>
<p><span class="math display">\[
x^2y + 2y - 4 x = 0,
\]</span></p>
<p>if <span class="math inline">\(x=4\)</span>, what is a value for <span class="math inline">\(y\)</span> such that <span class="math inline">\((x,y)\)</span> is a point on the graph of the equation?</p>
<div class="cell" data-hold="true" data-execution_count="42">
<div class="cell-output cell-output-display" data-execution_count="43">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15396278497585772145" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_15396278497585772145">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="15396278497585772145" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="15396278497585772145_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("15396278497585772145").addEventListener("change", function() {
var correct = (Math.abs(this.value - 0.8888888888888888) <= 0.001);
var msgBox = document.getElementById('15396278497585772145_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_15396278497585772145")
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_15396278497585772145")
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>For the equation</p>
<p><span class="math display">\[
(y-5)\cdot \cos(4\cdot \sqrt{(x-4)^2 + y^2)} = x\cdot\sin(2\sqrt{x^2 + y^2})
\]</span></p>
<p>is the point <span class="math inline">\((5,0)\)</span> a solution?</p>
<div class="cell" data-hold="true" data-execution_count="43">
<div class="cell-output cell-output-display" data-execution_count="44">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="764015551082001298" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_764015551082001298">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_764015551082001298_1">
<input class="form-check-input" type="radio" name="radio_764015551082001298" id="radio_764015551082001298_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_764015551082001298_2">
<input class="form-check-input" type="radio" name="radio_764015551082001298" id="radio_764015551082001298_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="764015551082001298_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_764015551082001298"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('764015551082001298_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_764015551082001298")
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_764015551082001298")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-3" class="level5">
<h5 class="anchored" data-anchor-id="question-3">Question</h5>
<p>Let <span class="math inline">\((x/3)^2 + (y/2)^2 = 1\)</span>. Find the slope of the tangent line at the point <span class="math inline">\((3/\sqrt{2}, 2/\sqrt{2})\)</span>.</p>
<div class="cell" data-hold="true" data-execution_count="44">
<div class="cell-output cell-output-display" data-execution_count="45">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="8965628254450821999" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_8965628254450821999">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="8965628254450821999" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="8965628254450821999_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("8965628254450821999").addEventListener("change", function() {
var correct = (Math.abs(this.value - -0.6666666666666666) <= 0.001);
var msgBox = document.getElementById('8965628254450821999_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_8965628254450821999")
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_8965628254450821999")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<section id="question-4" class="level6">
<h6 class="anchored" data-anchor-id="question-4">Question</h6>
<p>The <a href="http://www-history.mcs.st-and.ac.uk/Curves/Lame.html">lame</a> curves satisfy:</p>
<p><span class="math display">\[
\left(\frac{x}{a}\right)^n + \left(\frac{y}{b}\right)^n = 1.
\]</span></p>
<p>An ellipse is when <span class="math inline">\(n=1\)</span>. Take <span class="math inline">\(n=3\)</span>, <span class="math inline">\(a=1\)</span>, and <span class="math inline">\(b=2\)</span>.</p>
<p>Find a <em>positive</em> value of <span class="math inline">\(y\)</span> when <span class="math inline">\(x=1/2\)</span>.</p>
<div class="cell" data-hold="true" data-execution_count="45">
<div class="cell-output cell-output-display" data-execution_count="46">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="10778344140107602619" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_10778344140107602619">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="10778344140107602619" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="10778344140107602619_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("10778344140107602619").addEventListener("change", function() {
var correct = (Math.abs(this.value - 1.9129311827723892) <= 0.001);
var msgBox = document.getElementById('10778344140107602619_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_10778344140107602619")
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_10778344140107602619")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>What expression gives <span class="math inline">\(dy/dx\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="46">
<div class="cell-output cell-output-display" data-execution_count="47">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="2694798215192243754" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_2694798215192243754">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_2694798215192243754_1">
<input class="form-check-input" type="radio" name="radio_2694798215192243754" id="radio_2694798215192243754_1" value="1">
<span class="label-body px-1">
\(b \cdot (1 - (x/a)^n)^{1/n}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2694798215192243754_2">
<input class="form-check-input" type="radio" name="radio_2694798215192243754" id="radio_2694798215192243754_2" value="2">
<span class="label-body px-1">
\(-(y/x) \cdot (x/a)^n \cdot (y/b)^{-n}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2694798215192243754_3">
<input class="form-check-input" type="radio" name="radio_2694798215192243754" id="radio_2694798215192243754_3" value="3">
<span class="label-body px-1">
\(-(x/a)^n / (y/b)^n\)
</span>
</label>
</div>
</div>
</div>
<div id="2694798215192243754_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_2694798215192243754"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('2694798215192243754_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_2694798215192243754")
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_2694798215192243754")
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>Let <span class="math inline">\(y - x^2 = -\log(x)\)</span>. At the point <span class="math inline">\((1/2, 0.9431...)\)</span>, the graph has a tangent line. Find this line, then find its intersection point with the <span class="math inline">\(y\)</span> axes.</p>
<p>This intersection is:</p>
<div class="cell" data-hold="true" data-execution_count="47">
<div class="cell-output cell-output-display" data-execution_count="48">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="9078560423508484355" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_9078560423508484355">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="9078560423508484355" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="9078560423508484355_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("9078560423508484355").addEventListener("change", function() {
var correct = (Math.abs(this.value - 1.4431471805599454) <= 0.001);
var msgBox = document.getElementById('9078560423508484355_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_9078560423508484355")
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_9078560423508484355")
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>The <a href="http://www-history.mcs.st-and.ac.uk/Curves/Witch.html">witch</a> of <a href="http://www.maa.org/publications/periodicals/convergence/mathematical-treasures-maria-agnesis-analytical-institutions">Agnesi</a> is the curve given by the equation</p>
<p><span class="math display">\[
y(x^2 + a^2) = a^3.
\]</span></p>
<p>If <span class="math inline">\(a=1\)</span>, numerically find a a value of <span class="math inline">\(y\)</span> when <span class="math inline">\(x=2\)</span>.</p>
<div class="cell" data-hold="true" data-execution_count="48">
<div class="cell-output cell-output-display" data-execution_count="49">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="10744643143579004485" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_10744643143579004485">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="10744643143579004485" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="10744643143579004485_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("10744643143579004485").addEventListener("change", function() {
var correct = (Math.abs(this.value - 0.20000000000000004) <= 0.001);
var msgBox = document.getElementById('10744643143579004485_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_10744643143579004485")
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_10744643143579004485")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>What expression yields <span class="math inline">\(dy/dx\)</span> for this curve:</p>
<div class="cell" data-hold="true" data-execution_count="49">
<div class="cell-output cell-output-display" data-execution_count="50">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="17509294797043836341" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_17509294797043836341">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_17509294797043836341_1">
<input class="form-check-input" type="radio" name="radio_17509294797043836341" id="radio_17509294797043836341_1" value="1">
<span class="label-body px-1">
\(2xy / (x^2 + a^2)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_17509294797043836341_2">
<input class="form-check-input" type="radio" name="radio_17509294797043836341" id="radio_17509294797043836341_2" value="2">
<span class="label-body px-1">
\(-2xy/(x^2 + a^2)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_17509294797043836341_3">
<input class="form-check-input" type="radio" name="radio_17509294797043836341" id="radio_17509294797043836341_3" value="3">
<span class="label-body px-1">
\(a^3/(x^2 + a^2)\)
</span>
</label>
</div>
</div>
</div>
<div id="17509294797043836341_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_17509294797043836341"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('17509294797043836341_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_17509294797043836341")
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_17509294797043836341")
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>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../derivatives/figures/fcarc-may2016-fig35-350.gif" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Image number 35 from LHospitals calculus book (the first). Given a description of the curve, identify the point <code>E</code> which maximizes the height.</figcaption><p></p>
</figure>
</div>
<p>The figure above shows a problem appearing in LHospitals first calculus book. Given a function defined implicitly by <span class="math inline">\(x^3 + y^3 = axy\)</span> (with <span class="math inline">\(AP=x\)</span>, <span class="math inline">\(AM=y\)</span> and <span class="math inline">\(AB=a\)</span>) find the point <span class="math inline">\(E\)</span> that maximizes the height. In the <a href="http://www.ams.org/samplings/feature-column/fc-2016-05">AMS feature column</a> this problem is illustrated and solved in the historical manner, with the comment that the concept of implicit differentiation wouldnt have occurred to LHospital.</p>
<p>Using Implicit differentiation, find when <span class="math inline">\(dy/dx = 0\)</span>.</p>
<div class="cell" data-hold="true" data-execution_count="51">
<div class="cell-output cell-output-display" data-execution_count="52">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="30148596760991804" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_30148596760991804">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_30148596760991804_1">
<input class="form-check-input" type="radio" name="radio_30148596760991804" id="radio_30148596760991804_1" value="1">
<span class="label-body px-1">
\(y^2 = 3x/a\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_30148596760991804_2">
<input class="form-check-input" type="radio" name="radio_30148596760991804" id="radio_30148596760991804_2" value="2">
<span class="label-body px-1">
\(y=3x^2/a\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_30148596760991804_3">
<input class="form-check-input" type="radio" name="radio_30148596760991804" id="radio_30148596760991804_3" value="3">
<span class="label-body px-1">
\(y^2=a/(3x)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_30148596760991804_4">
<input class="form-check-input" type="radio" name="radio_30148596760991804" id="radio_30148596760991804_4" value="4">
<span class="label-body px-1">
\(y=a/(3x^2)\)
</span>
</label>
</div>
</div>
</div>
<div id="30148596760991804_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_30148596760991804"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('30148596760991804_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_30148596760991804")
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_30148596760991804")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Substituting the correct value of <span class="math inline">\(y\)</span>, above, into the defining equation gives what value for <span class="math inline">\(x\)</span>:</p>
<div class="cell" data-hold="true" data-execution_count="52">
<div class="cell-output cell-output-display" data-execution_count="53">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="8893479326781815712" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_8893479326781815712">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_8893479326781815712_1">
<input class="form-check-input" type="radio" name="radio_8893479326781815712" id="radio_8893479326781815712_1" value="1">
<span class="label-body px-1">
\(x=(1/3) a 2^{1/3}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_8893479326781815712_2">
<input class="form-check-input" type="radio" name="radio_8893479326781815712" id="radio_8893479326781815712_2" value="2">
<span class="label-body px-1">
\(x=(1/2) a^3 3^{1/3}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_8893479326781815712_3">
<input class="form-check-input" type="radio" name="radio_8893479326781815712" id="radio_8893479326781815712_3" value="3">
<span class="label-body px-1">
\(x=(1/3) a^2 2^{1/2}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_8893479326781815712_4">
<input class="form-check-input" type="radio" name="radio_8893479326781815712" id="radio_8893479326781815712_4" value="4">
<span class="label-body px-1">
\(x=(1/2) a 2^{1/2}\)
</span>
</label>
</div>
</div>
</div>
<div id="8893479326781815712_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_8893479326781815712"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('8893479326781815712_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_8893479326781815712")
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_8893479326781815712")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-8" class="level6">
<h6 class="anchored" data-anchor-id="question-8">Question</h6>
<p>For the equation of an ellipse:</p>
<p><span class="math display">\[
\left(\frac{x}{a}\right)^2 + \left(\frac{y}{b}\right)^2 = 1,
\]</span></p>
<p>compute <span class="math inline">\(d^2y/dx^2\)</span>. Is this the answer?</p>
<p><span class="math display">\[
\frac{d^2y}{dx^2} = -\frac{b^2}{a^2\cdot y} - \frac{b^4\cdot x^2}{a^4\cdot y^3} = -\frac{1}{y}\frac{b^2}{a^2}(1 + \frac{b^2 x^2}{a^2 y^2}).
\]</span></p>
<div class="cell" data-hold="true" data-execution_count="53">
<div class="cell-output cell-output-display" data-execution_count="54">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="11015858724863530783" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_11015858724863530783">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_11015858724863530783_1">
<input class="form-check-input" type="radio" name="radio_11015858724863530783" id="radio_11015858724863530783_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_11015858724863530783_2">
<input class="form-check-input" type="radio" name="radio_11015858724863530783" id="radio_11015858724863530783_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="11015858724863530783_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_11015858724863530783"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('11015858724863530783_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_11015858724863530783")
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_11015858724863530783")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>If <span class="math inline">\(y&gt;0\)</span> is the sign positive or negative?</p>
<div class="cell" data-hold="true" data-execution_count="54">
<div class="cell-output cell-output-display" data-execution_count="55">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="6865852169373479876" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_6865852169373479876">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_6865852169373479876_1">
<input class="form-check-input" type="radio" name="radio_6865852169373479876" id="radio_6865852169373479876_1" value="1">
<span class="label-body px-1">
positive
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6865852169373479876_2">
<input class="form-check-input" type="radio" name="radio_6865852169373479876" id="radio_6865852169373479876_2" value="2">
<span class="label-body px-1">
negative
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6865852169373479876_3">
<input class="form-check-input" type="radio" name="radio_6865852169373479876" id="radio_6865852169373479876_3" value="3">
<span class="label-body px-1">
Can be both
</span>
</label>
</div>
</div>
</div>
<div id="6865852169373479876_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_6865852169373479876"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('6865852169373479876_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_6865852169373479876")
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_6865852169373479876")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>If <span class="math inline">\(x&gt;0\)</span> is the sign positive or negative?</p>
<div class="cell" data-hold="true" data-execution_count="55">
<div class="cell-output cell-output-display" data-execution_count="56">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="14360898479955729448" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_14360898479955729448">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_14360898479955729448_1">
<input class="form-check-input" type="radio" name="radio_14360898479955729448" id="radio_14360898479955729448_1" value="1">
<span class="label-body px-1">
positive
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14360898479955729448_2">
<input class="form-check-input" type="radio" name="radio_14360898479955729448" id="radio_14360898479955729448_2" value="2">
<span class="label-body px-1">
negative
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14360898479955729448_3">
<input class="form-check-input" type="radio" name="radio_14360898479955729448" id="radio_14360898479955729448_3" value="3">
<span class="label-body px-1">
Can be both
</span>
</label>
</div>
</div>
</div>
<div id="14360898479955729448_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_14360898479955729448"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('14360898479955729448_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_14360898479955729448")
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_14360898479955729448")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>When <span class="math inline">\(x&gt;0\)</span>, the graph of the equation is…</p>
<div class="cell" data-hold="true" data-execution_count="56">
<div class="cell-output cell-output-display" data-execution_count="57">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="13747175260796697145" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_13747175260796697145">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_13747175260796697145_1">
<input class="form-check-input" type="radio" name="radio_13747175260796697145" id="radio_13747175260796697145_1" value="1">
<span class="label-body px-1">
concave up
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13747175260796697145_2">
<input class="form-check-input" type="radio" name="radio_13747175260796697145" id="radio_13747175260796697145_2" value="2">
<span class="label-body px-1">
concave down
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13747175260796697145_3">
<input class="form-check-input" type="radio" name="radio_13747175260796697145" id="radio_13747175260796697145_3" value="3">
<span class="label-body px-1">
both concave up and down
</span>
</label>
</div>
</div>
</div>
<div id="13747175260796697145_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_13747175260796697145"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('13747175260796697145_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_13747175260796697145")
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_13747175260796697145")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
</section>
</section>
<section id="appendix" class="level2" data-number="33.7">
<h2 data-number="33.7" class="anchored" data-anchor-id="appendix"><span class="header-section-number">33.7</span> Appendix</h2>
<p>There are other packages in the <code>Julia</code> ecosystem that can plot implicit equations.</p>
<section id="the-implicitequations-package" class="level3" data-number="33.7.1">
<h3 data-number="33.7.1" class="anchored" data-anchor-id="the-implicitequations-package"><span class="header-section-number">33.7.1</span> The ImplicitEquations package</h3>
<p>The <code>ImplicitEquations</code> packages can plot equations and inequalities. The use is somewhat similar to the examples above, but the object plotted is a predicate, not a function. These predicates are created with functions like <code>Eq</code> or <code>Lt</code>.</p>
<p>For example, the <code>ImplicitPlots</code> manual shows this function <span class="math inline">\(f(x,y) = (x^4 + y^4 - 1) \cdot (x^2 + y^2 - 2) + x^5 \cdot y\)</span> to plot. Using <code>ImplicitEquations</code>, this equation would be plotted with:</p>
<div class="cell" data-hold="true" data-execution_count="57">
<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><span class="im">using</span> <span class="bu">ImplicitEquations</span></span>
<span id="cb52-2"><a href="#cb52-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> (x<span class="op">^</span><span class="fl">4</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">4</span> <span class="op">-</span> <span class="fl">1</span>) <span class="op">*</span> (x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">2</span> <span class="op">-</span> <span class="fl">2</span>) <span class="op">+</span> x<span class="op">^</span><span class="fl">5</span> <span class="op">*</span> y</span>
<span id="cb52-3"><a href="#cb52-3" aria-hidden="true" tabindex="-1"></a>r <span class="op">=</span> <span class="fu">Eq</span>(f, <span class="fl">0</span>) <span class="co"># the equation f(x,y) = 0</span></span>
<span id="cb52-4"><a href="#cb52-4" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</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="58">
<p><img src="implicit_differentiation_files/figure-html/cell-58-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Unlike <code>ImplicitPlots</code>, inequalities may be displayed:</p>
<div class="cell" data-hold="true" data-execution_count="58">
<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">f</span>(x,y) <span class="op">=</span> (x<span class="op">^</span><span class="fl">4</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">4</span> <span class="op">-</span> <span class="fl">1</span>) <span class="op">*</span> (x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">2</span> <span class="op">-</span> <span class="fl">2</span>) <span class="op">+</span> x<span class="op">^</span><span class="fl">5</span> <span class="op">*</span> y</span>
<span id="cb53-2"><a href="#cb53-2" aria-hidden="true" tabindex="-1"></a>r <span class="op">=</span> <span class="fu">Lt</span>(f, <span class="fl">0</span>) <span class="co"># the inequality f(x,y) &lt; 0</span></span>
<span id="cb53-3"><a href="#cb53-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(r; M<span class="op">=</span><span class="fl">10</span>, N<span class="op">=</span><span class="fl">10</span>) <span class="co"># less blocky</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">
<p><img src="implicit_differentiation_files/figure-html/cell-59-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The rendered plots look “blocky” due to the algorithm used to plot the equations. As there is no rule defining <span class="math inline">\((x,y)\)</span> pairs to plot, a search by regions is done. A region is initially labeled undetermined. If it can be shown that for any value in the region the equation is true (equations can also be inequalities), the region is colored black. If it can be shown it will never be true, the region is dropped. If a black-and-white answer is not clear, the region is subdivided and each subregion is similarly tested. This continues until the remaining undecided regions are smaller than some threshold. Such regions comprise a boundary, and here are also colored black. Only regions are plotted - not <span class="math inline">\((x,y)\)</span> pairs - so the results are blocky. Pass larger values of <span class="math inline">\(N=M\)</span> (with defaults of <span class="math inline">\(8\)</span>) to <code>plot</code> to lower the threshold at the cost of longer computation times, as seen in the last example.</p>
</section>
<section id="the-intervalconstraintprogramming-package" class="level3" data-number="33.7.2">
<h3 data-number="33.7.2" class="anchored" data-anchor-id="the-intervalconstraintprogramming-package"><span class="header-section-number">33.7.2</span> The IntervalConstraintProgramming package</h3>
<p>The <code>IntervalConstraintProgramming</code> package also can be used to graph implicit equations. For certain problem descriptions it is significantly faster and makes better graphs. The usage is slightly more involved. We show the commands, but dont run them here, as there are minor conflicts with the <code>CalculusWithJulia</code>package.</p>
<p>We specify a problem using the <code>@constraint</code> macro. Using a macro allows expressions to involve free symbols, so the problem is specified in an equation-like manner:</p>
<div class="sourceCode cell-code" id="cb54"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb54-1"><a href="#cb54-1" aria-hidden="true" tabindex="-1"></a>S <span class="op">=</span> <span class="pp">@constraint</span> x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">2</span> <span class="op">&lt;=</span> <span class="fl">2</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>The right hand side must be a number.</p>
<p>The area to plot over must be specified as an <code>IntervalBox</code>, basically a pair of intervals. The interval <span class="math inline">\([a,b]\)</span> is expressed through <code>a..b</code>:</p>
<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>J <span class="op">=</span> <span class="op">-</span><span class="fl">3</span><span class="op">..</span><span class="fl">3</span></span>
<span id="cb55-2"><a href="#cb55-2" aria-hidden="true" tabindex="-1"></a>X <span class="op">=</span> IntervalArithmetic.<span class="fu">IntervalBox</span>(J, J)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>The <code>pave</code> command does the heavy lifting:</p>
<div class="sourceCode cell-code" id="cb56"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb56-1"><a href="#cb56-1" aria-hidden="true" tabindex="-1"></a>region <span class="op">=</span> IntervalConstraintProgramming.<span class="fu">pave</span>(S, X)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>A plot can be made of either the boundary, the interior, or both.</p>
<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><span class="fu">plot</span>(region.inner) <span class="co"># plot interior; use r.boundary for boundary</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</section>
</section>
</main> <!-- /main -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const clipboard = new window.ClipboardJS('.code-copy-button', {
target: function(trigger) {
return trigger.previousElementSibling;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
setTimeout(function() {
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
});
function tippyHover(el, contentFn) {
const config = {
allowHTML: true,
content: contentFn,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start'
};
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
let href = ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
return note.innerHTML;
});
}
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const cites = ref.parentNode.getAttribute('data-cites').split(' ');
tippyHover(ref, function() {
var popup = window.document.createElement('div');
cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
var filterRegex = new RegExp('/' + window.location.host + '/');
var isInternal = (href) => {
return filterRegex.test(href) || localhostRegex.test(href);
}
// Inspect non-navigation links and adorn them if external
var links = window.document.querySelectorAll('a:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external)');
for (var i=0; i<links.length; i++) {
const link = links[i];
if (!isInternal(link.href)) {
// target, if specified
link.setAttribute("target", "_blank");
}
}
});
</script>
<nav class="page-navigation">
<div class="nav-page nav-page-previous">
<a href="../derivatives/lhospitals_rule.html" class="pagination-link">
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">32</span>&nbsp; <span class="chapter-title">LHospitals Rule</span></span>
</a>
</div>
<div class="nav-page nav-page-next">
<a href="../derivatives/related_rates.html" class="pagination-link">
<span class="nav-page-text"><span class="chapter-number">34</span>&nbsp; <span class="chapter-title">Related rates</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>