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

5267 lines
317 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 - 55&nbsp; Scalar functions</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="../differentiable_vector_calculus/scalar_functions_applications.html" rel="next">
<link href="../differentiable_vector_calculus/vector_valued_functions.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">55</span>&nbsp; <span class="chapter-title">Scalar functions</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 collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="false">Derivatives</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-3" class="collapse list-unstyled sidebar-section depth1 ">
<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"><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" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-6" aria-expanded="true">Differential vector calculus</a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-6" aria-expanded="true">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-6" class="collapse list-unstyled sidebar-section depth1 show">
<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 active"><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="#visualizing-scalar-functions" id="toc-visualizing-scalar-functions" class="nav-link active" data-scroll-target="#visualizing-scalar-functions"> <span class="header-section-number">55.1</span> Visualizing scalar functions</a>
<ul class="collapse">
<li><a href="#contour-plots-and-heatmaps" id="toc-contour-plots-and-heatmaps" class="nav-link" data-scroll-target="#contour-plots-and-heatmaps"> <span class="header-section-number">55.1.1</span> Contour plots and heatmaps</a></li>
</ul></li>
<li><a href="#limits" id="toc-limits" class="nav-link" data-scroll-target="#limits"> <span class="header-section-number">55.2</span> Limits</a>
<ul class="collapse">
<li><a href="#continuity-of-scalar-functions" id="toc-continuity-of-scalar-functions" class="nav-link" data-scroll-target="#continuity-of-scalar-functions"> <span class="header-section-number">55.2.1</span> Continuity of scalar functions</a></li>
</ul></li>
<li><a href="#partial-derivatives-and-the-gradient" id="toc-partial-derivatives-and-the-gradient" class="nav-link" data-scroll-target="#partial-derivatives-and-the-gradient"> <span class="header-section-number">55.3</span> Partial derivatives and the gradient</a>
<ul class="collapse">
<li><a href="#finding-partial-derivatives-in-julia" id="toc-finding-partial-derivatives-in-julia" class="nav-link" data-scroll-target="#finding-partial-derivatives-in-julia"> <span class="header-section-number">55.3.1</span> Finding partial derivatives in Julia</a></li>
<li><a href="#visualizing-the-gradient" id="toc-visualizing-the-gradient" class="nav-link" data-scroll-target="#visualizing-the-gradient"> <span class="header-section-number">55.3.2</span> Visualizing the gradient</a></li>
</ul></li>
<li><a href="#differentiable" id="toc-differentiable" class="nav-link" data-scroll-target="#differentiable"> <span class="header-section-number">55.4</span> Differentiable</a></li>
<li><a href="#the-chain-rule-to-evaluate-fcircvecgamma" id="toc-the-chain-rule-to-evaluate-fcircvecgamma" class="nav-link" data-scroll-target="#the-chain-rule-to-evaluate-fcircvecgamma"> <span class="header-section-number">55.5</span> The chain rule to evaluate <span class="math inline">\(f\circ\vec\gamma\)</span></a></li>
<li><a href="#directional-derivatives" id="toc-directional-derivatives" class="nav-link" data-scroll-target="#directional-derivatives"> <span class="header-section-number">55.6</span> Directional Derivatives</a></li>
<li><a href="#other-types-of-compositions-and-the-chain-rule" id="toc-other-types-of-compositions-and-the-chain-rule" class="nav-link" data-scroll-target="#other-types-of-compositions-and-the-chain-rule"> <span class="header-section-number">55.7</span> Other types of compositions and the chain rule</a>
<ul class="collapse">
<li><a href="#chain-rule-for-a-univariate-function-composed-with-a-scalar-function" id="toc-chain-rule-for-a-univariate-function-composed-with-a-scalar-function" class="nav-link" data-scroll-target="#chain-rule-for-a-univariate-function-composed-with-a-scalar-function"> <span class="header-section-number">55.7.1</span> Chain rule for a univariate function composed with a scalar function</a></li>
<li><a href="#chain-rule-for-a-scalar-function-f-composed-with-a-function-g-rm-rightarrow-rn." id="toc-chain-rule-for-a-scalar-function-f-composed-with-a-function-g-rm-rightarrow-rn." class="nav-link" data-scroll-target="#chain-rule-for-a-scalar-function-f-composed-with-a-function-g-rm-rightarrow-rn."> <span class="header-section-number">55.7.2</span> Chain rule for a scalar function, <span class="math inline">\(f\)</span>, composed with a function <span class="math inline">\(G: R^m \rightarrow R^n\)</span>.</a></li>
</ul></li>
<li><a href="#higher-order-partial-derivatives" id="toc-higher-order-partial-derivatives" class="nav-link" data-scroll-target="#higher-order-partial-derivatives"> <span class="header-section-number">55.8</span> Higher order partial derivatives</a></li>
<li><a href="#questions" id="toc-questions" class="nav-link" data-scroll-target="#questions"> <span class="header-section-number">55.9</span> Questions</a></li>
</ul>
<div class="toc-actions"><div><i class="bi bi-github"></i></div><div class="action-links"><p><a href="https://github.com/jverzani/CalculusWithJuliaNotes.jl/edit/main/quarto/differentiable_vector_calculus/scalar_functions.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">55</span>&nbsp; <span class="chapter-title">Scalar functions</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">ForwardDiff</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">SymPy</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">Roots</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">QuadGK</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">JSON</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>Also, these methods from the <code>Contour</code> package:</p>
<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="im">import</span> <span class="bu">Contour</span>: contours, levels, level, lines, coordinates</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<hr>
<p>Consider a function <span class="math inline">\(f: R^n \rightarrow R\)</span>. It has multiple arguments for its input (an <span class="math inline">\(x_1, x_2, \dots, x_n\)</span>) and only one, <em>scalar</em>, value for an output. Some simple examples might be:</p>
<p><span class="math display">\[
\begin{align}
f(x,y) &amp;= x^2 + y^2\\
g(x,y) &amp;= x \cdot y\\
h(x,y) &amp;= \sin(x) \cdot \sin(y)
\end{align}
\]</span></p>
<p>For two examples from real life consider the elevation Point Query Service (of the <a href="https://nationalmap.gov/epqs/">USGS</a>) returns the elevation in international feet or meters for a specific latitude/longitude within the United States. The longitude can be associated to an <span class="math inline">\(x\)</span> coordinate, the latitude to a <span class="math inline">\(y\)</span> coordinate, and the elevation a <span class="math inline">\(z\)</span> coordinate, and as long as the region is small enough, the <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span> coordinates can be thought to lie on a plane. (A flat earth assumption.)</p>
<p>Similarly, a weather map, say of the United States, may show the maximum predicted temperature for a given day. This describes a function that take a position (<span class="math inline">\(x\)</span>, <span class="math inline">\(y\)</span>) and returns a predicted temperature (<span class="math inline">\(z\)</span>).</p>
<p>Mathematically, we may describe the values <span class="math inline">\((x,y)\)</span> in terms of a point, <span class="math inline">\(P=(x,y)\)</span> or a vector <span class="math inline">\(\vec{v} = \langle x, y \rangle\)</span> using the identification of a point with a vector. As convenient, we may write any of <span class="math inline">\(f(x,y)\)</span>, <span class="math inline">\(f(P)\)</span>, or <span class="math inline">\(f(\vec{v})\)</span> to describe the evaluation of <span class="math inline">\(f\)</span> at the value <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span></p>
<hr>
<p>Returning to the task at hand, in <code>Julia</code>, defining a scalar function is straightforward, the syntax following mathematical notation:</p>
<div class="cell" data-execution_count="5">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fu">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>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="fu">g</span>(x,y) <span class="op">=</span> x <span class="op">*</span> y</span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="fu">h</span>(x,y) <span class="op">=</span> <span class="fu">sin</span>(x) <span class="op">*</span> <span class="fu">sin</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="6">
<pre><code>h (generic function with 1 method)</code></pre>
</div>
</div>
<p>To call a scalar function for specific values of <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span> is also similar to the mathematical case:</p>
<div class="cell" 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><span class="fu">f</span>(<span class="fl">1</span>,<span class="fl">2</span>), <span class="fu">g</span>(<span class="fl">2</span>, <span class="fl">3</span>), <span class="fu">h</span>(<span class="fl">3</span>,<span class="fl">4</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="7">
<pre><code>(5, 6, -0.10679997423758245)</code></pre>
</div>
</div>
<p>It may be advantageous to have the values as a vector or a point, as in <code>v=[x,y]</code>. Splatting can be used to turn a vector or tuple into two arguments:</p>
<div class="cell" data-execution_count="7">
<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>v <span class="op">=</span> [<span class="fl">1</span>,<span class="fl">2</span>]</span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(v<span class="op">...</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="8">
<pre><code>5</code></pre>
</div>
</div>
<p>Alternatively, the function may be defined using a vector argument:</p>
<div class="cell" data-execution_count="8">
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(v) <span class="op">=</span> v[<span class="fl">1</span>]<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> v[<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="9">
<pre><code>f (generic function with 2 methods)</code></pre>
</div>
</div>
<p>A style required for other packages within the <code>Julia</code> ecosystem, as there are many advantages to passing containers of values: they can have arbitrary length, they can be modified inside a function, the functions can be more generic, etc.</p>
<p>More verbosely, but avoiding index notation, we can use multiline functions:</p>
<div class="cell" data-execution_count="9">
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span> <span class="fu">g</span>(v)</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> x, y <span class="op">=</span> v</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a> x <span class="op">*</span> y</span>
<span id="cb11-4"><a href="#cb11-4" 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="10">
<pre><code>g (generic function with 2 methods)</code></pre>
</div>
</div>
<p>Then we have</p>
<div class="cell" data-execution_count="10">
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(v), <span class="fu">g</span>([<span class="fl">2</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="11">
<pre><code>(5, 6)</code></pre>
</div>
</div>
<hr>
<p>More elegantly, perhaps and the approach we will use in this section is to mirror the mathematical notation through multiple dispatch. If we define <code>j</code> for multiple variables, say with:</p>
<div class="cell" data-execution_count="11">
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="fu">j</span>(x,y) <span class="op">=</span> x<span class="op">^</span><span class="fl">2</span> <span class="op">-</span> <span class="fl">2</span>x<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="12">
<pre><code>j (generic function with 1 method)</code></pre>
</div>
</div>
<p>The we can define an alternative method with just a single variable and use splatting to turn it into multiple variables:</p>
<div class="cell" data-execution_count="12">
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="fu">j</span>(v) <span class="op">=</span> <span class="fu">j</span>(v<span class="op">...</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="13">
<pre><code>j (generic function with 2 methods)</code></pre>
</div>
</div>
<p>The we can call <code>j</code> with a vector or point:</p>
<div class="cell" data-execution_count="13">
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="fu">j</span>([<span class="fl">1</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="14">
<pre><code>-7</code></pre>
</div>
</div>
<p>or by passing in the individual components:</p>
<div class="cell" data-execution_count="14">
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="fu">j</span>(<span class="fl">1</span>,<span class="fl">2</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="15">
<pre><code>-7</code></pre>
</div>
</div>
<hr>
<p>Following a calculus perspective, we take up the question of how to visualize scalar functions within <code>Julia</code>? Further, how to describe the change in the function between nearby values?</p>
<section id="visualizing-scalar-functions" class="level2" data-number="55.1">
<h2 data-number="55.1" class="anchored" data-anchor-id="visualizing-scalar-functions"><span class="header-section-number">55.1</span> Visualizing scalar functions</h2>
<p>Suppose for the moment that <span class="math inline">\(f:R^2 \rightarrow R\)</span>. The equation <span class="math inline">\(z = f(x,y)\)</span> may be visualized by the set of points in <span class="math inline">\(3\)</span>-dimensions <span class="math inline">\(\{(x,y,z): z = f(x,y)\}\)</span>. This will render as a surface, and that surface will pass a “vertical line test”, in that each <span class="math inline">\((x,y)\)</span> value corresponds to at most one <span class="math inline">\(z\)</span> value. We will see alternatives for describing surfaces beyond through a function of the form <span class="math inline">\(z=f(x,y)\)</span>. These are similar to how a curve in the <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span> plane can be described by a function of the form <span class="math inline">\(y=f(x)\)</span> but also through an equation of the form <span class="math inline">\(F(x,y) = c\)</span> or through a parametric description, such as is used for planar curves. For now though we focus on the case where <span class="math inline">\(z=f(x,y)\)</span>.</p>
<p>In <code>Julia</code>, plotting such a surface requires a generalization to plotting a univariate function where, typically, a grid of evenly spaced values is given between some <span class="math inline">\(a\)</span> and <span class="math inline">\(b\)</span>, the corresponding <span class="math inline">\(y\)</span> or <span class="math inline">\(f(x)\)</span> values are found, and then the points are connected in a dot-to-dot manner.</p>
<p>Here, a two-dimensional grid of <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span> values needs specifying, and the corresponding <span class="math inline">\(z\)</span> values found. As the grid will be assumed to be regular only the <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span> values need specifying, the set of pairs can be computed. The <span class="math inline">\(z\)</span> values, it will be seen, are easily computed. This cloud of points is plotted and each cell in the <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span> plane is plotted with a surface giving the <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span>-<span class="math inline">\(z\)</span>, <span class="math inline">\(3\)</span>-dimensional, view. One way to plot such a surface is to tessalate the cell and then for each triangle, represent a plane made up of the <span class="math inline">\(3\)</span> boundary points.</p>
<p>Here is an example:</p>
<div class="cell" data-execution_count="15">
<div class="sourceCode cell-code" id="cb23"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a><span class="fu">𝒇</span>(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></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">
<pre><code>𝒇 (generic function with 1 method)</code></pre>
</div>
</div>
<div class="cell" data-execution_count="16">
<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>xs <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">2</span>, <span class="fl">2</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a>ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">2</span>, <span class="fl">2</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, 𝒇)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="17">
<p><img src="scalar_functions_files/figure-html/cell-17-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The <code>surface</code> function will generate the surface.</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>Using <code>surface</code> as a function name is equivalent to <code>plot(xs, ys, f, seriestype=:surface)</code>.</p>
</div>
</div>
<p>We can also use <code>surface(xs, ys, zs)</code> where <code>zs</code> is not a vector, but rather a <em>matrix</em> of values corresponding to a grid described by the <code>xs</code> and <code>ys</code>. A matrix is a rectangular collection of values indexed by row and column through indices <code>i</code> and <code>j</code>. Here the values in <code>zs</code> should satisfy: the <span class="math inline">\(i\)</span>th row and <span class="math inline">\(j\)</span>th column entry should be <span class="math inline">\(z_{ij} = f(x_i, y_j)\)</span> where <span class="math inline">\(x_i\)</span> is the <span class="math inline">\(i\)</span>th entry from the <code>xs</code> and <span class="math inline">\(y_j\)</span> the <span class="math inline">\(j\)</span>th entry from the <code>ys</code>.</p>
<p>We can generate this using a comprehension:</p>
<div class="cell" data-hold="true" data-execution_count="17">
<div class="sourceCode cell-code" id="cb26"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a>zs <span class="op">=</span> [<span class="fu">𝒇</span>(x,y) for y <span class="kw">in</span> ys, x <span class="kw">in</span> xs]</span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, zs)</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">
<p><img src="scalar_functions_files/figure-html/cell-18-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>If remembering that the <span class="math inline">\(y\)</span> values go first, and then the <span class="math inline">\(x\)</span> values in the above is too hard, then an alternative can be used. Broadcasting <code>f.(xs,ys)</code> may not make sense, were the <code>xs</code> and <code>ys</code> not of commensurate lengths, and when it does, this call pairs off <code>xs</code> and <code>ys</code> values and passes them to <code>f</code>. What is desired here is different, where for each <code>xs</code> value there are pairs for each of the <code>ys</code> values. The syntax <code>xs'</code> can ve viewed as creating a <em>row</em> vector, where <code>xs</code> is a <em>column</em> vector. Broadcasting will create a <em>matrix</em> of values in this case. So the following is identical to the above:</p>
<div class="cell" data-execution_count="18">
<div class="sourceCode cell-code" id="cb27"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, <span class="fu">𝒇</span>.(xs<span class="op">'</span>, ys))</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">
<p><img src="scalar_functions_files/figure-html/cell-19-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>(This is still subtle. The use of the adjoint operation on <code>ys</code> will error if the dimensions are not square, but will produce an incorrect surface if not. It would be best to simply pass the function and let <code>Plots</code> handle this detail which for the alternative <code>Makie</code> is reversed.)</p>
<hr>
<p>An alternate to <code>surface</code> is <code>wireframe</code> which may not use shading in all backenends. This displays a grid in the <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span> plane mapped to the surface:</p>
<div class="cell" data-hold="true" data-execution_count="19">
<div class="sourceCode cell-code" id="cb28"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">2</span>,<span class="fl">2</span>, length<span class="op">=</span><span class="fl">10</span>) <span class="co"># downsample to see the frame</span></span>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a><span class="fu">wireframe</span>(xs, ys, 𝒇) <span class="co"># gr() or pyplot() wireplots render better than plotly()</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">
<p><img src="scalar_functions_files/figure-html/cell-20-output-1.svg" class="img-fluid"></p>
</div>
</div>
<section id="example" class="level5">
<h5 class="anchored" data-anchor-id="example">Example</h5>
<p>The surface <span class="math inline">\(f(x,y) = x^2 - y^2\)</span> has a “saddle,” as this shows:</p>
<div class="cell" data-hold="true" data-execution_count="20">
<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">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>
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">2</span>, <span class="fl">2</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
<span id="cb29-3"><a href="#cb29-3" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, 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="21">
<p><img src="scalar_functions_files/figure-html/cell-21-output-1.svg" class="img-fluid"></p>
</div>
</div>
</section>
<section id="example-1" class="level5">
<h5 class="anchored" data-anchor-id="example-1">Example</h5>
<p>As mentioned. In plots of univariate functions, a dot-to-dot algorithm is followed. For surfaces, the two dots are replaced by four points, which over determines a plane. Some choice is made to partition that rectangle into two triangles, and for each triangle, the <span class="math inline">\(3\)</span> resulting points determines a plane, which can be suitably rendered.</p>
<p>We can see this in the default <code>gr</code> toolkit by forcing the surface to show just one cell, as the <code>xs</code> and <code>ys</code> below only contain <span class="math inline">\(2\)</span> values:</p>
<div class="cell" data-hold="true" data-execution_count="21">
<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>xs <span class="op">=</span> [<span class="op">-</span><span class="fl">1</span>,<span class="fl">1</span>]; ys <span class="op">=</span> [<span class="op">-</span><span class="fl">1</span>,<span class="fl">1</span>]</span>
<span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> x<span class="op">*</span>y</span>
<span id="cb30-3"><a href="#cb30-3" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, 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="22">
<p><img src="scalar_functions_files/figure-html/cell-22-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Compare this, to the same region, but with many cells to represent the surface:</p>
<div class="cell" data-hold="true" data-execution_count="22">
<div class="sourceCode cell-code" id="cb31"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">1</span>, <span class="fl">1</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
<span id="cb31-2"><a href="#cb31-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> x<span class="op">*</span>y</span>
<span id="cb31-3"><a href="#cb31-3" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, 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="23">
<p><img src="scalar_functions_files/figure-html/cell-23-output-1.svg" class="img-fluid"></p>
</div>
</div>
</section>
<section id="contour-plots-and-heatmaps" class="level3" data-number="55.1.1">
<h3 data-number="55.1.1" class="anchored" data-anchor-id="contour-plots-and-heatmaps"><span class="header-section-number">55.1.1</span> Contour plots and heatmaps</h3>
<p>Consider the example of latitude, longitude, and elevation data describing a surface. The following graph is generated from such data, which was retrieved from the USGS website for a given area. The grid points are chosen about every <span class="math inline">\(150\)</span>m, so this is not too fine grained.</p>
<div class="cell" data-execution_count="25">
<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>SC <span class="op">=</span> JSON.<span class="fu">parse</span>(somocon) <span class="co"># defined in a hidden cell</span></span>
<span id="cb32-2"><a href="#cb32-2" aria-hidden="true" tabindex="-1"></a>xsₛ, ysₛ, zsₛ <span class="op">=</span> [<span class="fu">float</span>.(SC[i]) for i <span class="kw">in</span> (<span class="st">"xs"</span>, <span class="st">"ys"</span>,<span class="st">"zs"</span>)]</span>
<span id="cb32-3"><a href="#cb32-3" aria-hidden="true" tabindex="-1"></a>zzsₛ <span class="op">=</span> <span class="fu">reshape</span>(zsₛ, (<span class="fu">length</span>(xsₛ), <span class="fu">length</span>(ysₛ)))<span class="ch">' # reshape to matrix</span></span>
<span id="cb32-4"><a href="#cb32-4" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xsₛ, ysₛ, zzsₛ)</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">
<p><img src="scalar_functions_files/figure-html/cell-26-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>This shows a bit of the topography. If we look at the region from directly above, the graph looks different:</p>
<div class="cell" data-execution_count="26">
<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><span class="fu">surface</span>(xsₛ, ysₛ, zzsₛ, camera<span class="op">=</span>(<span class="fl">0</span>, <span class="fl">90</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="scalar_functions_files/figure-html/cell-27-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The rendering uses different colors to indicate height. A more typical graph, that is somewhat similar to the top down view, is a <em>contour</em> map.</p>
<p>For a scalar function, Define a <em>level curve</em> as the solutions to the equations <span class="math inline">\(f(x,y) = c\)</span> for a given <span class="math inline">\(c\)</span>. (Or more generally <span class="math inline">\(f(\vec{x}) = c\)</span> for a vector if dimension <span class="math inline">\(2\)</span> or more.) Plotting a selection of level curves yields a <em>contour</em> graph. These are produced with <code>contour</code> and called as above. For example, we have:</p>
<div class="cell" data-execution_count="27">
<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><span class="fu">contour</span>(xsₛ, ysₛ, zzsₛ)</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">
<p><img src="scalar_functions_files/figure-html/cell-28-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Were one to walk along one of the contour lines, then there would be no change in elevation. The areas of greatest change in elevation - basically the hills - occur where the different contour lines are closest. In this particular area, there is a river that runs from the upper right through to the lower left and this is flanked by hills.</p>
<p>The <span class="math inline">\(c\)</span> values for the levels drawn may be specified through the <code>levels</code> argument:</p>
<div class="cell" data-execution_count="28">
<div class="sourceCode cell-code" id="cb35"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a><span class="fu">contour</span>(xsₛ, ysₛ, zzsₛ, levels<span class="op">=</span>[<span class="fl">50</span>,<span class="fl">75</span>,<span class="fl">100</span>, <span class="fl">125</span>, <span class="fl">150</span>, <span class="fl">175</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="29">
<p><img src="scalar_functions_files/figure-html/cell-29-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>That shows the <span class="math inline">\(50\)</span>m, <span class="math inline">\(75\)</span>m, … contours.</p>
<p>If a fixed number of evenly spaced levels is desirable, then the <code>nlevels</code> argument is available.</p>
<div class="cell" data-execution_count="29">
<div class="sourceCode cell-code" id="cb36"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a><span class="fu">contour</span>(xsₛ, ysₛ, zzsₛ, nlevels <span class="op">=</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="30">
<p><img src="scalar_functions_files/figure-html/cell-30-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>If a function describes the surface, then the function may be passed as the third value:</p>
<div class="cell" data-hold="true" data-execution_count="30">
<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><span class="fu">f</span>(x, y) <span class="op">=</span> <span class="fu">sin</span>(x) <span class="op">-</span> <span class="fu">cos</span>(y)</span>
<span id="cb37-2"><a href="#cb37-2" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> <span class="fu">range</span>(<span class="fl">0</span>, <span class="fl">2</span>pi, length<span class="op">=</span><span class="fl">100</span>)</span>
<span id="cb37-3"><a href="#cb37-3" aria-hidden="true" tabindex="-1"></a>ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="cn">pi</span>, <span class="cn">pi</span>, length <span class="op">=</span> <span class="fl">100</span>)</span>
<span id="cb37-4"><a href="#cb37-4" aria-hidden="true" tabindex="-1"></a><span class="fu">contour</span>(xs, ys, 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="31">
<p><img src="scalar_functions_files/figure-html/cell-31-output-1.svg" class="img-fluid"></p>
</div>
</div>
<section id="example-2" class="level5">
<h5 class="anchored" data-anchor-id="example-2">Example</h5>
<p>An informative graphic mixes both a surface plot with a contour plot. The <code>PyPlot</code> package can be used to generate one, but such graphs are not readily made within the <code>Plots</code> framework. Here is a workaround, where the contours are generated through the <code>Contours</code> package. At the beginning of this section several of its methods are imported.</p>
<p>This example shows how to add a contour at a fixed level (<span class="math inline">\(0\)</span> below). As no hidden line algorithm is used to hide the contour line if the surface were to cover it, a transparency is specified through <code>alpha=0.5</code>:</p>
<div class="cell" data-hold="true" data-execution_count="31">
<div class="sourceCode cell-code" id="cb38"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb38-1"><a href="#cb38-1" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span> <span class="fu">surface_contour</span>(xs, ys, f; offset<span class="op">=</span><span class="fl">0</span>)</span>
<span id="cb38-2"><a href="#cb38-2" aria-hidden="true" tabindex="-1"></a> p <span class="op">=</span> <span class="fu">surface</span>(xs, ys, f, legend<span class="op">=</span><span class="cn">false</span>, fillalpha<span class="op">=</span><span class="fl">0.5</span>)</span>
<span id="cb38-3"><a href="#cb38-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-4"><a href="#cb38-4" aria-hidden="true" tabindex="-1"></a> <span class="co">## we add to the graphic p, then plot</span></span>
<span id="cb38-5"><a href="#cb38-5" aria-hidden="true" tabindex="-1"></a> zs <span class="op">=</span> [<span class="fu">f</span>(x,y) for x <span class="kw">in</span> xs, y <span class="kw">in</span> ys] <span class="co"># reverse order for use with Contour package</span></span>
<span id="cb38-6"><a href="#cb38-6" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> cl <span class="kw">in</span> <span class="fu">levels</span>(<span class="fu">contours</span>(xs, ys, zs))</span>
<span id="cb38-7"><a href="#cb38-7" aria-hidden="true" tabindex="-1"></a> lvl <span class="op">=</span> <span class="fu">level</span>(cl) <span class="co"># the z-value of this contour level</span></span>
<span id="cb38-8"><a href="#cb38-8" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> line <span class="kw">in</span> <span class="fu">lines</span>(cl)</span>
<span id="cb38-9"><a href="#cb38-9" aria-hidden="true" tabindex="-1"></a> _xs, _ys <span class="op">=</span> <span class="fu">coordinates</span>(line) <span class="co"># coordinates of this line segment</span></span>
<span id="cb38-10"><a href="#cb38-10" aria-hidden="true" tabindex="-1"></a> _zs <span class="op">=</span> offset <span class="op">.+</span> (<span class="fl">0</span> <span class="op">.*</span> _xs)</span>
<span id="cb38-11"><a href="#cb38-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">plot!</span>(p, _xs, _ys, _zs, alpha<span class="op">=</span><span class="fl">0.5</span>) <span class="co"># add curve on x-y plane</span></span>
<span id="cb38-12"><a href="#cb38-12" aria-hidden="true" tabindex="-1"></a> <span class="cf">end</span></span>
<span id="cb38-13"><a href="#cb38-13" aria-hidden="true" tabindex="-1"></a> <span class="cf">end</span></span>
<span id="cb38-14"><a href="#cb38-14" aria-hidden="true" tabindex="-1"></a> p</span>
<span id="cb38-15"><a href="#cb38-15" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span>
<span id="cb38-16"><a href="#cb38-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-17"><a href="#cb38-17" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="cn">pi</span>, stop<span class="op">=</span><span class="cn">pi</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
<span id="cb38-18"><a href="#cb38-18" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> <span class="fl">2</span> <span class="op">+</span> <span class="fu">sin</span>(x) <span class="op">-</span> <span class="fu">cos</span>(y)</span>
<span id="cb38-19"><a href="#cb38-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-20"><a href="#cb38-20" aria-hidden="true" tabindex="-1"></a><span class="fu">surface_contour</span>(xs, ys, 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="32">
<p><img src="scalar_functions_files/figure-html/cell-32-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>We can see that at the minimum of the surface, the contour lines are nested closed loops with decreasing area.</p>
</section>
<section id="example-3" class="level5">
<h5 class="anchored" data-anchor-id="example-3">Example</h5>
<p>The figure shows a weather map from <span class="math inline">\(1943\)</span> with contour lines based on atmospheric pressure. These are also know as <em>isolines</em>.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../differentiable_vector_calculus/figures/daily-map.jpg" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Image from <a href="https://www.weather.gov/unr/1943-01-22">weather.gov</a> of a contour map showing atmospheric pressures from January 22, 1943 in Rapid City, South Dakota.</figcaption><p></p>
</figure>
</div>
<p>This day is highlighted as “The most notable temperature fluctuations occurred on January 22, 1943 when temperatures rose and fell almost 50 degrees in a few minutes. This phenomenon was caused when a frontal boundary separating extremely cold Arctic air from warmer Pacific air rolled like an ocean tide along the northern and eastern slopes of the Black Hills.”</p>
<p>This frontal boundary is marked with triangles and half circles along the thicker black line. The tight spacing of the contour lines above that marked line show a big change in pressure in a short distance.</p>
</section>
<section id="example-4" class="level5">
<h5 class="anchored" data-anchor-id="example-4">Example</h5>
<p>Sea surface temperature varies with latitude and other factors, such as water depth. The following figure shows average temperatures for January 1982 around Australia. The filled contours allow for an easier identification of the ranges represented.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../differentiable_vector_calculus/figures/australia.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Image from <a href="https://iridl.ldeo.columbia.edu/maproom/Global/Ocean_Temp/Monthly_Temp.html">IRI</a> shows mean sea surface temperature near Australia in January 1982. IRI has zoomable graphs for this measurement from 1981 to the present. The contour lines are in 2 degree Celsius increments.</figcaption><p></p>
</figure>
</div>
</section>
<section id="example-5" class="level5">
<h5 class="anchored" data-anchor-id="example-5">Example</h5>
<p>The filled contour and the heatmap are related figures to a simple contour graph. The heatmap uses a color gradient to indicate the value at <span class="math inline">\((x,y)\)</span>:</p>
<div class="cell" data-hold="true" data-execution_count="34">
<div class="sourceCode cell-code" id="cb39"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb39-1"><a href="#cb39-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> <span class="fu">exp</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 class="op">/</span><span class="fl">5</span>) <span class="op">*</span> <span class="fu">sin</span>(x) <span class="op">*</span> <span class="fu">cos</span>(y)</span>
<span id="cb39-2"><a href="#cb39-2" aria-hidden="true" tabindex="-1"></a>xs<span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="cn">pi</span>, <span class="cn">pi</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
<span id="cb39-3"><a href="#cb39-3" aria-hidden="true" tabindex="-1"></a><span class="fu">heatmap</span>(xs, ys, 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="35">
<p><img src="scalar_functions_files/figure-html/cell-35-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The filled contour layers on the contour lines to a heatmap:</p>
<div class="cell" data-hold="true" data-execution_count="35">
<div class="sourceCode cell-code" id="cb40"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb40-1"><a href="#cb40-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> <span class="fu">exp</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 class="op">/</span><span class="fl">5</span>) <span class="op">*</span> <span class="fu">sin</span>(x) <span class="op">*</span> <span class="fu">cos</span>(y)</span>
<span id="cb40-2"><a href="#cb40-2" aria-hidden="true" tabindex="-1"></a>xs<span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="cn">pi</span>, <span class="cn">pi</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
<span id="cb40-3"><a href="#cb40-3" aria-hidden="true" tabindex="-1"></a><span class="fu">contourf</span>(xs, ys, 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="36">
<p><img src="scalar_functions_files/figure-html/cell-36-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>This function has a prominent peak and a prominent valley, around the middle of the viewing window. The nested contour lines indicate this, and the color key can be used to identify which is the peak and which the valley.</p>
</section>
</section>
</section>
<section id="limits" class="level2" data-number="55.2">
<h2 data-number="55.2" class="anchored" data-anchor-id="limits"><span class="header-section-number">55.2</span> Limits</h2>
<p>The notion of a limit for a univariate function: as <span class="math inline">\(x\)</span> gets close to <span class="math inline">\(c\)</span> then <span class="math inline">\(f(x)\)</span> gets close to <span class="math inline">\(L\)</span>, needs some modification:</p>
<blockquote class="blockquote">
<p>Let <span class="math inline">\(f: R^n \rightarrow R\)</span> and <span class="math inline">\(C\)</span> be a point in <span class="math inline">\(R^n\)</span>. Then <span class="math inline">\(\lim_{P \rightarrow C}f(P) = L\)</span> if for every <span class="math inline">\(\epsilon &gt; 0\)</span> there exists a <span class="math inline">\(\delta &gt; 0\)</span> such that <span class="math inline">\(|f(P) - L| &lt; \epsilon\)</span> whenever <span class="math inline">\(0 &lt; \| P - C \| &lt; \delta\)</span>.</p>
</blockquote>
<p>(If <span class="math inline">\(P=(x_1, x_2, \dots, x_n)\)</span> we use <span class="math inline">\(f(P) = f(x_1, x_2, \dots, x_n)\)</span>.)</p>
<p>This says, informally, for any scale about <span class="math inline">\(L\)</span> there is a “ball” about <span class="math inline">\(C\)</span> (not including <span class="math inline">\(C\)</span>) for which the images of <span class="math inline">\(f\)</span> always sit in the ball. Formally we define a ball of radius <span class="math inline">\(r\)</span> about a point <span class="math inline">\(C\)</span> to be all points <span class="math inline">\(P\)</span> with distance between <span class="math inline">\(P\)</span> and <span class="math inline">\(C\)</span> less than <span class="math inline">\(r\)</span>. A ball is an <em>open</em> set. An <a href="https://en.wikipedia.org/wiki/Open_set#Euclidean_space">open</a> is a set <span class="math inline">\(U\)</span> such that for any <span class="math inline">\(x\)</span> in <span class="math inline">\(U\)</span>, there is a radius <span class="math inline">\(r\)</span> such that the ball of radius <span class="math inline">\(r\)</span> about <span class="math inline">\(x\)</span> is <em>still</em> within <span class="math inline">\(U\)</span>. An open set generalizes an open interval. A <em>closed</em> set generalizes a <em>closed</em> interval. These are <a href="https://en.wikipedia.org/wiki/Closed_set">defined</a> by a set that contains its boundary. Boundary points are any points that can be approached in the limit by points within the set.</p>
<p>In the univariate case, it can be useful to characterize a limit at <span class="math inline">\(x=c\)</span> existing if <em>both</em> the left and right limits exist and the two are equal. Generalizing to getting close in <span class="math inline">\(R^m\)</span> leads to the intuitive idea of a limit existing in terms of any continuous “path” that approaches <span class="math inline">\(C\)</span> in the <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span> plane has a limit and all are equal. Let <span class="math inline">\(\gamma\)</span> describe the path, and <span class="math inline">\(\lim_{s \rightarrow t}\gamma(s) = C\)</span>. Then <span class="math inline">\(f \circ \gamma\)</span> will be a univariate function. If there is a limit, <span class="math inline">\(L\)</span>, then this composition will also have the same limit as <span class="math inline">\(s \rightarrow t\)</span>. Conversely, if for <em>every</em> path this composition has the <em>same</em> limit, then <span class="math inline">\(f\)</span> will have a limit.</p>
<p>The “two path corollary” is a trick to show a limit does not exist - just find two paths where there is a limit, but they differ, then a limit does not exist in general.</p>
<section id="continuity-of-scalar-functions" class="level3" data-number="55.2.1">
<h3 data-number="55.2.1" class="anchored" data-anchor-id="continuity-of-scalar-functions"><span class="header-section-number">55.2.1</span> Continuity of scalar functions</h3>
<p>Continuity is defined in a familiar manner: <span class="math inline">\(f(P)\)</span> is continuous at <span class="math inline">\(C\)</span> if <span class="math inline">\(\lim_{P \rightarrow C} f(P) = f(C)\)</span>, where we interpret <span class="math inline">\(P \rightarrow C\)</span> in the sense of a ball about <span class="math inline">\(C\)</span>.</p>
<p>As with univariate functions continuity will be preserved under function addition, subtraction, multiplication, and division (provided there is no dividing by <span class="math inline">\(0\)</span>). With this, all these functions are continuous everywhere and so have limits everywhere:</p>
<p><span class="math display">\[
f(x,y) = \sin(x + y), \quad
g(x,y,z) = x^2 + y^2 + z^2, \quad
h(w, x,y,z) = \sqrt{w^2 + x^2 + y^2 + z^2}.
\]</span></p>
<p>Not all functions will have a limit though. Consider <span class="math inline">\(f(x,y) = 2x^2/(x^2+y^2)\)</span> and <span class="math inline">\(C=(0,0)\)</span>. It is not defined at <span class="math inline">\(C\)</span> (dividing by <span class="math inline">\(0\)</span>), but may have a limit at <span class="math inline">\(C\)</span>. Consider the path <span class="math inline">\(x=0\)</span> (the <span class="math inline">\(y\)</span>-axis) parameterized by <span class="math inline">\(\vec\gamma(t) = \langle 0, t\rangle\)</span>. Along this path <span class="math inline">\((f\circ \vec\gamma)(t) = 0/t^2 = 0\)</span> so will have a limit of <span class="math inline">\(0\)</span>. If the limit of <span class="math inline">\(f\)</span> exists it must be <span class="math inline">\(0\)</span>. But, along the line <span class="math inline">\(y=0\)</span> (the <span class="math inline">\(x\)</span> axis) parameterized by <span class="math inline">\(\vec{\gamma}(t) = \langle t, 0 \rangle\)</span>, the function simplifies to <span class="math inline">\((f\circ\vec\gamma)(t)=2\)</span>, so would have a limit of <span class="math inline">\(2\)</span>. As the limit along different paths is different, this function has no limit in general.</p>
<section id="example-6" class="level5">
<h5 class="anchored" data-anchor-id="example-6">Example</h5>
<p>If is not enough that a limit exist along many paths to say a limit exists in general. It must be all paths and be equal. An example might be this function:</p>
<p><span class="math display">\[
f(x,y) =
\begin{cases}
(x + y)/(x-y) &amp; x \neq y,\\
0 &amp; x = y
\end{cases}
\]</span></p>
<p>At <span class="math inline">\(\vec{0}\)</span> this will not have a limit. However, along any line <span class="math inline">\(y=mx\)</span> we have a limit. If <span class="math inline">\(m=1\)</span> the function is constantly <span class="math inline">\(0\)</span>, and so has the limit. If <span class="math inline">\(m \neq 1\)</span>, then we get <span class="math inline">\(f(x, y) = f(x, mx) = (1 + m)/(1-m)\)</span>, a constant So for each <span class="math inline">\(m\)</span> there is a different limit. Consequently, the scalar function does not have a limit.</p>
</section>
</section>
</section>
<section id="partial-derivatives-and-the-gradient" class="level2" data-number="55.3">
<h2 data-number="55.3" class="anchored" data-anchor-id="partial-derivatives-and-the-gradient"><span class="header-section-number">55.3</span> Partial derivatives and the gradient</h2>
<p>Discussing the behaviour of a scalar function along a path is described mathematically through composition. If <span class="math inline">\(\vec\gamma(t)\)</span> is a path in <span class="math inline">\(R^n\)</span>, then the composition <span class="math inline">\(f \circ \vec\gamma\)</span> will be a univariate function. When <span class="math inline">\(n=2\)</span>, we can visualize this composition directly, or as a <span class="math inline">\(3\)</span>-D path on the surface given by <span class="math inline">\(\vec{r}(t) = \langle \gamma_1(t), \gamma_2(t), \dots, \gamma_n(t), (f \circ \vec\gamma)(t) \rangle\)</span>.</p>
<div class="cell" data-execution_count="36">
<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">f₁</span>(x,y) <span class="op">=</span> <span class="fl">2</span> <span class="op">-</span> x<span class="op">^</span><span class="fl">2</span> <span class="op">-</span> <span class="fl">3</span>y<span class="op">^</span><span class="fl">2</span></span>
<span id="cb41-2"><a href="#cb41-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f₁</span>(x) <span class="op">=</span> <span class="fu">f₁</span>(x<span class="op">...</span>)</span>
<span id="cb41-3"><a href="#cb41-3" aria-hidden="true" tabindex="-1"></a><span class="fu">γ₁</span>(t) <span class="op">=</span> <span class="fl">2</span> <span class="op">*</span> [t, <span class="op">-</span>t<span class="op">^</span><span class="fl">2</span>] <span class="co"># use \gamma[tab]</span></span>
<span id="cb41-4"><a href="#cb41-4" aria-hidden="true" tabindex="-1"></a>x₁s <span class="op">=</span> y₁s <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">1</span>, <span class="fl">1</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
<span id="cb41-5"><a href="#cb41-5" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(x₁s, y₁s, f₁)</span>
<span id="cb41-6"><a href="#cb41-6" aria-hidden="true" tabindex="-1"></a><span class="fu">r3₁</span>(t) <span class="op">=</span> [<span class="fu">γ₁</span>(t)<span class="op">...</span>, <span class="fu">f₁</span>(<span class="fu">γ₁</span>(t))] <span class="co"># to plot the path on the surface</span></span>
<span id="cb41-7"><a href="#cb41-7" aria-hidden="true" tabindex="-1"></a><span class="fu">plot_parametric!</span>(<span class="fl">0</span><span class="op">..</span><span class="fl">1</span><span class="op">/</span><span class="fl">2</span>, r3₁, linewidth<span class="op">=</span><span class="fl">5</span>, color<span class="op">=:</span>black)</span>
<span id="cb41-8"><a href="#cb41-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb41-9"><a href="#cb41-9" aria-hidden="true" tabindex="-1"></a><span class="fu">r2₁</span>(t) <span class="op">=</span> [<span class="fu">γ₁</span>(t)<span class="op">...</span>, <span class="fl">0</span>]</span>
<span id="cb41-10"><a href="#cb41-10" aria-hidden="true" tabindex="-1"></a><span class="fu">plot_parametric!</span>(<span class="fl">0</span><span class="op">..</span><span class="fl">1</span><span class="op">/</span><span class="fl">2</span>, r2₁, linewidth<span class="op">=</span><span class="fl">5</span>, color<span class="op">=:</span>black) <span class="co"># in the $x$-$y$ plane</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="37">
<p><img src="scalar_functions_files/figure-html/cell-37-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The vector valued function <code>r3(t) = [γ(t)..., f(γ(t))]</code> takes the <span class="math inline">\(2\)</span>-dimensional path specified by <span class="math inline">\(\vec\gamma(t)\)</span> and adds a third, <span class="math inline">\(x\)</span>, direction by composing the position with <code>f</code>. In this way, a <span class="math inline">\(2\)</span>-D path is visualized with a <span class="math inline">\(3\)</span>-D path. This viewpoint can be reversed, as desired.</p>
<p>However, the composition, <span class="math inline">\(f\circ\vec\gamma\)</span>, is a univariate function, so this can also be visualized by</p>
<div class="cell" data-execution_count="37">
<div class="sourceCode cell-code" id="cb42"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb42-1"><a href="#cb42-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(f₁ <span class="op"></span> γ₁, <span class="fl">0</span>, <span class="fl">1</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="38">
<p><img src="scalar_functions_files/figure-html/cell-38-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>With this graph, we might be led to ask about derivatives or rates of change. For this example, we can algebraically compute the composition:</p>
<p><span class="math display">\[
(f \circ \vec\gamma)(t) = 2 - (2t) - 3(-2t^2)^2 = 2 - 2t +12t^4
\]</span></p>
<p>From here we clearly have <span class="math inline">\(f'(t) = -2 + 48t^3\)</span>. But could this be computed in terms of a “derivative” of <span class="math inline">\(f\)</span> and the derivative of <span class="math inline">\(\vec\gamma\)</span>?</p>
<p>Before answering this, we discuss <em>directional</em> derivatives along the simplified paths <span class="math inline">\(\vec\gamma_x(t) = \langle t, c\rangle\)</span> or <span class="math inline">\(\vec\gamma_y(t) = \langle c, t\rangle\)</span>.</p>
<p>If we compose <span class="math inline">\(f \circ \vec\gamma_x\)</span>, we can visualize this as a curve on the surface from <span class="math inline">\(f\)</span> that moves in the <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span> plane along the line <span class="math inline">\(y=c\)</span>. The derivative of this curve will satisfy:</p>
<p><span class="math display">\[
\begin{align}
(f \circ \vec\gamma_x)'(x) &amp;=
\lim_{t \rightarrow x} \frac{(f\circ\vec\gamma_x)(t) - (f\circ\vec\gamma_x)(x)}{t-x}\\
&amp;= \lim_{t\rightarrow x} \frac{f(t, c) - f(x,c)}{t-x}\\
&amp;= \lim_{h \rightarrow 0} \frac{f(x+h, c) - f(x, c)}{h}.
\end{align}
\]</span></p>
<p>The latter expresses this to be the derivative of the function that holds the <span class="math inline">\(y\)</span> value fixed, but lets the <span class="math inline">\(x\)</span> value vary. It is the rate of change in the <span class="math inline">\(x\)</span> direction. There is special notation for this:</p>
<p><span class="math display">\[
\begin{align}
\frac{\partial f(x,y)}{\partial x} &amp;=
\lim_{h \rightarrow 0} \frac{f(x+h, y) - f(x, y)}{h},\quad\text{and analogously}\\
\frac{\partial f(x,y)}{\partial y} &amp;=
\lim_{h \rightarrow 0} \frac{f(x, y+h) - f(x, y)}{h}.
\end{align}
\]</span></p>
<p>These are called the <em>partial</em> derivatives of <span class="math inline">\(f\)</span>. The symbol <span class="math inline">\(\partial\)</span>, read as “partial”, is reminiscent of “<span class="math inline">\(d\)</span>”, but indicates the derivative is only in a given direction. Other notations exist for this:</p>
<p><span class="math display">\[
\frac{\partial f}{\partial x}, \quad f_x, \quad \partial_x f,
\]</span></p>
<p>and more generally, when <span class="math inline">\(n\)</span> may be <span class="math inline">\(2\)</span> or more,</p>
<p><span class="math display">\[
\frac{\partial f}{\partial x_i}, \quad f_{x_i}, \quad f_i, \quad \partial_{x_i} f, \quad \partial_i f.
\]</span></p>
<p>The <em>gradient</em> of a scalar function <span class="math inline">\(f\)</span> is the vector comprised of the partial derivatives:</p>
<p><span class="math display">\[
\nabla f(x_1, x_2, \dots, x_n) = \langle
\frac{\partial f}{\partial x_1},
\frac{\partial f}{\partial x_2}, \dots,
\frac{\partial f}{\partial x_n} \rangle.
\]</span></p>
<p>As seen, the gradient is a vector-valued function, but has, also, multivariable inputs. It is a function from <span class="math inline">\(R^n \rightarrow R^n\)</span>.</p>
<section id="example-7" class="level5">
<h5 class="anchored" data-anchor-id="example-7">Example</h5>
<p>Let <span class="math inline">\(f(x,y) = x^2 - 2xy\)</span>, then to compute the partials, we just treat the other variables like a constant. (This is consistent with the view that the partial derivative is just a regular derivative along a line where all other variables are constant.)</p>
<p>Then</p>
<p><span class="math display">\[
\begin{align}
\frac{\partial (x^2 - 2xy)}{\partial x} &amp;= 2x - 2y\\
\frac{\partial (x^2 - 2xy)}{\partial y} &amp;= 0 - 2x = -2x.
\end{align}
\]</span></p>
<p>Combining, gives <span class="math inline">\(\nabla{f} = \langle 2x -2y, -2x \rangle\)</span>.</p>
<p>If <span class="math inline">\(g(x,y,z) = \sin(x) + z\cos(y)\)</span>, then</p>
<p><span class="math display">\[
\begin{align}
\frac{\partial g }{\partial x} &amp;= \cos(x) + 0 = \cos(x),\\
\frac{\partial g }{\partial y} &amp;= 0 + z(-\sin(y)) = -z\sin(y),\\
\frac{\partial g }{\partial z} &amp;= 0 + \cos(y) = \cos(y).
\end{align}
\]</span></p>
<p>Combining, gives <span class="math inline">\(\nabla{g} = \langle \cos(x), -z\sin(y), \cos(y) \rangle\)</span>.</p>
</section>
<section id="finding-partial-derivatives-in-julia" class="level3" data-number="55.3.1">
<h3 data-number="55.3.1" class="anchored" data-anchor-id="finding-partial-derivatives-in-julia"><span class="header-section-number">55.3.1</span> Finding partial derivatives in Julia</h3>
<p>Two different methods are described, one for working with functions, the other symbolic expressions. This mirrors our treatment for vector-valued functions, where <code>ForwardDiff.derivative</code> was used for functions, and <code>SymPy</code>s <code>diff</code> function for symbolic expressions.</p>
<p>Suppose, we consider <span class="math inline">\(f(x,y) = x^2 - 2xy\)</span>. We may define it with <code>Julia</code> through:</p>
<div class="cell" data-execution_count="38">
<div class="sourceCode cell-code" id="cb43"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb43-1"><a href="#cb43-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> <span class="fl">2</span>x<span class="op">*</span>y</span>
<span id="cb43-2"><a href="#cb43-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f₂</span>(v) <span class="op">=</span> <span class="fu">f₂</span>(v<span class="op">...</span>) <span class="co"># to handle vectors. Need not be defined each time</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>f₂ (generic function with 2 methods)</code></pre>
</div>
</div>
<p>The numeric gradient at a point, can be found from the function <code>ForwardDiff.gradient</code> through:</p>
<div class="cell" data-execution_count="39">
<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>pt₂ <span class="op">=</span> [<span class="fl">1</span>, <span class="fl">2</span>]</span>
<span id="cb45-2"><a href="#cb45-2" aria-hidden="true" tabindex="-1"></a>ForwardDiff.<span class="fu">gradient</span>(f₂, pt₂) <span class="co"># uses the f(v) call above</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">
<pre><code>2-element Vector{Int64}:
-2
-2</code></pre>
</div>
</div>
<p>This, of course matches the computation above, where <span class="math inline">\(\nabla f = \langle (2x -2y, -2x)\)</span>, so at <span class="math inline">\((1,2)\)</span> is <span class="math inline">\((-2, 2)\)</span>, as a point in <span class="math inline">\(R^2\)</span>.</p>
<p>The <code>ForwardDiff.gradient</code> function expects a function that accepts a vector of values, so the method for <code>f(v)</code> is needed for the computation.</p>
<p>To go from a function that takes a point to a function of that point, we have the following definition. This takes advantage of <code>Julia</code>s multiple dispatch to add a new method for the <code>gradient</code> generic. This is done in the <code>CalculusWithJulia</code> package along the lines of:</p>
<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>FowardDiff.<span class="fu">gradient</span>(f<span class="op">::</span><span class="dt">Function</span>) <span class="op">=</span> x <span class="op">-&gt;</span> ForwardDiff.<span class="fu">gradient</span>(f, x)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>It works as follows, where a vector of values is passed in for the point in question:</p>
<div class="cell" data-execution_count="41">
<div class="sourceCode cell-code" id="cb48"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb48-1"><a href="#cb48-1" aria-hidden="true" tabindex="-1"></a><span class="fu">gradient</span>(f₂)([<span class="fl">1</span>,<span class="fl">2</span>]), <span class="fu">gradient</span>(f₂)([<span class="fl">3</span>,<span class="fl">4</span>])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="41">
<pre><code>([-2, -2], [-2, -6])</code></pre>
</div>
</div>
<p>This expects a point or vector for its argument, and not the expanded values. Were that desired, something like this would work:</p>
<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>ForwardDiff.<span class="fu">gradient</span>(f<span class="op">::</span><span class="dt">Function</span>) <span class="op">=</span> (x, xs<span class="op">...</span>) <span class="op">-&gt;</span> ForwardDiff.<span class="fu">gradient</span>(f, <span class="fu">vcat</span>(x, xs<span class="op">...</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell" data-execution_count="43">
<div class="sourceCode cell-code" id="cb51"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb51-1"><a href="#cb51-1" aria-hidden="true" tabindex="-1"></a><span class="fu">gradient</span>(f₂)([<span class="fl">1</span>,<span class="fl">2</span>]), <span class="fu">gradient</span>(f₂)(<span class="fl">3</span>,<span class="fl">4</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="42">
<pre><code>([-2, -2], [-2, -6])</code></pre>
</div>
</div>
<p>From the gradient, finding the partial derivatives involves extraction of the corresponding component.</p>
<p>For example, were it desirable, this function could be used to find the partial in <span class="math inline">\(x\)</span> for some constant <span class="math inline">\(y\)</span>:</p>
<div class="cell" data-execution_count="44">
<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">partial_x</span>(f, y) <span class="op">=</span> x <span class="op">-&gt;</span> ForwardDiff.<span class="fu">gradient</span>(f,[x,y])[<span class="fl">1</span>] <span class="co"># first component of gradient</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="43">
<pre><code>partial_x (generic function with 1 method)</code></pre>
</div>
</div>
<p>Another alternative would be to hold one variable constant, and use the <code>derivative</code> function, as in:</p>
<div class="cell" data-hold="true" data-execution_count="45">
<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><span class="fu">partial_x</span>(f, y) <span class="op">=</span> x <span class="op">-&gt;</span> ForwardDiff.<span class="fu">derivative</span>(u <span class="op">-&gt;</span> <span class="fu">f</span>(u,y), 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="44">
<pre><code>partial_x (generic function with 1 method)</code></pre>
</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>For vector-valued functions, we can overide the syntax <code>'</code> using <code>Base.adjoint</code>, as <code>'</code> is treated as a postfix operator in <code>Julia</code> for the <code>adjoint</code> operation. The symbol <code>\\nabla</code> is also available in <code>Julia</code>, but it is not an operator, so cant be used as mathematically written <code>∇f</code> (this could be used as a name though). In <code>CalculusWithJulia</code> a definition is made so essentially <code>∇(f) = x -&gt; ForwardDiff.gradient(f, x)</code>. It does require parentheses to be called, as in <code>∇(f)</code>.</p>
</div>
</div>
<section id="symbolic-expressions" class="level4">
<h4 class="anchored" data-anchor-id="symbolic-expressions">Symbolic expressions</h4>
<p>The partial derivatives are more directly found with <code>SymPy</code>. As with univariate functions, the <code>diff</code> function is used by simply passing in the variable in which to find the partial derivative:</p>
<div class="cell" data-execution_count="46">
<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="pp">@syms</span> x y</span>
<span id="cb57-2"><a href="#cb57-2" aria-hidden="true" tabindex="-1"></a>ex <span class="op">=</span> x<span class="op">^</span><span class="fl">2</span> <span class="op">-</span> <span class="fl">2</span>x<span class="op">*</span>y</span>
<span id="cb57-3"><a href="#cb57-3" aria-hidden="true" tabindex="-1"></a><span class="fu">diff</span>(ex, x)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="45">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
2 x - 2 y
\]
</span>
</div>
</div>
<p>And evaluation:</p>
<div class="cell" data-execution_count="47">
<div class="sourceCode cell-code" id="cb58"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb58-1"><a href="#cb58-1" aria-hidden="true" tabindex="-1"></a><span class="fu">diff</span>(ex,x)(x<span class="op">=&gt;</span><span class="fl">1</span>, y<span class="op">=&gt;</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="46">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
-2
\]
</span>
</div>
</div>
<p>Or</p>
<div class="cell" data-execution_count="48">
<div class="sourceCode cell-code" id="cb59"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb59-1"><a href="#cb59-1" aria-hidden="true" tabindex="-1"></a><span class="fu">diff</span>(ex, y)(x<span class="op">=&gt;</span><span class="fl">1</span>, y<span class="op">=&gt;</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="47">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
-2
\]
</span>
</div>
</div>
<p>The gradient would be found by combining the two:</p>
<div class="cell" data-execution_count="49">
<div class="sourceCode cell-code" id="cb60"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb60-1"><a href="#cb60-1" aria-hidden="true" tabindex="-1"></a>[<span class="fu">diff</span>(ex, x), <span class="fu">diff</span>(ex, 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="48">
<pre><code>2-element Vector{Sym}:
2⋅x - 2⋅y
-2⋅x</code></pre>
</div>
</div>
<p>This can be simplified through broadcasting:</p>
<div class="cell" data-execution_count="50">
<div class="sourceCode cell-code" id="cb62"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb62-1"><a href="#cb62-1" aria-hidden="true" tabindex="-1"></a>grad_ex <span class="op">=</span> <span class="fu">diff</span>.(ex, [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="49">
<pre><code>2-element Vector{Sym}:
2⋅x - 2⋅y
-2⋅x</code></pre>
</div>
</div>
<p>To evaluate at a point we have:</p>
<div class="cell" data-execution_count="51">
<div class="sourceCode cell-code" id="cb64"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb64-1"><a href="#cb64-1" aria-hidden="true" tabindex="-1"></a><span class="fu">subs</span>.(grad_ex, x<span class="op">=&gt;</span><span class="fl">1</span>, y<span class="op">=&gt;</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="50">
<pre><code>2-element Vector{Sym}:
-2
-2</code></pre>
</div>
</div>
<p>The above relies on broadcasting treating the pair as a single value so the substitution is repeated for each entry of <code>grad_ex</code>.</p>
<p>The <code>gradient</code> function from <code>CalculusWithJulia</code> is defined to find the symbolic gradient. It uses <code>free_symbols</code> to specify the number and order of the variables, but that may be wrong; they are specified below:</p>
<div class="cell" data-execution_count="52">
<div class="sourceCode cell-code" id="cb66"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb66-1"><a href="#cb66-1" aria-hidden="true" tabindex="-1"></a><span class="fu">gradient</span>(ex, [x, y]) <span class="co"># [∂f/∂x, ∂f/∂y]</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="51">
<pre><code>2-element Vector{Sym}:
2⋅x - 2⋅y
-2⋅x</code></pre>
</div>
</div>
<p>To use <code></code> and specify the variables, a tuple (grouping parentheses) is used:</p>
<div class="cell" data-execution_count="53">
<div class="sourceCode cell-code" id="cb68"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb68-1"><a href="#cb68-1" aria-hidden="true" tabindex="-1"></a><span class="fu"></span>((ex, [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="52">
<pre><code>2-element Vector{Sym}:
2⋅x - 2⋅y
-2⋅x</code></pre>
</div>
</div>
<hr>
<p>In computer science there are two related concepts <a href="https://en.wikipedia.org/wiki/Currying">Currying</a> and <a href="https://en.wikipedia.org/wiki/Partial_application">Partial application</a>. For a function <span class="math inline">\(f(x,y)\)</span>, say, partial application is the process of fixing one of the variables, producing a new function of fewer variables. For example, fixing <span class="math inline">\(y=c\)</span>, the we get a new function (of just <span class="math inline">\(x\)</span> and not <span class="math inline">\((x,y)\)</span>) <span class="math inline">\(g(x) = f(x,c)\)</span>. In partial derivatives the partial derivative of <span class="math inline">\(f(x,y)\)</span> with respect to <span class="math inline">\(x\)</span> is the derivative of the function <span class="math inline">\(g\)</span>, as defined above.</p>
<p>Currying, is related, but technically returns a function, so we think of the curried version of <span class="math inline">\(f\)</span> as a function, <span class="math inline">\(h\)</span>, which takes <span class="math inline">\(x\)</span> and returns the function <span class="math inline">\(y \rightarrow f(x,y)\)</span> so that <span class="math inline">\(h(x)(y) = f(x, y)\)</span>.</p>
</section>
</section>
<section id="visualizing-the-gradient" class="level3" data-number="55.3.2">
<h3 data-number="55.3.2" class="anchored" data-anchor-id="visualizing-the-gradient"><span class="header-section-number">55.3.2</span> Visualizing the gradient</h3>
<p>The gradient is not a univariate function, a simple vector-valued function, or a scalar function, but rather a <em>vector field</em> (which will be discussed later). For the case, <span class="math inline">\(f: R^2 \rightarrow R\)</span>, the gradient will be a function which takes a point <span class="math inline">\((x,y)\)</span> and returns a vector , <span class="math inline">\(\langle \partial{f}/\partial{x}(x,y), \partial{f}/\partial{y}(x,y) \rangle\)</span>. We can visualize this by plotting a vector at several points on a grid. This task is made easier with a function like the following, which handles the task of vectorizing the values. It is provided within the <code>CalculusWithJulia</code> package:</p>
<div class="sourceCode cell-code" id="cb70"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb70-1"><a href="#cb70-1" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span> <span class="fu">vectorfieldplot!</span>(V; xlim<span class="op">=</span>(<span class="op">-</span><span class="fl">5</span>,<span class="fl">5</span>), ylim<span class="op">=</span>(<span class="op">-</span><span class="fl">5</span>,<span class="fl">5</span>), nx<span class="op">=</span><span class="fl">10</span>, ny<span class="op">=</span><span class="fl">10</span>, kwargs<span class="op">...</span>)</span>
<span id="cb70-2"><a href="#cb70-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb70-3"><a href="#cb70-3" aria-hidden="true" tabindex="-1"></a> dx, dy <span class="op">=</span> (xlim[<span class="fl">2</span>]<span class="op">-</span>xlim[<span class="fl">1</span>])<span class="op">/</span>nx, (ylim[<span class="fl">2</span>]<span class="op">-</span>ylim[<span class="fl">1</span>])<span class="op">/</span>ny</span>
<span id="cb70-4"><a href="#cb70-4" aria-hidden="true" tabindex="-1"></a> xs, ys <span class="op">=</span> xlim[<span class="fl">1</span>]<span class="op">:</span>dx<span class="op">:</span>xlim[<span class="fl">2</span>], ylim[<span class="fl">1</span>]<span class="op">:</span>dy<span class="op">:</span>ylim[<span class="fl">2</span>]</span>
<span id="cb70-5"><a href="#cb70-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb70-6"><a href="#cb70-6" aria-hidden="true" tabindex="-1"></a> ps <span class="op">=</span> [[x,y] for x <span class="kw">in</span> xs for y <span class="kw">in</span> ys]</span>
<span id="cb70-7"><a href="#cb70-7" aria-hidden="true" tabindex="-1"></a> vs <span class="op">=</span> <span class="fu">V</span>.(ps)</span>
<span id="cb70-8"><a href="#cb70-8" aria-hidden="true" tabindex="-1"></a> λ <span class="op">=</span> <span class="fl">0.9</span> <span class="op">*</span> <span class="fu">minimum</span>([u<span class="op">/</span><span class="fu">maximum</span>(<span class="fu">getindex</span>.(vs,i)) for (i,u) <span class="kw">in</span> <span class="fu">enumerate</span>((dx,dy))])</span>
<span id="cb70-9"><a href="#cb70-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb70-10"><a href="#cb70-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">quiver!</span>(<span class="fu">unzip</span>(ps)<span class="op">...</span>, quiver<span class="op">=</span><span class="fu">unzip</span><span class="op">*</span> vs))</span>
<span id="cb70-11"><a href="#cb70-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb70-12"><a href="#cb70-12" 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>
<p>Here we show the gradient for the scalar function <span class="math inline">\(f(x,y) = 2 - x^2 - 3y^2\)</span> over the region <span class="math inline">\([-2, 2]\times[-2,2]\)</span> along with a contour plot:</p>
<div class="cell" data-hold="true" data-execution_count="55">
<div class="sourceCode cell-code" id="cb71"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb71-1"><a href="#cb71-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> <span class="fl">2</span> <span class="op">-</span> x<span class="op">^</span><span class="fl">2</span> <span class="op">-</span> <span class="fl">3</span>y<span class="op">^</span><span class="fl">2</span></span>
<span id="cb71-2"><a href="#cb71-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(v) <span class="op">=</span> <span class="fu">f</span>(v<span class="op">...</span>)</span>
<span id="cb71-3"><a href="#cb71-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb71-4"><a href="#cb71-4" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">2</span>,<span class="fl">2</span>, length<span class="op">=</span><span class="fl">50</span>)</span>
<span id="cb71-5"><a href="#cb71-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb71-6"><a href="#cb71-6" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> <span class="fu">contour</span>(xs, ys, f, nlevels<span class="op">=</span><span class="fl">12</span>)</span>
<span id="cb71-7"><a href="#cb71-7" aria-hidden="true" tabindex="-1"></a><span class="fu">vectorfieldplot!</span>(p, <span class="fu">gradient</span>(f), xlim<span class="op">=</span>(<span class="op">-</span><span class="fl">2</span>,<span class="fl">2</span>), ylim<span class="op">=</span>(<span class="op">-</span><span class="fl">2</span>,<span class="fl">2</span>), nx<span class="op">=</span><span class="fl">10</span>, ny<span class="op">=</span><span class="fl">10</span>)</span>
<span id="cb71-8"><a href="#cb71-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb71-9"><a href="#cb71-9" aria-hidden="true" tabindex="-1"></a>p</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="53">
<p><img src="scalar_functions_files/figure-html/cell-56-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The figure suggests a potential geometric relationship between the gradient and the contour line to be explored later.</p>
</section>
</section>
<section id="differentiable" class="level2" data-number="55.4">
<h2 data-number="55.4" class="anchored" data-anchor-id="differentiable"><span class="header-section-number">55.4</span> Differentiable</h2>
<p>We see here how the gradient of <span class="math inline">\(f\)</span>, <span class="math inline">\(\nabla{f} = \langle f_{x_1}, f_{x_2}, \dots, f_{x_n} \rangle\)</span>, plays a similar role as the derivative does for univariate functions.</p>
<p>First, we consider the role of the derivative for univariate functions. The main characterization - the derivative is the slope of the line that best approximates the function at a point - is quantified by Taylors theorem. For a function <span class="math inline">\(f\)</span> with a continuous second derivative:</p>
<p><span class="math display">\[
f(c+h) = f(c) = f'(c)h + \frac{1}{2} f''(\xi) h^2,
\]</span></p>
<p>for some <span class="math inline">\(\xi\)</span> within <span class="math inline">\(c\)</span> and <span class="math inline">\(c+h\)</span>.</p>
<p>We re-express this through:</p>
<p><span class="math display">\[
(f(c+h) - f(c)) - f'(c)h =\frac{1}{2} f''(\xi) h^2.
\]</span></p>
<p>The right hand side is the <em>error</em> term between the function value at <span class="math inline">\(c+h\)</span> and, in this case, the linear approximation at the same value.</p>
<p>If the assumptions are relaxed, and <span class="math inline">\(f\)</span> is just assumed to be <em>differentiable</em> at <span class="math inline">\(x=c\)</span>, then only this is known:</p>
<p><span class="math display">\[
(f(c+h) - f(c)) - f'(c)h = \epsilon(h) h,
\]</span></p>
<p>where <span class="math inline">\(\epsilon(h) \rightarrow 0\)</span> as <span class="math inline">\(h \rightarrow 0\)</span>.</p>
<p>It is this characterization of differentiable that is generalized to define when a scalar function is <em>differentiable</em>.</p>
<blockquote class="blockquote">
<p><em>Differentiable</em>: Let <span class="math inline">\(f\)</span> be a scalar function. Then <span class="math inline">\(f\)</span> is <a href="https://tinyurl.com/qj8qcbb">differentiable</a> at a point <span class="math inline">\(C\)</span> <strong>if</strong> the first order partial derivatives exist at <span class="math inline">\(C\)</span> <strong>and</strong> for <span class="math inline">\(\vec{h}\)</span> going to <span class="math inline">\(\vec{0}\)</span>:</p>
<p><span class="math inline">\(\|f(C + \vec{h}) - f(C) - \nabla{f}(C) \cdot \vec{h}\| = \mathcal{o}(\|\vec{h}\|),\)</span></p>
<p>where <span class="math inline">\(\mathcal{o}(\|\vec{h}\|)\)</span> means that dividing the left hand side by <span class="math inline">\(\|\vec{h}\|\)</span> and taking a limit as <span class="math inline">\(\vec{h}\rightarrow 0\)</span> the limit will be <span class="math inline">\(0\)</span>..</p>
</blockquote>
<p>The limits here are for limits of scalar functions, which means along any path going to <span class="math inline">\(\vec{0}\)</span>, not just straight line paths, as are used to define the partial derivatives. Hidden above, is an assumption that there is some open set around <span class="math inline">\(C\)</span> for which <span class="math inline">\(f\)</span> is defined for <span class="math inline">\(f(C + \vec{h})\)</span> when <span class="math inline">\(C+\vec{h}\)</span> is in this open set.</p>
<p>The role of the derivative in the univariate case is played by the gradient in the scalar case, where <span class="math inline">\(f'(c)h\)</span> is replaced by <span class="math inline">\(\nabla{f}(C) \cdot \vec{h}\)</span>. For the univariate case, differentiable is simply the derivative existing, but saying a scalar function is differentiable at <span class="math inline">\(C\)</span> is a stronger statement than saying it has a gradient or, equivalently, it has partial derivatives at <span class="math inline">\(C\)</span>, as this is assumed in the statement along with the other condition.</p>
<p>Later we will see how Taylors theorem generalizes for scalar functions and interpret the gradient geometrically, as was done for the derivative (it being the slope of the tangent line).</p>
</section>
<section id="the-chain-rule-to-evaluate-fcircvecgamma" class="level2" data-number="55.5">
<h2 data-number="55.5" class="anchored" data-anchor-id="the-chain-rule-to-evaluate-fcircvecgamma"><span class="header-section-number">55.5</span> The chain rule to evaluate <span class="math inline">\(f\circ\vec\gamma\)</span></h2>
<p>In finding a partial derivative, we restricted the surface along a curve in the <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span> plane, in this case the curve <span class="math inline">\(\vec{\gamma}(t)=\langle t, c\rangle\)</span>. In general if we have a curve in the <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span> plane, <span class="math inline">\(\vec{\gamma}(t)\)</span>, we can compose the scalar function <span class="math inline">\(f\)</span> with <span class="math inline">\(\vec{\gamma}\)</span> to create a univariate function. If the functions are “smooth” then this composed function should have a derivative, and some version of a “chain rule” should provide a means to compute the derivative in terms of the “derivative” of <span class="math inline">\(f\)</span> (the gradient) and the derivative of <span class="math inline">\(\vec{\gamma}\)</span> (<span class="math inline">\(\vec{\gamma}'\)</span>).</p>
<blockquote class="blockquote">
<p><em>Chain rule</em>: Suppose <span class="math inline">\(f\)</span> is <em>differentiable</em> at <span class="math inline">\(C\)</span>, and <span class="math inline">\(\vec{\gamma}(t)\)</span> is differentiable at <span class="math inline">\(c\)</span> with <span class="math inline">\(\vec{\gamma}(c) = C\)</span>. Then <span class="math inline">\(f\circ\vec{\gamma}\)</span> is differentiable at <span class="math inline">\(c\)</span> with derivative <span class="math inline">\(\nabla f(\vec{\gamma}(c)) \cdot \vec{\gamma}'(c)\)</span>.</p>
</blockquote>
<p>This is similar to the chain rule for univariate functions <span class="math inline">\((f\circ g)'(u) = f'(g(u)) g'(u)\)</span> or <span class="math inline">\(df/dx = df/du \cdot du/dx\)</span>. However, when we write out in components there are more terms. For example, for <span class="math inline">\(n=2\)</span> we have with <span class="math inline">\(\vec{\gamma} = \langle x(t), y(t) \rangle\)</span>:</p>
<p><span class="math display">\[
\frac{d(f\circ\vec{\gamma})}{dt} =
\frac{\partial f}{\partial x} \frac{dx}{dt} +
\frac{\partial f}{\partial y} \frac{dy}{dt}.
\]</span></p>
<p>The proof is a consequence of the definition of differentiability and will be shown in more generality later.</p>
<section id="example-8" class="level5">
<h5 class="anchored" data-anchor-id="example-8">Example</h5>
<p>Consider the function <span class="math inline">\(f(x,y) = 2 - x^2 - y^2\)</span> and the curve <span class="math inline">\(\vec\gamma(t) = t\langle \cos(t), -\sin(t) \rangle\)</span> at <span class="math inline">\(t=\pi/6\)</span>. We visualize this below:</p>
<div class="cell" data-execution_count="56">
<div class="sourceCode cell-code" id="cb72"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb72-1"><a href="#cb72-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f₃</span>(x,y) <span class="op">=</span> <span class="fl">2</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>
<span id="cb72-2"><a href="#cb72-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f₃</span>(x) <span class="op">=</span> <span class="fu">f₃</span>(x<span class="op">...</span>)</span>
<span id="cb72-3"><a href="#cb72-3" aria-hidden="true" tabindex="-1"></a><span class="fu">γ₃</span>(t) <span class="op">=</span> t<span class="op">*</span>[<span class="fu">cos</span>(t), <span class="fu">-sin</span>(t)]</span>
<span id="cb72-4"><a href="#cb72-4" aria-hidden="true" tabindex="-1"></a>t0₃ <span class="op">=</span> <span class="cn">pi</span><span class="op">/</span><span class="fl">6</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="54">
<pre><code>0.5235987755982988</code></pre>
</div>
</div>
<div class="cell" data-hold="true" data-execution_count="57">
<div class="sourceCode cell-code" id="cb74"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb74-1"><a href="#cb74-1" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">3</span><span class="op">/</span><span class="fl">2</span>, <span class="fl">3</span><span class="op">/</span><span class="fl">2</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
<span id="cb74-2"><a href="#cb74-2" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, f₃, legend<span class="op">=</span><span class="cn">false</span>)</span>
<span id="cb74-3"><a href="#cb74-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb74-4"><a href="#cb74-4" aria-hidden="true" tabindex="-1"></a><span class="fu">r</span>(t) <span class="op">=</span> [<span class="fu">γ₃</span>(t)<span class="op">...</span>, (f₃<span class="op"></span>γ₃)(t)]</span>
<span id="cb74-5"><a href="#cb74-5" aria-hidden="true" tabindex="-1"></a><span class="fu">plot_parametric!</span>(<span class="fl">0</span><span class="op">..</span><span class="fl">1</span><span class="op">/</span><span class="fl">2</span>, r, linewidth<span class="op">=</span><span class="fl">5</span>, color<span class="op">=:</span>black)</span>
<span id="cb74-6"><a href="#cb74-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb74-7"><a href="#cb74-7" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(<span class="fu">r</span>(t0₃), r<span class="op">'</span>(t0₃), linewidth<span class="op">=</span><span class="fl">5</span>, color<span class="op">=:</span>black)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="55">
<p><img src="scalar_functions_files/figure-html/cell-58-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>In three dimensions, the tangent line is seen, but the univariate function <span class="math inline">\(f \circ \vec\gamma\)</span> looks like:</p>
<div class="cell" data-hold="true" data-execution_count="58">
<div class="sourceCode cell-code" id="cb75"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb75-1"><a href="#cb75-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(f₃ <span class="op"></span> γ₃, <span class="fl">0</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>)</span>
<span id="cb75-2"><a href="#cb75-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(t <span class="op">-&gt;</span> (f₃ <span class="op"></span> γ₃)(t0₃) <span class="op">+</span> (f₃ <span class="op"></span> γ₃)<span class="ch">'(t0₃)*(t - t0₃), 0, pi/2)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="56">
<p><img src="scalar_functions_files/figure-html/cell-59-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>From the graph, the slope of the tangent line looks to be about <span class="math inline">\(-1\)</span>, using the chain rule gives the exact value:</p>
<div class="cell" data-execution_count="59">
<div class="sourceCode cell-code" id="cb76"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb76-1"><a href="#cb76-1" aria-hidden="true" tabindex="-1"></a>ForwardDiff.<span class="fu">gradient</span>(f₃, <span class="fu">γ₃</span>(t0₃)) <span class="op"></span> γ₃<span class="ch">'(t0₃)</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="57">
<pre><code>-1.0471975511965976</code></pre>
</div>
</div>
<p>We can compare this to taking the derivative after composition:</p>
<div class="cell" data-execution_count="60">
<div class="sourceCode cell-code" id="cb78"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb78-1"><a href="#cb78-1" aria-hidden="true" tabindex="-1"></a>(f₃ <span class="op"></span> γ₃)<span class="ch">'(t0₃)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="58">
<pre><code>-1.0471975511965976</code></pre>
</div>
</div>
</section>
<section id="example-9" class="level5">
<h5 class="anchored" data-anchor-id="example-9">Example</h5>
<p>Consider the following plot showing a hiking trail on a surface:</p>
<div class="cell" data-hold="true" data-execution_count="62">
<div class="cell-output cell-output-display" data-execution_count="60">
<p><img src="scalar_functions_files/figure-html/cell-63-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Though here it is hard to see the trail rendered on the surface, for the hiker, such questions are far from the mind. Rather, questions such as what is the steepest part of the trail may come to mind.</p>
<p>For this question, we can answer it in turns of the sampled data in the <code>lenape</code> variable. The steepness being the change in elevation with respect to distance in the <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span> direction. Treating latitude and longitude coordinates describing motion in a plane (as opposed to a very big sphere), we can compute the maximum steepness:</p>
<div class="cell" data-hold="true" data-execution_count="63">
<div class="sourceCode cell-code" id="cb80"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb80-1"><a href="#cb80-1" aria-hidden="true" tabindex="-1"></a>xs, ys, zs <span class="op">=</span> lenape.longitude, lenape.latitude, lenape.elevation</span>
<span id="cb80-2"><a href="#cb80-2" aria-hidden="true" tabindex="-1"></a>dzs <span class="op">=</span> zs[<span class="fl">2</span><span class="op">:</span><span class="kw">end</span>] <span class="op">-</span> zs[<span class="fl">1</span><span class="op">:</span><span class="kw">end</span><span class="op">-</span><span class="fl">1</span>]</span>
<span id="cb80-3"><a href="#cb80-3" aria-hidden="true" tabindex="-1"></a>dxs, dys <span class="op">=</span> xs[<span class="fl">2</span><span class="op">:</span><span class="kw">end</span>] <span class="op">-</span> xs[<span class="fl">1</span><span class="op">:</span><span class="kw">end</span><span class="op">-</span><span class="fl">1</span>], ys[<span class="fl">2</span><span class="op">:</span><span class="kw">end</span>] <span class="op">-</span> ys[<span class="fl">1</span><span class="op">:</span><span class="kw">end</span><span class="op">-</span><span class="fl">1</span>]</span>
<span id="cb80-4"><a href="#cb80-4" aria-hidden="true" tabindex="-1"></a>deltas <span class="op">=</span> <span class="fu">sqrt</span>.(dxs<span class="op">.^</span><span class="fl">2</span> <span class="op">+</span> dys<span class="op">.^</span><span class="fl">2</span>) <span class="op">*</span> <span class="fl">69</span> <span class="op">/</span> <span class="fl">1.6</span> <span class="op">*</span> <span class="fl">1000</span> <span class="co"># in meters now</span></span>
<span id="cb80-5"><a href="#cb80-5" aria-hidden="true" tabindex="-1"></a><span class="kw">global</span> slopes <span class="op">=</span> <span class="fu">abs</span>.(dzs <span class="op">./</span> deltas) <span class="co"># to re-use</span></span>
<span id="cb80-6"><a href="#cb80-6" aria-hidden="true" tabindex="-1"></a>m <span class="op">=</span> <span class="fu">maximum</span>(slopes)</span>
<span id="cb80-7"><a href="#cb80-7" aria-hidden="true" tabindex="-1"></a><span class="fu">atand</span>(<span class="fu">maximum</span>(slopes)) <span class="co"># in degrees due to the `d`</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="61">
<pre><code>58.377642682886105</code></pre>
</div>
</div>
<p>This is certainly too steep for a trail, which should be at most <span class="math inline">\(10\)</span> to <span class="math inline">\(15\)</span> degrees or so, not <span class="math inline">\(58\)</span>. This is due to the inaccuracy in the measurements. An average might be better:</p>
<div class="cell" data-execution_count="64">
<div class="sourceCode cell-code" id="cb82"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb82-1"><a href="#cb82-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> <span class="bu">Statistics</span>: mean</span>
<span id="cb82-2"><a href="#cb82-2" aria-hidden="true" tabindex="-1"></a><span class="fu">atand</span>(<span class="fu">mean</span>(slopes))</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="62">
<pre><code>8.817002448325248</code></pre>
</div>
</div>
<p>Which seems about right for a generally uphill trail section, as this is.</p>
<p>In the above example, the data is given in terms of a sample, not a functional representation. Suppose instead, the surface was generated by <code>f</code> and the path - in the <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span> plane - by <span class="math inline">\(\gamma\)</span>. Then we could estimate the maximum and average steepness by a process like this:</p>
<div class="cell" data-execution_count="65">
<div class="sourceCode cell-code" id="cb84"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb84-1"><a href="#cb84-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f₄</span>(x,y) <span class="op">=</span> <span class="fl">2</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>
<span id="cb84-2"><a href="#cb84-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f₄</span>(x) <span class="op">=</span> <span class="fu">f₄</span>(x<span class="op">...</span>)</span>
<span id="cb84-3"><a href="#cb84-3" aria-hidden="true" tabindex="-1"></a><span class="fu">γ₄</span>(t) <span class="op">=</span> t<span class="op">*</span>[<span class="fu">cos</span>(t), <span class="fu">-sin</span>(t)]</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="63">
<pre><code>γ₄ (generic function with 1 method)</code></pre>
</div>
</div>
<div class="cell" data-hold="true" data-execution_count="66">
<div class="sourceCode cell-code" id="cb86"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb86-1"><a href="#cb86-1" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">3</span><span class="op">/</span><span class="fl">2</span>, <span class="fl">3</span><span class="op">/</span><span class="fl">2</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
<span id="cb86-2"><a href="#cb86-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb86-3"><a href="#cb86-3" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, f₄, legend<span class="op">=</span><span class="cn">false</span>)</span>
<span id="cb86-4"><a href="#cb86-4" aria-hidden="true" tabindex="-1"></a><span class="fu">r</span>(t) <span class="op">=</span> [<span class="fu">γ₄</span>(t)<span class="op">...</span>, (f₄ <span class="op"></span> γ₄)(t)]</span>
<span id="cb86-5"><a href="#cb86-5" aria-hidden="true" tabindex="-1"></a><span class="fu">plot_parametric!</span>(<span class="fl">0</span><span class="op">..</span><span class="fl">1</span><span class="op">/</span><span class="fl">2</span>, r, linewidth<span class="op">=</span><span class="fl">5</span>, color<span class="op">=:</span>black)</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="64">
<p><img src="scalar_functions_files/figure-html/cell-67-output-1.svg" class="img-fluid"></p>
</div>
</div>
<div class="cell" data-execution_count="67">
<div class="sourceCode cell-code" id="cb87"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb87-1"><a href="#cb87-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(f₄ <span class="op"></span> γ₄, <span class="fl">0</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>)</span>
<span id="cb87-2"><a href="#cb87-2" aria-hidden="true" tabindex="-1"></a><span class="fu">slope</span>(t) <span class="op">=</span> <span class="fu">abs</span>((f₄ <span class="op"></span> γ₄)<span class="ch">'(t))</span></span>
<span id="cb87-3"><a href="#cb87-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb87-4"><a href="#cb87-4" aria-hidden="true" tabindex="-1"></a><span class="fl">1</span><span class="op">/</span>(<span class="cn">pi</span><span class="op">/</span><span class="fl">2</span> <span class="op">-</span> <span class="fl">0</span>) <span class="op">*</span> <span class="fu">quadgk</span>(t <span class="op">-&gt;</span> <span class="fu">atand</span>(<span class="fu">slope</span>(t)), <span class="fl">0</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>)[<span class="fl">1</span>] <span class="co"># the average</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="65">
<pre><code>50.585772642502285</code></pre>
</div>
</div>
<p>the average is <span class="math inline">\(50\)</span> degrees. As for the maximum slope:</p>
<div class="cell" data-hold="true" data-execution_count="68">
<div class="sourceCode cell-code" id="cb89"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb89-1"><a href="#cb89-1" aria-hidden="true" tabindex="-1"></a>cps <span class="op">=</span> <span class="fu">find_zeros</span>(slope, <span class="fl">0</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>) <span class="co"># critical points</span></span>
<span id="cb89-2"><a href="#cb89-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb89-3"><a href="#cb89-3" aria-hidden="true" tabindex="-1"></a><span class="fu">append!</span>(cps, (<span class="fl">0</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>)) <span class="co"># add end points</span></span>
<span id="cb89-4"><a href="#cb89-4" aria-hidden="true" tabindex="-1"></a><span class="fu">unique!</span>(cps)</span>
<span id="cb89-5"><a href="#cb89-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb89-6"><a href="#cb89-6" aria-hidden="true" tabindex="-1"></a>M, i <span class="op">=</span> <span class="fu">findmax</span>(<span class="fu">slope</span>.(cps)) <span class="co"># max, index</span></span>
<span id="cb89-7"><a href="#cb89-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb89-8"><a href="#cb89-8" aria-hidden="true" tabindex="-1"></a>cps[i], <span class="fu">slope</span>(cps[i])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="66">
<pre><code>(1.5707963267948966, 3.1415926535897927)</code></pre>
</div>
</div>
<p>The maximum slope occurs at an endpoint.</p>
</section>
</section>
<section id="directional-derivatives" class="level2" data-number="55.6">
<h2 data-number="55.6" class="anchored" data-anchor-id="directional-derivatives"><span class="header-section-number">55.6</span> Directional Derivatives</h2>
<p>The last example, how steep is the direction we are walking, is a question that can be asked when walking in a straight line in the <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span> plane. The answer has a simplified answer:</p>
<p>Let <span class="math inline">\(\vec\gamma(t) = C + t \langle a, b \rangle\)</span> be a line that goes through the point <span class="math inline">\(C\)</span> parallel, or in the direction of, to <span class="math inline">\(\vec{v} = \langle a , b \rangle\)</span>.</p>
<p>Then the function <span class="math inline">\(f \circ \vec\gamma(t)\)</span> will have a derivative when <span class="math inline">\(f\)</span> is differentiable and by the chain rule will be:</p>
<p><span class="math display">\[
(f\circ\vec\gamma)'(\vec\gamma(t)) = \nabla{f}(\vec\gamma(t)) \cdot \vec\gamma'(t) =
\nabla{f}(\vec\gamma(t)) \cdot \langle a, b\rangle =
\vec{v} \cdot \nabla{f}(\vec\gamma(t)).
\]</span></p>
<p>At <span class="math inline">\(t=0\)</span>, we see that <span class="math inline">\((f\circ\vec\gamma)'(C) = \nabla{f}(C)\cdot \vec{v}\)</span>.</p>
<p>This defines the <em>directional derivative</em> at <span class="math inline">\(C\)</span> in the direction <span class="math inline">\(\vec{v}\)</span>:</p>
<p><span class="math display">\[
\text{Directional derivative} = \nabla_{\vec{v}}(f) = \nabla{f} \cdot \vec{v}.
\]</span></p>
<p>If <span class="math inline">\(\vec{v}\)</span> is a <em>unit</em> vector, then the value of the directional derivative is the rate of increase in <span class="math inline">\(f\)</span> in the direction of <span class="math inline">\(\vec{v}\)</span>.</p>
<p>This is a <em>natural</em> generalization of the partial derivatives, which, in two dimensions, are the directional derivative in the <span class="math inline">\(x\)</span> direction and the directional derivative in the <span class="math inline">\(y\)</span> direction.</p>
<p>The following figure shows <span class="math inline">\(C = (1/2, -1/2)\)</span> and the two curves. Planes are added, as it can be easiest to visualize these curves as the intersection of the surface generated by <span class="math inline">\(f\)</span> and the vertical planes <span class="math inline">\(x=C_x\)</span> and <span class="math inline">\(y=C_y\)</span></p>
<div class="cell" data-hold="true" data-execution_count="69">
<div class="cell-output cell-output-display" data-execution_count="67">
<p><img src="scalar_functions_files/figure-html/cell-70-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>We can then visualize the directional derivative by a plane through <span class="math inline">\(C\)</span> in the direction <span class="math inline">\(\vec{v}\)</span>. Here we take <span class="math inline">\(C=(1/2, -1/2)\)</span>, as before, and <span class="math inline">\(\vec{v} = \langle 1, 1\rangle\)</span>:</p>
<div class="cell" data-hold="true" data-execution_count="70">
<div class="cell-output cell-output-display" data-execution_count="68">
<p><img src="scalar_functions_files/figure-html/cell-71-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>In this figure, we see that the directional derivative appears to be <span class="math inline">\(0\)</span>, unlike the partial derivatives in <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span>, which are negative and positive, respectively.</p>
<section id="example-10" class="level5">
<h5 class="anchored" data-anchor-id="example-10">Example</h5>
<p>Let <span class="math inline">\(f(x,y) = \sin(x+2y)\)</span> and <span class="math inline">\(\vec{v} = \langle 2, 1\rangle\)</span>. The directional derivative of <span class="math inline">\(f\)</span> in the direction of <span class="math inline">\(\vec{v}\)</span> at <span class="math inline">\((x,y)\)</span> is:</p>
<p><span class="math display">\[
\nabla{f}\cdot \frac{\vec{v}}{\|\vec{v}\|} = \langle \cos(x + 2y), 2\cos(x + 2y)\rangle \cdot \frac{\langle 2, 1 \rangle}{\sqrt{5}} = \frac{4}{\sqrt{5}} \cos(x + 2y).
\]</span></p>
</section>
<section id="example-11" class="level5">
<h5 class="anchored" data-anchor-id="example-11">Example</h5>
<p>Suppose <span class="math inline">\(f(x,y)\)</span> describes a surface, and <span class="math inline">\(\vec\gamma(t)\)</span> parameterizes a path in the <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span> plane. Then the vector valued function <span class="math inline">\(\vec{r}(t) = \langle \vec\gamma_1(t), \vec\gamma_2(t), (f\circ\vec\gamma)(t)\rangle\)</span> describes a path on the surface. The maximum steepness of the this path is found by maximizing the slope of the directional derivative in the direction of the tangent line. This would be the function of <span class="math inline">\(t\)</span>:</p>
<p><span class="math display">\[
\nabla{f}(\vec\gamma(t)) \cdot \vec{T}(t),
\]</span></p>
<p>Where <span class="math inline">\(T(t) = \vec\gamma'(t)/\|\vec\gamma'(t)\|\)</span> is the unit tangent vector to <span class="math inline">\(\gamma\)</span>.</p>
<p>Let <span class="math inline">\(f(x,y) = 2 - x^2 - y^2\)</span> and <span class="math inline">\(\vec\gamma(t) = (\pi-t) \langle \cos(t), \sin(t) \rangle\)</span>. What is the maximum steepness?</p>
<p>We have <span class="math inline">\(\nabla{f} = \langle -2x, -2y \rangle\)</span> and <span class="math inline">\(\vec\gamma'(t) = -\langle(\cos(t), \sin(t)) + (\pi-t) \langle(-\sin(t), \cos(t)\rangle\)</span>. We maximize this over <span class="math inline">\([0, \pi]\)</span>:</p>
<div class="cell" data-hold="true" data-execution_count="71">
<div class="sourceCode cell-code" id="cb91"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb91-1"><a href="#cb91-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> <span class="fl">2</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>
<span id="cb91-2"><a href="#cb91-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(v) <span class="op">=</span> <span class="fu">f</span>(v<span class="op">...</span>)</span>
<span id="cb91-3"><a href="#cb91-3" aria-hidden="true" tabindex="-1"></a><span class="fu">gamma</span>(t) <span class="op">=</span> (<span class="cn">pi</span><span class="op">-</span>t) <span class="op">*</span> [<span class="fu">cos</span>(t), <span class="fu">sin</span>(t)]</span>
<span id="cb91-4"><a href="#cb91-4" aria-hidden="true" tabindex="-1"></a><span class="fu">dd</span>(t) <span class="op">=</span> <span class="fu">gradient</span>(f)(<span class="fu">gamma</span>(t)) <span class="op"></span> gamma<span class="op">'</span>(t)</span>
<span id="cb91-5"><a href="#cb91-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb91-6"><a href="#cb91-6" aria-hidden="true" tabindex="-1"></a>cps <span class="op">=</span> <span class="fu">find_zeros</span>(dd, <span class="fl">0</span>, <span class="cn">pi</span>)</span>
<span id="cb91-7"><a href="#cb91-7" aria-hidden="true" tabindex="-1"></a><span class="fu">unique!</span>(<span class="fu">append!</span>(cps, (<span class="fl">0</span>, <span class="cn">pi</span>))) <span class="co"># add endpoints</span></span>
<span id="cb91-8"><a href="#cb91-8" aria-hidden="true" tabindex="-1"></a>M,i <span class="op">=</span> <span class="fu">findmax</span>(<span class="fu">dd</span>.(cps))</span>
<span id="cb91-9"><a href="#cb91-9" aria-hidden="true" tabindex="-1"></a>M</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="69">
<pre><code>6.283185307179586</code></pre>
</div>
</div>
</section>
<section id="example-the-gradient-indicates-the-direction-of-steepest-ascent" class="level5">
<h5 class="anchored" data-anchor-id="example-the-gradient-indicates-the-direction-of-steepest-ascent">Example: The gradient indicates the direction of steepest ascent</h5>
<p>Consider this figure showing a surface and a level curve along with a contour line:</p>
<div class="cell" data-hold="true" data-execution_count="72">
<div class="cell-output cell-output-display" data-execution_count="70">
<p><img src="scalar_functions_files/figure-html/cell-73-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>We have the level curve for <span class="math inline">\(f(x,y) = c\)</span> represented, and a point <span class="math inline">\((x,y, f(x,y))\)</span> drawn. At the point <span class="math inline">\((x,y)\)</span> which sits on the level curve, we have indicated the gradient and the tangent curve to the level curve, or contour line. Worth reiterating, the gradient is not on the surface, but rather is a <span class="math inline">\(2\)</span>-dimensional vector, but it does indicate a direction that can be taken on the surface. We will see that this direction indicates the path of steepest ascent.</p>
<p>The figure suggests a relationship between the gradient and the tangents to the contour lines. Lets parameterize the contour line by <span class="math inline">\(\vec\gamma(t)\)</span>, assuming such a parameterization exists, let <span class="math inline">\(C = (x,y) = \vec\gamma(t)\)</span>, for some <span class="math inline">\(t\)</span>, be a point on the level curve, and <span class="math inline">\(\vec{T} = \vec\gamma'(t)/\|\vec\gamma'(t)\|\)</span> be the tangent to to the level curve at <span class="math inline">\(C\)</span>. Then the directional derivative at <span class="math inline">\(C\)</span> in the direction of <span class="math inline">\(T\)</span> must be <span class="math inline">\(0\)</span>, as along the level curve, the function <span class="math inline">\(f\circ \vec\gamma = c\)</span>, a constant. But by the chain rule, this says:</p>
<p><span class="math display">\[
0 = (c)' = (f\circ\vec\gamma)'(t) = \nabla{f}(\vec\gamma(t)) \cdot \vec\gamma'(t)
\]</span></p>
<p>That is the gradient is <em>orthogonal</em> to <span class="math inline">\(\vec{\gamma}'(t)\)</span>. As well, is orthogonal to the tangent vector <span class="math inline">\(\vec{T}\)</span> and hence to the level curve at any point. (As the dot product is <span class="math inline">\(0\)</span>.)</p>
<p>Now, consider a unit vector <span class="math inline">\(\vec{v}\)</span> in the direction of steepest ascent at <span class="math inline">\(C\)</span>. Since <span class="math inline">\(\nabla{f}(C)\)</span> and <span class="math inline">\(\vec{T}\)</span> are orthogonal, we can express the unit vector uniquely as <span class="math inline">\(a\nabla{f}(C) + b \vec{T}\)</span> with <span class="math inline">\(a^2 + b^2 = 1\)</span>. The directional derivative is then</p>
<p><span class="math display">\[
\nabla{f} \cdot \vec{v} = \nabla{f} \cdot (a\nabla{f}(C) + b \vec{T}) = a \| \nabla{f} \|^2 + b \nabla{f} \cdot \vec{T} = a \| \nabla{f} \|^2.
\]</span></p>
<p>The will be largest when <span class="math inline">\(a=1\)</span> and <span class="math inline">\(b=0\)</span>. That is, the direction of greatest ascent in indicated by the gradient. (It is smallest when <span class="math inline">\(a=-1\)</span> and <span class="math inline">\(b=0\)</span>, the direction opposite the gradient.</p>
<p>In practical terms, if standing on a hill, walking in the direction of the gradient will go uphill the fastest possible way, walking along a contour will not gain any elevation. The two directions are orthogonal.</p>
</section>
</section>
<section id="other-types-of-compositions-and-the-chain-rule" class="level2" data-number="55.7">
<h2 data-number="55.7" class="anchored" data-anchor-id="other-types-of-compositions-and-the-chain-rule"><span class="header-section-number">55.7</span> Other types of compositions and the chain rule</h2>
<p>The chain rule we discussed was for a composition of <span class="math inline">\(f:R^n \rightarrow R\)</span> with <span class="math inline">\(\vec\gamma:R \rightarrow R^n\)</span> resulting in a function <span class="math inline">\(f\circ\vec\gamma:R \rightarrow R\)</span>. There are other possible compositions.</p>
<p>For example, suppose we have an economic model for beverage consumption based on temperature given by <span class="math inline">\(c(T)\)</span>. But temperature depends on geographic location, so may be modeled through a function <span class="math inline">\(T(x,y)\)</span>. The composition <span class="math inline">\(c \circ T\)</span> would be a function from <span class="math inline">\(R^2 \rightarrow R\)</span>, so should have partial derivatives with respect to <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span> which should be expressible in terms of the derivative of <span class="math inline">\(c\)</span> and the partial derivatives of <span class="math inline">\(T\)</span>.</p>
<p>Consider a different situation, say we have <span class="math inline">\(f(x,y)\)</span> a scalar function, but want to consider the position in polar coordinates involving <span class="math inline">\(r\)</span> and <span class="math inline">\(\theta\)</span>. We can think directly of <span class="math inline">\(F(r,\theta) = f(r\cdot\cos(\theta), r\cdot\sin(\theta))\)</span>, but more generally, we have a function <span class="math inline">\(G(r, \theta)\)</span> that is vector valued: <span class="math inline">\(G(r,\theta) = \langle r\cdot\cos(\theta), r\cdot\sin(\theta) \rangle\)</span> (<span class="math inline">\(G:R^2 \rightarrow R^2\)</span>). The composition <span class="math inline">\(F=f\circ G\)</span> is a scalar function of <span class="math inline">\(r\)</span> and <span class="math inline">\(\theta\)</span> and the partial derivatives with respect to these should be expressible in terms of the partial derivatives of <span class="math inline">\(f\)</span> and the partial derivatives of <span class="math inline">\(G\)</span>.</p>
<p>Finding the derivative of a composition in terms of the individual pieces involves some form of the chain rule, which will differ depending on the exact circumstances.</p>
<section id="chain-rule-for-a-univariate-function-composed-with-a-scalar-function" class="level3" data-number="55.7.1">
<h3 data-number="55.7.1" class="anchored" data-anchor-id="chain-rule-for-a-univariate-function-composed-with-a-scalar-function"><span class="header-section-number">55.7.1</span> Chain rule for a univariate function composed with a scalar function</h3>
<p>If <span class="math inline">\(f(t)\)</span> is a univariate function and <span class="math inline">\(G(x,y)\)</span> a scalar function, the <span class="math inline">\(F(x,y) = f(G(x,y))\)</span> will be a scalar function and may have partial derivatives. If <span class="math inline">\(f\)</span> and <span class="math inline">\(G\)</span> are differentiable at a point <span class="math inline">\(P\)</span>, then</p>
<p><span class="math display">\[
\frac{\partial F}{\partial x} = f'(G(x,y)) \frac{\partial G}{\partial x}, \quad
\frac{\partial F}{\partial y} = f'(G(x,y)) \frac{\partial G}{\partial y},
\]</span></p>
<p>and</p>
<p><span class="math display">\[
\nabla{F} = \nabla{f \circ G} = f'(G(x,y)) \nabla{G}(x,y).
\]</span></p>
<p>The result is an immediate application of the univariate chain rule, when the partial functions are considered.</p>
<section id="example-12" class="level5">
<h5 class="anchored" data-anchor-id="example-12">Example</h5>
<p>Imagine a scenario where sales of some commodity (say ice) depend on the temperature which in turn depends on location. Formally, we might have functions <span class="math inline">\(S(T)\)</span> and <span class="math inline">\(T(x,y)\)</span> and then sales would be the composition <span class="math inline">\(S(T(x,y))\)</span>. How might sales go up or down if one moved west, or one moved in the northwest direction? These would be a <em>directional</em> derivative, answered by <span class="math inline">\(\nabla{S}\cdot \hat{v}\)</span>, where <span class="math inline">\(\vec{v}\)</span> is the direction. Of importance would be to compute <span class="math inline">\(\nabla{S}\)</span> which might best be done through the chain rule.</p>
<p>For example, if <span class="math inline">\(S(T) = \exp((T - 70)/10)\)</span> and <span class="math inline">\(T(x,y) = (1-x^2)\cdot y\)</span>, the gradient of <span class="math inline">\(S(T(x,y))\)</span> would be given by:</p>
<p><span class="math display">\[
S'(T(x,y)) \nabla{T}(x,y) = (S(T(x,y))/10) \langle(-2xy, 1-x^2 \rangle.
\]</span></p>
</section>
</section>
<section id="chain-rule-for-a-scalar-function-f-composed-with-a-function-g-rm-rightarrow-rn." class="level3" data-number="55.7.2">
<h3 data-number="55.7.2" class="anchored" data-anchor-id="chain-rule-for-a-scalar-function-f-composed-with-a-function-g-rm-rightarrow-rn."><span class="header-section-number">55.7.2</span> Chain rule for a scalar function, <span class="math inline">\(f\)</span>, composed with a function <span class="math inline">\(G: R^m \rightarrow R^n\)</span>.</h3>
<p>If <span class="math inline">\(G(u_1, \dots, u_m) = \langle G_1, G_2,\dots, G_n\rangle\)</span> is a function of <span class="math inline">\(m\)</span> inputs that returns <span class="math inline">\(n\)</span> outputs we may view it as <span class="math inline">\(G: R^m \rightarrow R^n\)</span>. The composition with a scalar function <span class="math inline">\(f(v_1, v_2, \dots, v_n)=z\)</span> from <span class="math inline">\(R^n \rightarrow R\)</span> creates a scalar function from <span class="math inline">\(R^m \rightarrow R\)</span>, so the question of partial derivatives is of interest. We have:</p>
<p><span class="math display">\[
\frac{\partial (f \circ G)}{\partial u_i} =
\frac{\partial f}{\partial v_1} \frac{\partial G}{\partial u_i} +
\frac{\partial f}{\partial v_2} \frac{\partial G}{\partial u_i} + \dots +
\frac{\partial f}{\partial v_n} \frac{\partial G}{\partial u_i}.
\]</span></p>
<p>The gradient is then:</p>
<p><span class="math display">\[
\nabla(f\circ G) =
\frac{\partial f}{\partial v_1} \nabla{G_1} +
\frac{\partial f}{\partial v_2} \nabla{G_2} + \dots +
\frac{\partial f}{\partial v_n} \nabla{G_n} = \nabla(f) \cdot \langle \nabla{G_1}, \nabla{G_2}, \dots, \nabla{G_n} \rangle,
\]</span></p>
<p>The last expression is a suggestion, as it is an abuse of previously used notation: the dot product isnt between vectors of the same type, as the rightmost vector is representing a vector of vectors. The <a href="https://en.wikipedia.org/wiki/Jacobian_matrix_and_determinant">Jacobian</a> matrix combines these vectors into a rectangular array, though with the vectors written as <em>row</em> vectors. If <span class="math inline">\(G: R^m \rightarrow R^n\)</span>, then the Jacobian is the <span class="math inline">\(n \times m\)</span> matrix with <span class="math inline">\((i,j)\)</span> entry given by <span class="math inline">\(\partial G_i, \partial u_j\)</span>:</p>
<p><span class="math display">\[
J = \left[
\begin{align}
\frac{\partial G_1}{\partial u_1} &amp; \frac{\partial G_1}{\partial u_2} &amp; \dots \frac{\partial G_1}{\partial u_m}\\
\frac{\partial G_2}{\partial u_1} &amp; \frac{\partial G_2}{\partial u_2} &amp; \dots \frac{\partial G_2}{\partial u_m}\\
&amp; \vdots &amp; \\
\frac{\partial G_n}{\partial u_1} &amp; \frac{\partial G_n}{\partial u_2} &amp; \dots \frac{\partial G_n}{\partial u_m}
\end{align}
\right].
\]</span></p>
<p>With this notation, and matrix multiplication we have <span class="math inline">\((\nabla(f\circ G))^t = \nabla(f)^t J\)</span>.</p>
<p>(Later, we will see that the chain rule in general has a familiar form using matrices, not vectors, which will avoid the need for a transpose.)</p>
<section id="example-13" class="level5">
<h5 class="anchored" data-anchor-id="example-13">Example</h5>
<p>Let <span class="math inline">\(f(x,y) = x^2 + y^2\)</span> be a scalar function. We have if <span class="math inline">\(G(r, \theta) = \langle r\cos(\theta)(, r\sin(\theta) \rangle\)</span> then after simplification, we have <span class="math inline">\((f \circ G)(r, \theta) = r^2\)</span>. Clearly then <span class="math inline">\(\partial(f\circ G)/\partial r = 2r\)</span> and <span class="math inline">\(\partial(f\circ G)/\partial \theta = 0\)</span>.</p>
<p>Were this computed through the chain rule, we have:</p>
<p><span class="math display">\[
\begin{align}
\nabla G_1 &amp;= \langle \frac{\partial r\cos(\theta)}{\partial r}, \frac{\partial r\cos(\theta)}{\partial \theta} \rangle=
\langle \cos(\theta), -r \sin(\theta) \rangle,\\
\nabla G_2 &amp;= \langle \frac{\partial r\sin(\theta)}{\partial r}, \frac{\partial r\sin(\theta)}{\partial \theta} \rangle=
\langle \sin(\theta), r \cos(\theta) \rangle.
\end{align}
\]</span></p>
<p>We have <span class="math inline">\(\partial f/\partial x = 2x\)</span> and <span class="math inline">\(\partial f/\partial y = 2y\)</span>, which at <span class="math inline">\(G\)</span> are <span class="math inline">\(2r\cos(\theta)\)</span> and <span class="math inline">\(2r\sin(\theta)\)</span>, so by the chain rule, we should have</p>
<p><span class="math display">\[
\begin{align}
\frac{\partial (f\circ G)}{\partial r} &amp;=
\frac{\partial{f}}{\partial{x}}\frac{\partial G_1}{\partial r} +
\frac{\partial{f}}{\partial{y}}\frac{\partial G_2}{\partial r} =
2r\cos(\theta) \cos(\theta) + 2r\sin(\theta) \sin(\theta) =
2r (\cos^2(\theta) + \sin^2(\theta)) = 2r, \\
\frac{\partial (f\circ G)}{\partial \theta} &amp;=
\frac{\partial f}{\partial x}\frac{\partial G_1}{\partial \theta} +
\frac{\partial f}{\partial y}\frac{\partial G_2}{\partial \theta} =
2r\cos(\theta)(-r\sin(\theta)) + 2r\sin(\theta)(r\cos(\theta)) = 0.
\end{align}
\]</span></p>
</section>
</section>
</section>
<section id="higher-order-partial-derivatives" class="level2" data-number="55.8">
<h2 data-number="55.8" class="anchored" data-anchor-id="higher-order-partial-derivatives"><span class="header-section-number">55.8</span> Higher order partial derivatives</h2>
<p>If <span class="math inline">\(f:R^n \rightarrow R\)</span>, the <span class="math inline">\(\partial f/\partial x_i\)</span> takes <span class="math inline">\(R^n \rightarrow R\)</span> too, so may also have a partial derivative.</p>
<p>Consider the case <span class="math inline">\(f: R^2 \rightarrow R\)</span>, then there are <span class="math inline">\(4\)</span> possible partial derivatives of order 2: partial in <span class="math inline">\(x\)</span> then <span class="math inline">\(x\)</span>, partial in <span class="math inline">\(x\)</span> then <span class="math inline">\(y\)</span>, partial in <span class="math inline">\(y\)</span> and then <span class="math inline">\(x\)</span>, and, finally, partial in <span class="math inline">\(y\)</span> and then <span class="math inline">\(y\)</span>.</p>
<p>The notation for the partial in <span class="math inline">\(y\)</span> <em>of</em> the partial in <span class="math inline">\(x\)</span> is:</p>
<p><span class="math display">\[
\frac{\partial^2 f}{\partial{y}\partial{x}} = \frac{\partial{\frac{\partial{f}}{\partial{x}}}}{\partial{y}} = \frac{\partial f_x}{\partial{y}} = f_{xy}.
\]</span></p>
<p>The placement of <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span> indicating the order is different in the two notations.</p>
<p>We can compute these for an example easily enough:</p>
<div class="cell" data-hold="true" data-execution_count="73">
<div class="sourceCode cell-code" id="cb93"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb93-1"><a href="#cb93-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> x y</span>
<span id="cb93-2"><a href="#cb93-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x, y) <span class="op">=</span> <span class="fu">exp</span>(x) <span class="op">*</span> <span class="fu">cos</span>(y)</span>
<span id="cb93-3"><a href="#cb93-3" aria-hidden="true" tabindex="-1"></a>ex <span class="op">=</span> <span class="fu">f</span>(x,y)</span>
<span id="cb93-4"><a href="#cb93-4" aria-hidden="true" tabindex="-1"></a><span class="fu">diff</span>(ex, x, x), <span class="fu">diff</span>(ex, x, y), <span class="fu">diff</span>(ex, y, x), <span class="fu">diff</span>(ex, y, 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="71">
<pre><code>(exp(x)*cos(y), -exp(x)*sin(y), -exp(x)*sin(y), -exp(x)*cos(y))</code></pre>
</div>
</div>
<p>In <code>SymPy</code> the variable to differentiate by is taken from left to right, so <code>diff(ex, x, y, x)</code> would first take the partial in <span class="math inline">\(x\)</span>, then <span class="math inline">\(y\)</span>, and finally <span class="math inline">\(x\)</span>.</p>
<p>We see that <code>diff(ex, x, y)</code> and <code>diff(ex, y, x)</code> are identical. This is not a coincidence, as by <a href="https://tinyurl.com/y7sfw9sx">Schwarzs Theorem</a> (also known as Clairauts theorem) this will always be the case under typical assumptions:</p>
<blockquote class="blockquote">
<p>Theorem on mixed partials. If the mixed partials <span class="math inline">\(\partial^2 f/\partial x \partial y\)</span> and <span class="math inline">\(\partial^2 f/\partial y \partial x\)</span> exist and are continuous, then they are equal.</p>
</blockquote>
<p>For higher order mixed partials, something similar to Schwarzs theorem still holds. Say <span class="math inline">\(f:R^n \rightarrow R\)</span> is <span class="math inline">\(C^k\)</span> if <span class="math inline">\(f\)</span> is continuous and all partial derivatives of order <span class="math inline">\(j \leq k\)</span> are continous. If <span class="math inline">\(f\)</span> is <span class="math inline">\(C^k\)</span>, and <span class="math inline">\(k=k_1+k_2+\cdots+k_n\)</span> (<span class="math inline">\(k_i \geq 0\)</span>) then</p>
<p><span class="math display">\[
\frac{\partial^k f}{\partial x_1^{k_1} \partial x_2^{k_2} \cdots \partial x_n^{k_n}},
\]</span></p>
<p>is uniquely defined. That is, which order the partial derivatives are taken is unimportant if the function is sufficiently smooth.</p>
<hr>
<p>The <a href="https://en.wikipedia.org/wiki/Hessian_matrix">Hessian</a> matrix is the matrix of mixed partials defined (for <span class="math inline">\(n=2\)</span>) by:</p>
<p><span class="math display">\[
H = \left[
\begin{align}
\frac{\partial^2 f}{\partial x \partial x} &amp; \frac{\partial^2 f}{\partial x \partial y}\\
\frac{\partial^2 f}{\partial y \partial x} &amp; \frac{\partial^2 f}{\partial y \partial y}
\end{align}
\right].
\]</span></p>
<p>For symbolic expressions, the Hessian may be computed directly in <code>SymPy</code> with its <code>hessian</code> function:</p>
<div class="cell" data-execution_count="74">
<div class="sourceCode cell-code" id="cb95"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb95-1"><a href="#cb95-1" aria-hidden="true" tabindex="-1"></a>ex</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="72">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
e^{x} \cos{\left(y \right)}
\]
</span>
</div>
</div>
<div class="cell" data-execution_count="75">
<div class="sourceCode cell-code" id="cb96"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb96-1"><a href="#cb96-1" aria-hidden="true" tabindex="-1"></a><span class="fu">hessian</span>(ex, (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="73">
<pre><code>2×2 Matrix{Sym}:
exp(x)*cos(y) -exp(x)*sin(y)
-exp(x)*sin(y) -exp(x)*cos(y)</code></pre>
</div>
</div>
<p>When the mixed partials are continuous, this will be a symmetric matrix. The Hessian matrix plays the role of the second derivative in the multivariate Taylor theorem.</p>
<p>For numeric use, <code>FowardDiff</code> has a <code>hessian</code> function. It expects a scalar function and a point and returns the Hessian matrix. We have for <span class="math inline">\(f(x,y) = e^x\cos(y)\)</span> at the point <span class="math inline">\((1,2)\)</span>, the Hessian matrix is:</p>
<div class="cell" data-hold="true" data-execution_count="76">
<div class="sourceCode cell-code" id="cb98"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb98-1"><a href="#cb98-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> <span class="fu">exp</span>(x) <span class="op">*</span> <span class="fu">cos</span>(y)</span>
<span id="cb98-2"><a href="#cb98-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(v) <span class="op">=</span> <span class="fu">f</span>(v<span class="op">...</span>)</span>
<span id="cb98-3"><a href="#cb98-3" aria-hidden="true" tabindex="-1"></a>pt <span class="op">=</span> [<span class="fl">1</span>, <span class="fl">2</span>]</span>
<span id="cb98-4"><a href="#cb98-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb98-5"><a href="#cb98-5" aria-hidden="true" tabindex="-1"></a>ForwardDiff.<span class="fu">hessian</span>(f, pt) <span class="co"># symmetric</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="74">
<pre><code>2×2 Matrix{Float64}:
-1.1312 -2.47173
-2.47173 1.1312</code></pre>
</div>
</div>
</section>
<section id="questions" class="level2" data-number="55.9">
<h2 data-number="55.9" class="anchored" data-anchor-id="questions"><span class="header-section-number">55.9</span> Questions</h2>
<section id="question" class="level6">
<h6 class="anchored" data-anchor-id="question">Question</h6>
<p>Consider the graph of a function <span class="math inline">\(z= f(x,y)\)</span> presented below:</p>
<div class="cell" data-hold="true" data-execution_count="77">
<div class="cell-output cell-output-display" data-execution_count="75">
<p><img src="scalar_functions_files/figure-html/cell-78-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>From the graph, is the value of <span class="math inline">\(f(1/2, 1)\)</span> positive or negative?</p>
<div class="cell" data-hold="true" data-execution_count="78">
<div class="cell-output cell-output-display" data-execution_count="76">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="10809636823135675830" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_10809636823135675830">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_10809636823135675830_1">
<input class="form-check-input" type="radio" name="radio_10809636823135675830" id="radio_10809636823135675830_1" value="1">
<span class="label-body px-1">
positive
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_10809636823135675830_2">
<input class="form-check-input" type="radio" name="radio_10809636823135675830" id="radio_10809636823135675830_2" value="2">
<span class="label-body px-1">
negative
</span>
</label>
</div>
</div>
</div>
<div id="10809636823135675830_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_10809636823135675830"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('10809636823135675830_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_10809636823135675830")
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_10809636823135675830")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>On which line is the function <span class="math inline">\(0\)</span>:</p>
<div class="cell" data-hold="true" data-execution_count="79">
<div class="cell-output cell-output-display" data-execution_count="77">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="16869468093988549210" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_16869468093988549210">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_16869468093988549210_1">
<input class="form-check-input" type="radio" name="radio_16869468093988549210" id="radio_16869468093988549210_1" value="1">
<span class="label-body px-1">
The line \(x=0\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_16869468093988549210_2">
<input class="form-check-input" type="radio" name="radio_16869468093988549210" id="radio_16869468093988549210_2" value="2">
<span class="label-body px-1">
The line \(y=0\)
</span>
</label>
</div>
</div>
</div>
<div id="16869468093988549210_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_16869468093988549210"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('16869468093988549210_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_16869468093988549210")
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_16869468093988549210")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Consider the contour plot</p>
<div class="cell" data-hold="true" data-execution_count="80">
<div class="cell-output cell-output-display" data-execution_count="78">
<p><img src="scalar_functions_files/figure-html/cell-81-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>What is the value of <span class="math inline">\(f(1, 0)\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="81">
<div class="cell-output cell-output-display" data-execution_count="79">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12851428147713904375" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_12851428147713904375">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="12851428147713904375" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="12851428147713904375_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("12851428147713904375").addEventListener("change", function() {
var correct = (Math.abs(this.value - 0.367879) <= 0.5);
var msgBox = document.getElementById('12851428147713904375_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_12851428147713904375")
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_12851428147713904375")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>From this graph, the minimum value over this region is</p>
<div class="cell" data-hold="true" data-execution_count="82">
<div class="cell-output cell-output-display" data-execution_count="80">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15925376085390063254" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_15925376085390063254">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_15925376085390063254_1">
<input class="form-check-input" type="radio" name="radio_15925376085390063254" id="radio_15925376085390063254_1" value="1">
<span class="label-body px-1">
is around \((0.7, 0)\) and with a value less than \(-0.4\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_15925376085390063254_2">
<input class="form-check-input" type="radio" name="radio_15925376085390063254" id="radio_15925376085390063254_2" value="2">
<span class="label-body px-1">
is around \((2.0, 0)\) and with a value less than \(-0.4\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_15925376085390063254_3">
<input class="form-check-input" type="radio" name="radio_15925376085390063254" id="radio_15925376085390063254_3" value="3">
<span class="label-body px-1">
is around \((-2.0, 0)\) and with a value less than \(-0.4\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_15925376085390063254_4">
<input class="form-check-input" type="radio" name="radio_15925376085390063254" id="radio_15925376085390063254_4" value="4">
<span class="label-body px-1">
is around \((-0.7, 0)\) and with a value less than \(-0.4\)
</span>
</label>
</div>
</div>
</div>
<div id="15925376085390063254_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_15925376085390063254"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 4;
var msgBox = document.getElementById('15925376085390063254_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_15925376085390063254")
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_15925376085390063254")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>From this graph, where is the surface steeper?</p>
<div class="cell" data-hold="true" data-execution_count="83">
<div class="cell-output cell-output-display" data-execution_count="81">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="13288769514057470663" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_13288769514057470663">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_13288769514057470663_1">
<input class="form-check-input" type="radio" name="radio_13288769514057470663" id="radio_13288769514057470663_1" value="1">
<span class="label-body px-1">
near \((1/4, 0)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13288769514057470663_2">
<input class="form-check-input" type="radio" name="radio_13288769514057470663" id="radio_13288769514057470663_2" value="2">
<span class="label-body px-1">
near \((1/2, 0)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13288769514057470663_3">
<input class="form-check-input" type="radio" name="radio_13288769514057470663" id="radio_13288769514057470663_3" value="3">
<span class="label-body px-1">
near \((3/4, 0)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13288769514057470663_4">
<input class="form-check-input" type="radio" name="radio_13288769514057470663" id="radio_13288769514057470663_4" value="4">
<span class="label-body px-1">
near \((1, 0)\)
</span>
</label>
</div>
</div>
</div>
<div id="13288769514057470663_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_13288769514057470663"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('13288769514057470663_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_13288769514057470663")
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_13288769514057470663")
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>Consider the contour graph of a function below:</p>
<div class="cell" data-hold="true" data-execution_count="84">
<div class="cell-output cell-output-display" data-execution_count="82">
<p><img src="scalar_functions_files/figure-html/cell-85-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Are there any peaks or valleys (local extrema) indicated?</p>
<div class="cell" data-hold="true" data-execution_count="85">
<div class="cell-output cell-output-display" data-execution_count="83">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="4217391322102808904" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_4217391322102808904">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_4217391322102808904_1">
<input class="form-check-input" type="radio" name="radio_4217391322102808904" id="radio_4217391322102808904_1" value="1">
<span class="label-body px-1">
Yes, the closed loops near \((-1.5, 0)\) and \((1.5, 0)\) will contain these
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4217391322102808904_2">
<input class="form-check-input" type="radio" name="radio_4217391322102808904" id="radio_4217391322102808904_2" value="2">
<span class="label-body px-1">
No, the vertical lines parallel to \(x=0\) show this function to be flat
</span>
</label>
</div>
</div>
</div>
<div id="4217391322102808904_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_4217391322102808904"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('4217391322102808904_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_4217391322102808904")
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_4217391322102808904")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Imagine hiking on this surface within this region. Could you traverse from left to right without having to go up or down?</p>
<div class="cell" data-hold="true" data-execution_count="86">
<div class="cell-output cell-output-display" data-execution_count="84">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="13714482832838869436" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_13714482832838869436">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_13714482832838869436_1">
<input class="form-check-input" type="radio" name="radio_13714482832838869436" id="radio_13714482832838869436_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13714482832838869436_2">
<input class="form-check-input" type="radio" name="radio_13714482832838869436" id="radio_13714482832838869436_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="13714482832838869436_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_13714482832838869436"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('13714482832838869436_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_13714482832838869436")
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_13714482832838869436")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Imagine hiking on this surface within this region. Could you traverse from top to bottom without having to go up or down?</p>
<div class="cell" data-hold="true" data-execution_count="87">
<div class="cell-output cell-output-display" data-execution_count="85">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="5769942430670103638" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_5769942430670103638">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_5769942430670103638_1">
<input class="form-check-input" type="radio" name="radio_5769942430670103638" id="radio_5769942430670103638_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5769942430670103638_2">
<input class="form-check-input" type="radio" name="radio_5769942430670103638" id="radio_5769942430670103638_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="5769942430670103638_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_5769942430670103638"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('5769942430670103638_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_5769942430670103638")
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_5769942430670103638")
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>The figure (taken from <a href="https://www.openstreetmap.org/way/537938655#map=15/46.5308/10.4556&amp;layers=C">openstreetmap.org</a> shows the <a href="https://en.wikipedia.org/wiki/Stelvio_Pass">Stelvio</a> Pass in Northern Italy near the Swiss border.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../differentiable_vector_calculus/figures/stelvio-pass.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Stelvio Pass</figcaption><p></p>
</figure>
</div>
<p>The road through the pass (on the right) makes a series of switch backs.</p>
<p>Are these</p>
<div class="cell" data-hold="true" data-execution_count="89">
<div class="cell-output cell-output-display" data-execution_count="87">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="1281356201944380594" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_1281356201944380594">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_1281356201944380594_1">
<input class="form-check-input" type="radio" name="radio_1281356201944380594" id="radio_1281356201944380594_1" value="1">
<span class="label-body px-1">
running essentially perpendicular to the contour lines
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1281356201944380594_2">
<input class="form-check-input" type="radio" name="radio_1281356201944380594" id="radio_1281356201944380594_2" value="2">
<span class="label-body px-1">
running essentially parallel to the contour lines
</span>
</label>
</div>
</div>
</div>
<div id="1281356201944380594_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_1281356201944380594"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('1281356201944380594_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_1281356201944380594")
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_1281356201944380594")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Why?</p>
<div class="cell" data-hold="true" data-execution_count="90">
<div class="cell-output cell-output-display" data-execution_count="88">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="2568592969929957953" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_2568592969929957953">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_2568592969929957953_1">
<input class="form-check-input" type="radio" name="radio_2568592969929957953" id="radio_2568592969929957953_1" value="1">
<span class="label-body px-1">
By being essentially parallel, the steepness of the roadway can be kept to a passable level
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2568592969929957953_2">
<input class="form-check-input" type="radio" name="radio_2568592969929957953" id="radio_2568592969929957953_2" value="2">
<span class="label-body px-1">
By being essentially perpendicular, the road can more quickly climb up the mountain
</span>
</label>
</div>
</div>
</div>
<div id="2568592969929957953_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_2568592969929957953"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('2568592969929957953_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_2568592969929957953")
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_2568592969929957953")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>The pass is at about 2700 meters. As shown towards the top and bottom of the figure the contour lines show increasing heights, and to the left and right decreasing heights. The shape of the <a href="https://en.wikipedia.org/wiki/Mountain_pass">pass</a> would look like:</p>
<div class="cell" data-hold="true" data-execution_count="91">
<div class="cell-output cell-output-display" data-execution_count="89">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="16493377070031535182" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_16493377070031535182">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_16493377070031535182_1">
<input class="form-check-input" type="radio" name="radio_16493377070031535182" id="radio_16493377070031535182_1" value="1">
<span class="label-body px-1">
A saddle-like shape, called a <em>col</em> or <em>gap</em>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_16493377070031535182_2">
<input class="form-check-input" type="radio" name="radio_16493377070031535182" id="radio_16493377070031535182_2" value="2">
<span class="label-body px-1">
A upside down bowl-like shape like the top of a mountain
</span>
</label>
</div>
</div>
</div>
<div id="16493377070031535182_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_16493377070031535182"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('16493377070031535182_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_16493377070031535182")
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_16493377070031535182")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-3" class="level6">
<h6 class="anchored" data-anchor-id="question-3">Question</h6>
<p>Limits of scalar functions have the same set of rules as limits of univariate functions. These include limits of constants; limits of sums, differences, and scalar multiples; limits of products; and limits of ratios. The latter with the provision that division by <span class="math inline">\(0\)</span> does not occur at the point in question.</p>
<p>Using these, identify any points where the following limit <em>may</em> not exist, knowing the limits of the individual functions exist at <span class="math inline">\(\vec{c}\)</span>:</p>
<p><span class="math display">\[
\lim_{\vec{x} \rightarrow \vec{x}} \frac{af(\vec{x})g(\vec{x}) + bh(\vec{x})}{ci(\vec{x})}.
\]</span></p>
<div class="cell" data-hold="true" data-execution_count="92">
<div class="cell-output cell-output-display" data-execution_count="90">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="5821572146112185936" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_5821572146112185936">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_5821572146112185936_1">
<input class="form-check-input" type="radio" name="radio_5821572146112185936" id="radio_5821572146112185936_1" value="1">
<span class="label-body px-1">
When \(i(\vec{x}) = 0\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5821572146112185936_2">
<input class="form-check-input" type="radio" name="radio_5821572146112185936" id="radio_5821572146112185936_2" value="2">
<span class="label-body px-1">
When any of \(f(\vec{x})\), \(g(\vec{x})\), or \(i(\vec{x})\) are zero
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5821572146112185936_3">
<input class="form-check-input" type="radio" name="radio_5821572146112185936" id="radio_5821572146112185936_3" value="3">
<span class="label-body px-1">
The limit exists everywhere, as the function \(f\), \(g\), \(h\), and \(i\) have limits at \(\vec{c}\) by assumption
</span>
</label>
</div>
</div>
</div>
<div id="5821572146112185936_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_5821572146112185936"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('5821572146112185936_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_5821572146112185936")
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_5821572146112185936")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-4" class="level6">
<h6 class="anchored" data-anchor-id="question-4">Question</h6>
<p>Let <span class="math inline">\(f(x,y) = (x^2 - y^2) /(x^2 + y^2)\)</span>.</p>
<p>Fix <span class="math inline">\(y=0\)</span>. What is <span class="math inline">\(\lim_{x \rightarrow 0} f(x,0)\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="93">
<div class="cell-output cell-output-display" data-execution_count="91">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="8340978461645237888" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_8340978461645237888">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="8340978461645237888" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="8340978461645237888_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("8340978461645237888").addEventListener("change", function() {
var correct = (Math.abs(this.value - 1) <= 0);
var msgBox = document.getElementById('8340978461645237888_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_8340978461645237888")
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_8340978461645237888")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>Fix <span class="math inline">\(x=0\)</span>. What is <span class="math inline">\(\lim_{y \rightarrow 0} f(0, y)\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="94">
<div class="cell-output cell-output-display" data-execution_count="92">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15264959328731074233" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_15264959328731074233">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="15264959328731074233" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="15264959328731074233_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("15264959328731074233").addEventListener("change", function() {
var correct = (Math.abs(this.value - -1) <= 0);
var msgBox = document.getElementById('15264959328731074233_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_15264959328731074233")
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_15264959328731074233")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>The two paths technique shows a limit does not exist by finding two paths with <em>different</em> limits as <span class="math inline">\(\vec{x}\)</span> approaches <span class="math inline">\(\vec{c}\)</span>. Does this apply to <span class="math inline">\(\lim_{\langle x,y\rangle \rightarrow\langle 0, 0 \rangle}f(x,y)\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="95">
<div class="cell-output cell-output-display" data-execution_count="93">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15766230233238820003" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_15766230233238820003">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_15766230233238820003_1">
<input class="form-check-input" type="radio" name="radio_15766230233238820003" id="radio_15766230233238820003_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_15766230233238820003_2">
<input class="form-check-input" type="radio" name="radio_15766230233238820003" id="radio_15766230233238820003_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="15766230233238820003_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_15766230233238820003"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('15766230233238820003_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_15766230233238820003")
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_15766230233238820003")
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">\(f(x,y) = \langle \sin(x)\cos(2y), \sin(2x)\cos(y) \rangle\)</span></p>
<p>Compute <span class="math inline">\(f_x\)</span></p>
<div class="cell" data-hold="true" data-execution_count="96">
<div class="cell-output cell-output-display" data-execution_count="94">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="17326898546054126949" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_17326898546054126949">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_17326898546054126949_1">
<input class="form-check-input" type="radio" name="radio_17326898546054126949" id="radio_17326898546054126949_1" value="1">
<span class="label-body px-1">
\(\langle \cos(x)\cos(2y), 2\cos(2x)\cos(y)\rangle\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_17326898546054126949_2">
<input class="form-check-input" type="radio" name="radio_17326898546054126949" id="radio_17326898546054126949_2" value="2">
<span class="label-body px-1">
\(\langle \sin(x), \sin(2x) \rangle\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_17326898546054126949_3">
<input class="form-check-input" type="radio" name="radio_17326898546054126949" id="radio_17326898546054126949_3" value="3">
<span class="label-body px-1">
\(\langle \cos(2y), \cos(y) \rangle\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_17326898546054126949_4">
<input class="form-check-input" type="radio" name="radio_17326898546054126949" id="radio_17326898546054126949_4" value="4">
<span class="label-body px-1">
\(\sin(x)\cos(2y)\)
</span>
</label>
</div>
</div>
</div>
<div id="17326898546054126949_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_17326898546054126949"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('17326898546054126949_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_17326898546054126949")
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_17326898546054126949")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Compute <span class="math inline">\(f_y\)</span></p>
<div class="cell" data-hold="true" data-execution_count="97">
<div class="cell-output cell-output-display" data-execution_count="95">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="14256950342970278424" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_14256950342970278424">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_14256950342970278424_1">
<input class="form-check-input" type="radio" name="radio_14256950342970278424" id="radio_14256950342970278424_1" value="1">
<span class="label-body px-1">
\(- \sin(2x)\sin(y)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14256950342970278424_2">
<input class="form-check-input" type="radio" name="radio_14256950342970278424" id="radio_14256950342970278424_2" value="2">
<span class="label-body px-1">
\(\langle -2\sin(2y), -\sin(y) \rangle\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14256950342970278424_3">
<input class="form-check-input" type="radio" name="radio_14256950342970278424" id="radio_14256950342970278424_3" value="3">
<span class="label-body px-1">
\(\langle 2\sin(x), \sin(2x) \rangle\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14256950342970278424_4">
<input class="form-check-input" type="radio" name="radio_14256950342970278424" id="radio_14256950342970278424_4" value="4">
<span class="label-body px-1">
\(\langle -2\sin(x)\sin(2y), -\sin(2x)\sin(y) \rangle\)
</span>
</label>
</div>
</div>
</div>
<div id="14256950342970278424_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_14256950342970278424"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 4;
var msgBox = document.getElementById('14256950342970278424_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_14256950342970278424")
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_14256950342970278424")
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>Let <span class="math inline">\(f(x,y) = x^{y\sin(xy)}\)</span>. Using <code>ForwardDiff</code>, at the point <span class="math inline">\((1/2, 1/2)\)</span>, compute the following.</p>
<p>The value of <span class="math inline">\(f_x\)</span>:</p>
<div class="cell" data-hold="true" data-execution_count="98">
<div class="cell-output cell-output-display" data-execution_count="96">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="17542388983920443911" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_17542388983920443911">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="17542388983920443911" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="17542388983920443911_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("17542388983920443911").addEventListener("change", function() {
var correct = (Math.abs(this.value - 0.07297132538367865) <= 0.001);
var msgBox = document.getElementById('17542388983920443911_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_17542388983920443911")
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_17542388983920443911")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>The value of <span class="math inline">\(\partial{f}/\partial{y}\)</span>:</p>
<div class="cell" data-hold="true" data-execution_count="99">
<div class="cell-output cell-output-display" data-execution_count="97">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="9831935470251597398" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_9831935470251597398">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="9831935470251597398" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="9831935470251597398_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("9831935470251597398").addEventListener("change", function() {
var correct = (Math.abs(this.value - -0.3114994652875246) <= 0.001);
var msgBox = document.getElementById('9831935470251597398_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_9831935470251597398")
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_9831935470251597398")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
</section>
<section id="question-7" class="level6">
<h6 class="anchored" data-anchor-id="question-7">Question</h6>
<p>Let <span class="math inline">\(z = f(x,y)\)</span> have gradient <span class="math inline">\(\langle f_x, f_y \rangle\)</span>.</p>
<p>The gradient is:</p>
<div class="cell" data-hold="true" data-execution_count="100">
<div class="cell-output cell-output-display" data-execution_count="98">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="8563095169072339609" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_8563095169072339609">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_8563095169072339609_1">
<input class="form-check-input" type="radio" name="radio_8563095169072339609" id="radio_8563095169072339609_1" value="1">
<span class="label-body px-1">
two dimensional
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_8563095169072339609_2">
<input class="form-check-input" type="radio" name="radio_8563095169072339609" id="radio_8563095169072339609_2" value="2">
<span class="label-body px-1">
three dimensional
</span>
</label>
</div>
</div>
</div>
<div id="8563095169072339609_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_8563095169072339609"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('8563095169072339609_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_8563095169072339609")
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_8563095169072339609")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>The surface is:</p>
<div class="cell" data-hold="true" data-execution_count="101">
<div class="cell-output cell-output-display" data-execution_count="99">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="10975997342384958273" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_10975997342384958273">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_10975997342384958273_1">
<input class="form-check-input" type="radio" name="radio_10975997342384958273" id="radio_10975997342384958273_1" value="1">
<span class="label-body px-1">
two dimensional
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_10975997342384958273_2">
<input class="form-check-input" type="radio" name="radio_10975997342384958273" id="radio_10975997342384958273_2" value="2">
<span class="label-body px-1">
three dimensional
</span>
</label>
</div>
</div>
</div>
<div id="10975997342384958273_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_10975997342384958273"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('10975997342384958273_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_10975997342384958273")
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_10975997342384958273")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>The gradient points in the direction of greatest increase of <span class="math inline">\(f\)</span>. If a person were on a hill described by <span class="math inline">\(z=f(x,y)\)</span>, what three dimensional vector would they follow to go the steepest way up the hill?</p>
<div class="cell" data-hold="true" data-execution_count="102">
<div class="cell-output cell-output-display" data-execution_count="100">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="617212121323722552" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_617212121323722552">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_617212121323722552_1">
<input class="form-check-input" type="radio" name="radio_617212121323722552" id="radio_617212121323722552_1" value="1">
<span class="label-body px-1">
\(\langle f_x, f_y, -1 \rangle\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_617212121323722552_2">
<input class="form-check-input" type="radio" name="radio_617212121323722552" id="radio_617212121323722552_2" value="2">
<span class="label-body px-1">
\(\langle -f_x, -f_y, 1 \rangle\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_617212121323722552_3">
<input class="form-check-input" type="radio" name="radio_617212121323722552" id="radio_617212121323722552_3" value="3">
<span class="label-body px-1">
\(\langle f_x, f_y \rangle\)
</span>
</label>
</div>
</div>
</div>
<div id="617212121323722552_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_617212121323722552"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('617212121323722552_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_617212121323722552")
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_617212121323722552")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-8" class="level5">
<h5 class="anchored" data-anchor-id="question-8">Question</h5>
<p>The figure shows climbers on their way to summit Mt. Everest:</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../differentiable_vector_calculus/figures/everest.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Climbers en route to the summit of Mt. Everest</figcaption><p></p>
</figure>
</div>
<p>If the surface of the mountain is given by a function <span class="math inline">\(z=f(x,y)\)</span> then the climbers move along a single path parameterized, say, by <span class="math inline">\(\vec{\gamma}(t) = \langle x(t), y(t)\rangle\)</span>, as set up by the Sherpas.</p>
<p>Consider the composition <span class="math inline">\((f\circ\vec\gamma)(t)\)</span>.</p>
<p>For a climber with GPS coordinates <span class="math inline">\((x,y)\)</span>. What describes her elevation?</p>
<div class="cell" data-hold="true" data-execution_count="104">
<div class="cell-output cell-output-display" data-execution_count="102">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="613849687531448589" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_613849687531448589">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_613849687531448589_1">
<input class="form-check-input" type="radio" name="radio_613849687531448589" id="radio_613849687531448589_1" value="1">
<span class="label-body px-1">
\(\vec\gamma(x,y)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_613849687531448589_2">
<input class="form-check-input" type="radio" name="radio_613849687531448589" id="radio_613849687531448589_2" value="2">
<span class="label-body px-1">
\((f\circ\vec\gamma)(x,y)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_613849687531448589_3">
<input class="form-check-input" type="radio" name="radio_613849687531448589" id="radio_613849687531448589_3" value="3">
<span class="label-body px-1">
\(f(x,y)\)
</span>
</label>
</div>
</div>
</div>
<div id="613849687531448589_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_613849687531448589"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('613849687531448589_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_613849687531448589")
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_613849687531448589")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>A climber leaves base camp at <span class="math inline">\(t_0\)</span>. At time <span class="math inline">\(t &gt; t_0\)</span>, what describes her elevation?</p>
<div class="cell" data-hold="true" data-execution_count="105">
<div class="cell-output cell-output-display" data-execution_count="103">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="1919604464676527750" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_1919604464676527750">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_1919604464676527750_1">
<input class="form-check-input" type="radio" name="radio_1919604464676527750" id="radio_1919604464676527750_1" value="1">
<span class="label-body px-1">
\(f(t)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1919604464676527750_2">
<input class="form-check-input" type="radio" name="radio_1919604464676527750" id="radio_1919604464676527750_2" value="2">
<span class="label-body px-1">
\((f\circ\vec\gamma)(t)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1919604464676527750_3">
<input class="form-check-input" type="radio" name="radio_1919604464676527750" id="radio_1919604464676527750_3" value="3">
<span class="label-body px-1">
\(\vec\gamma(t)\)
</span>
</label>
</div>
</div>
</div>
<div id="1919604464676527750_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_1919604464676527750"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('1919604464676527750_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_1919604464676527750")
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_1919604464676527750")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>What does the vector-valued function <span class="math inline">\(\vec{r}(t) = \langle x(t), y(t), (f\circ\vec\gamma(t))\rangle\)</span> describe:</p>
<div class="cell" data-hold="true" data-execution_count="106">
<div class="cell-output cell-output-display" data-execution_count="104">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="11023649502562542648" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_11023649502562542648">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_11023649502562542648_1">
<input class="form-check-input" type="radio" name="radio_11023649502562542648" id="radio_11023649502562542648_1" value="1">
<span class="label-body px-1">
The climbers gradient, pointing in the direction of greatest ascent
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_11023649502562542648_2">
<input class="form-check-input" type="radio" name="radio_11023649502562542648" id="radio_11023649502562542648_2" value="2">
<span class="label-body px-1">
The three dimensional position of the climber
</span>
</label>
</div>
</div>
</div>
<div id="11023649502562542648_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_11023649502562542648"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('11023649502562542648_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_11023649502562542648")
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_11023649502562542648")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>In the figure, the climbers are making a switch back, so as to avoid the steeper direct ascent. Mathematically <span class="math inline">\(\nabla{f}(\vec\gamma(t)) \cdot \vec\gamma'(t)\)</span> describes the directional derivative that they follow. Using <span class="math inline">\(\|\vec{u}\cdot\vec{v}\| = \|\vec{u}\|\|\vec{v}\|\cos(\theta)\)</span>, does this route:</p>
<div class="cell" data-hold="true" data-execution_count="107">
<div class="cell-output cell-output-display" data-execution_count="105">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="7304091345220701471" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_7304091345220701471">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_7304091345220701471_1">
<input class="form-check-input" type="radio" name="radio_7304091345220701471" id="radio_7304091345220701471_1" value="1">
<span class="label-body px-1">
Keep \(\cos(\theta)\) as close to \(1\) as possible, so the slope taken is as big as possible
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7304091345220701471_2">
<input class="form-check-input" type="radio" name="radio_7304091345220701471" id="radio_7304091345220701471_2" value="2">
<span class="label-body px-1">
Keep \(̧\cos(\theta)\) as close to \(0\) as possible, so that they climbers don't waste energy going up and down
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7304091345220701471_3">
<input class="form-check-input" type="radio" name="radio_7304091345220701471" id="radio_7304091345220701471_3" value="3">
<span class="label-body px-1">
Keep \(\cos(\theta)\) smaller than \(1\), so that the slope taken is not too great
</span>
</label>
</div>
</div>
</div>
<div id="7304091345220701471_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_7304091345220701471"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('7304091345220701471_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_7304091345220701471")
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_7304091345220701471")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Suppose our climber reaches the top at time <span class="math inline">\(t\)</span>. What would be <span class="math inline">\((f\circ\vec\gamma)'(t)\)</span>, assuming the derivative exists?</p>
<div class="cell" data-hold="true" data-execution_count="108">
<div class="cell-output cell-output-display" data-execution_count="106">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="8429902045133019667" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_8429902045133019667">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_8429902045133019667_1">
<input class="form-check-input" type="radio" name="radio_8429902045133019667" id="radio_8429902045133019667_1" value="1">
<span class="label-body px-1">
It would not exist, as there would not be enough oxygen to compute it
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_8429902045133019667_2">
<input class="form-check-input" type="radio" name="radio_8429902045133019667" id="radio_8429902045133019667_2" value="2">
<span class="label-body px-1">
It would be \(\langle f_x, f_y\rangle\) and point towards the sky, the direction of greatest ascent
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_8429902045133019667_3">
<input class="form-check-input" type="radio" name="radio_8429902045133019667" id="radio_8429902045133019667_3" value="3">
<span class="label-body px-1">
It would be \(0\), as the top would be maximum for \(f\circ\vec\gamma\)
</span>
</label>
</div>
</div>
</div>
<div id="8429902045133019667_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_8429902045133019667"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('8429902045133019667_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_8429902045133019667")
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_8429902045133019667")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<section id="question-9" class="level6">
<h6 class="anchored" data-anchor-id="question-9">Question</h6>
<p>Building sustainable hiking trails involves proper water management. Two rules of thumb are 1) the trail should not be steeper than 10 degrees 2) the outward slope (in the steepest downhill direction) should be around 5%. (A trail tread is not flat, but rather sloped downward, similar to the crown on a road, so that water will run to the downhill side of the tread, not along the tread, which would cause erosion. In the best possible world, the outslope will exceed the downward slope.)</p>
<p>Suppose a trail height is described parametrically by a composition <span class="math inline">\((f \circ \vec\gamma)(t))\)</span>, where <span class="math inline">\(\vec\gamma(t) = \langle x(t),y(t)\rangle\)</span>. The vector <span class="math inline">\(\vec{T}(t) = \langle x(t), y(t), \nabla{f}(\vec\gamma(t)) \rangle\)</span> describes the tangent to the trail at a point (<span class="math inline">\(\vec\gamma(t)\)</span>). Let <span class="math inline">\(\hat{T}(t)\)</span> be the unit normal, and <span class="math inline">\(\hat{P}(t)\)</span> be a unit normal in the direction of the <em>projection</em> of <span class="math inline">\(\vec{T}\)</span> onto the <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span> plane. (Make the third component of <span class="math inline">\(\vec{T}\)</span> <span class="math inline">\(0\)</span>, and then form a unit vector from that.)</p>
<p>What expression below captures point 1 that the steepness should be no more than 10 degrees (<span class="math inline">\(\pi/18\)</span> radians):</p>
<div class="cell" data-hold="true" data-execution_count="109">
<div class="cell-output cell-output-display" data-execution_count="107">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12427471954024938019" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_12427471954024938019">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_12427471954024938019_1">
<input class="form-check-input" type="radio" name="radio_12427471954024938019" id="radio_12427471954024938019_1" value="1">
<span class="label-body px-1">
\(|\hat{T} \cdot \hat{P}| \leq \pi/18\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12427471954024938019_2">
<input class="form-check-input" type="radio" name="radio_12427471954024938019" id="radio_12427471954024938019_2" value="2">
<span class="label-body px-1">
\(|\hat{T} \cdot \hat{P}| \leq \sin(\pi/18)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12427471954024938019_3">
<input class="form-check-input" type="radio" name="radio_12427471954024938019" id="radio_12427471954024938019_3" value="3">
<span class="label-body px-1">
\(|\hat{T} \cdot \hat{P}| \leq \cos(π/18)\)
</span>
</label>
</div>
</div>
</div>
<div id="12427471954024938019_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_12427471954024938019"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('12427471954024938019_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_12427471954024938019")
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_12427471954024938019")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>The normal to the surface <span class="math inline">\(z=f(x,y)\)</span> is <em>not</em> the normal to the trail tread. Suppose <span class="math inline">\(\vec{N}(t)\)</span> is a function that returns this. At the same point <span class="math inline">\(\vec\gamma(t)\)</span>, let <span class="math inline">\(\vec{M} = \langle -f_x, -f_y, 0\rangle\)</span> be a vector in 3 dimensions pointing downhill. Let “hats” indicate unit vectors. The outward slope is <span class="math inline">\(\pi/2\)</span> minus the angle between <span class="math inline">\(\hat{N}\)</span> and <span class="math inline">\(\hat{M}\)</span>. What condition will ensure this angle is <span class="math inline">\(5\)</span> degrees (<span class="math inline">\(\pi/36\)</span> radians)?</p>
<div class="cell" data-hold="true" data-execution_count="110">
<div class="cell-output cell-output-display" data-execution_count="108">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="14397335900479322472" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_14397335900479322472">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_14397335900479322472_1">
<input class="form-check-input" type="radio" name="radio_14397335900479322472" id="radio_14397335900479322472_1" value="1">
<span class="label-body px-1">
\(|\hat{N} \cdot \hat{M}| \leq \sin(\pi/2 - \pi/18)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14397335900479322472_2">
<input class="form-check-input" type="radio" name="radio_14397335900479322472" id="radio_14397335900479322472_2" value="2">
<span class="label-body px-1">
\(|\hat{N} \cdot \hat{M}| \leq \pi/2 - \pi/18\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14397335900479322472_3">
<input class="form-check-input" type="radio" name="radio_14397335900479322472" id="radio_14397335900479322472_3" value="3">
<span class="label-body px-1">
\(|\hat{N} \cdot \hat{M}| \leq \cos(\pi/2 - π/36)\)
</span>
</label>
</div>
</div>
</div>
<div id="14397335900479322472_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_14397335900479322472"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('14397335900479322472_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_14397335900479322472")
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_14397335900479322472")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-10" class="level6">
<h6 class="anchored" data-anchor-id="question-10">Question</h6>
<p>Let <span class="math inline">\(f(x,y) = x^2 \cdot(x - y^2)\)</span>. Let <span class="math inline">\(\vec{v} = \langle 1, 2\rangle\)</span>. Find the directional derivative in the direction of <span class="math inline">\(\vec{v}\)</span>.</p>
<div class="cell" data-hold="true" data-execution_count="111">
<div class="cell-output cell-output-display" data-execution_count="109">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="16001079384072546742" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_16001079384072546742">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_16001079384072546742_1">
<input class="form-check-input" type="radio" name="radio_16001079384072546742" id="radio_16001079384072546742_1" value="1">
<span class="label-body px-1">
\(2 \cos{\left (3 \right )} - 7 \sin{\left (3 \right )}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_16001079384072546742_2">
<input class="form-check-input" type="radio" name="radio_16001079384072546742" id="radio_16001079384072546742_2" value="2">
<span class="label-body px-1">
\(4 x^{2} y \sin{\left (x - y^{2} \right )} - x^{2} \sin{\left (x - y^{2} \right )} + 2 x \cos{\left (x - y^{2} \right )}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_16001079384072546742_3">
<input class="form-check-input" type="radio" name="radio_16001079384072546742" id="radio_16001079384072546742_3" value="3">
<span class="label-body px-1">
\(\frac{\sqrt{5}}{5}\left(2 \cos{\left (3 \right )} - 7 \sin{\left (3 \right )}\right)\)
</span>
</label>
</div>
</div>
</div>
<div id="16001079384072546742_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_16001079384072546742"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('16001079384072546742_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_16001079384072546742")
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_16001079384072546742")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-11" class="level6">
<h6 class="anchored" data-anchor-id="question-11">Question</h6>
<p>Let <span class="math inline">\(\vec{v}\)</span> be any non-zero vector. Does <span class="math inline">\(\nabla{f}(\vec{x})\cdot\vec{v}\)</span> give the rate of increase of <span class="math inline">\(f\)</span> per unit of distance in the direction of <span class="math inline">\(\vec{v}\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="112">
<div class="cell-output cell-output-display" data-execution_count="110">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="465183603094766935" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_465183603094766935">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_465183603094766935_1">
<input class="form-check-input" type="radio" name="radio_465183603094766935" id="radio_465183603094766935_1" value="1">
<span class="label-body px-1">
No, not unless \(\vec{v}\) were a unit vector
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_465183603094766935_2">
<input class="form-check-input" type="radio" name="radio_465183603094766935" id="radio_465183603094766935_2" value="2">
<span class="label-body px-1">
Yes, by definition
</span>
</label>
</div>
</div>
</div>
<div id="465183603094766935_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_465183603094766935"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('465183603094766935_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_465183603094766935")
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_465183603094766935")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-12" class="level6">
<h6 class="anchored" data-anchor-id="question-12">Question</h6>
<p>Let <span class="math inline">\(f(x,y,z) = x^4 + 2xz + 2xy + y^4\)</span> and <span class="math inline">\(\vec\gamma(t) = \langle t, t^2, t^3\rangle\)</span>. Using the chain rule, compute <span class="math inline">\((f\circ\vec\gamma)'(t)\)</span>.</p>
<p>The value of <span class="math inline">\(\nabla{f}(x,y,z)\)</span> is</p>
<div class="cell" data-hold="true" data-execution_count="113">
<div class="cell-output cell-output-display" data-execution_count="111">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="8792854167338804053" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_8792854167338804053">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_8792854167338804053_1">
<input class="form-check-input" type="radio" name="radio_8792854167338804053" id="radio_8792854167338804053_1" value="1">
<span class="label-body px-1">
\(\langle 4x^3, 2z, 2y\rangle\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_8792854167338804053_2">
<input class="form-check-input" type="radio" name="radio_8792854167338804053" id="radio_8792854167338804053_2" value="2">
<span class="label-body px-1">
\(\langle x^3 + 2x + 2x, 2y+ y^3, 2x\rangle\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_8792854167338804053_3">
<input class="form-check-input" type="radio" name="radio_8792854167338804053" id="radio_8792854167338804053_3" value="3">
<span class="label-body px-1">
\(\langle 4x^3 + 2x + 2y, 2x + 4y^3, 2x \rangle\)
</span>
</label>
</div>
</div>
</div>
<div id="8792854167338804053_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_8792854167338804053"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('8792854167338804053_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_8792854167338804053")
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_8792854167338804053")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>The value of <span class="math inline">\(\vec\gamma'(t)\)</span> is:</p>
<div class="cell" data-hold="true" data-execution_count="114">
<div class="cell-output cell-output-display" data-execution_count="112">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="2059675719239306637" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_2059675719239306637">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_2059675719239306637_1">
<input class="form-check-input" type="radio" name="radio_2059675719239306637" id="radio_2059675719239306637_1" value="1">
<span class="label-body px-1">
\(\langle 1, 2t, 3t^2\rangle\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2059675719239306637_2">
<input class="form-check-input" type="radio" name="radio_2059675719239306637" id="radio_2059675719239306637_2" value="2">
<span class="label-body px-1">
\(1 + 2y + 3t^2\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2059675719239306637_3">
<input class="form-check-input" type="radio" name="radio_2059675719239306637" id="radio_2059675719239306637_3" value="3">
<span class="label-body px-1">
\(\langle 1,2, 3 \rangle\)
</span>
</label>
</div>
</div>
</div>
<div id="2059675719239306637_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_2059675719239306637"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('2059675719239306637_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_2059675719239306637")
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_2059675719239306637")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>The value of <span class="math inline">\((f\circ\vec\gamma)'(t)\)</span> is found by:</p>
<div class="cell" data-hold="true" data-execution_count="115">
<div class="cell-output cell-output-display" data-execution_count="113">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="16224648008014111976" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_16224648008014111976">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_16224648008014111976_1">
<input class="form-check-input" type="radio" name="radio_16224648008014111976" id="radio_16224648008014111976_1" value="1">
<span class="label-body px-1">
Taking the dot product of \(\nabla{f}(x,y,z)\) and \(\vec\gamma'(t)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_16224648008014111976_2">
<input class="form-check-input" type="radio" name="radio_16224648008014111976" id="radio_16224648008014111976_2" value="2">
<span class="label-body px-1">
Taking the dot product of \(\nabla{f}(\vec\gamma'(t))\) and \(\vec\gamma(t)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_16224648008014111976_3">
<input class="form-check-input" type="radio" name="radio_16224648008014111976" id="radio_16224648008014111976_3" value="3">
<span class="label-body px-1">
Taking the dot product of \(\nabla{f}(\vec\gamma(t))\) and \(\vec\gamma'(t)\)
</span>
</label>
</div>
</div>
</div>
<div id="16224648008014111976_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_16224648008014111976"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('16224648008014111976_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_16224648008014111976")
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_16224648008014111976")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-13" class="level6">
<h6 class="anchored" data-anchor-id="question-13">Question</h6>
<p>Let <span class="math inline">\(z = f(x,y)\)</span> be some unknown function,</p>
<p>From the figure, which drawn vector is the gradient at <span class="math inline">\((1/2, -3/4)\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="116">
<div class="cell-output cell-output-display" data-execution_count="114">
<p><img src="scalar_functions_files/figure-html/cell-117-output-1.svg" class="img-fluid"></p>
</div>
</div>
<div class="cell" data-hold="true" data-execution_count="117">
<div class="cell-output cell-output-display" data-execution_count="115">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="11134780556669551561" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_11134780556669551561">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_11134780556669551561_1">
<input class="form-check-input" type="radio" name="radio_11134780556669551561" id="radio_11134780556669551561_1" value="1">
<span class="label-body px-1">
The red one
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_11134780556669551561_2">
<input class="form-check-input" type="radio" name="radio_11134780556669551561" id="radio_11134780556669551561_2" value="2">
<span class="label-body px-1">
The green one
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_11134780556669551561_3">
<input class="form-check-input" type="radio" name="radio_11134780556669551561" id="radio_11134780556669551561_3" value="3">
<span class="label-body px-1">
The blue one
</span>
</label>
</div>
</div>
</div>
<div id="11134780556669551561_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_11134780556669551561"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('11134780556669551561_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_11134780556669551561")
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_11134780556669551561")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>From the figure, which drawn vector is the gradient as <span class="math inline">\((1/2, -3/4)\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="118">
<div class="cell-output cell-output-display" data-execution_count="116">
<p><img src="scalar_functions_files/figure-html/cell-119-output-1.svg" class="img-fluid"></p>
</div>
</div>
<div class="cell" data-hold="true" data-execution_count="119">
<div class="cell-output cell-output-display" data-execution_count="117">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12656510358181418416" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_12656510358181418416">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_12656510358181418416_1">
<input class="form-check-input" type="radio" name="radio_12656510358181418416" id="radio_12656510358181418416_1" value="1">
<span class="label-body px-1">
The blue one
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12656510358181418416_2">
<input class="form-check-input" type="radio" name="radio_12656510358181418416" id="radio_12656510358181418416_2" value="2">
<span class="label-body px-1">
The red one
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12656510358181418416_3">
<input class="form-check-input" type="radio" name="radio_12656510358181418416" id="radio_12656510358181418416_3" value="3">
<span class="label-body px-1">
The green one
</span>
</label>
</div>
</div>
</div>
<div id="12656510358181418416_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_12656510358181418416"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('12656510358181418416_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_12656510358181418416")
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_12656510358181418416")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-14" class="level6">
<h6 class="anchored" data-anchor-id="question-14">Question</h6>
<p>For a function <span class="math inline">\(f(x,y)\)</span> and a point (as a vector, <span class="math inline">\(\vec{c}\)</span>) we consider this derived function:</p>
<p><span class="math display">\[
g(\vec{x}) = f(\vec{c}) + \nabla{f}(\vec{c}) \cdot(\vec{x} - \vec{c}) + \frac{1}{2}(\vec{x} - \vec{c})^tH(\vec{c})(\vec{x} - \vec{c}),
\]</span></p>
<p>where <span class="math inline">\(H(\vec{c})\)</span> is the Hessian.</p>
<p>Further, <em>suppose</em> <span class="math inline">\(\nabla{f}(\vec{c}) = \vec{0}\)</span>, so in fact:</p>
<p><span class="math display">\[
g(\vec{x}) = f(\vec{c}) + \frac{1}{2}(\vec{x} - \vec{c})^tH(\vec{c})(\vec{x} - \vec{c}).
\]</span></p>
<p>If <span class="math inline">\(f\)</span> is a linear function at <span class="math inline">\(\vec{c}\)</span>, what does this say about <span class="math inline">\(g\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="120">
<div class="cell-output cell-output-display" data-execution_count="118">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="4353832264766428554" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_4353832264766428554">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_4353832264766428554_1">
<input class="form-check-input" type="radio" name="radio_4353832264766428554" id="radio_4353832264766428554_1" value="1">
<span class="label-body px-1">
Linear means \(H\) is the \(0\) matrix, so the gradient couldn't have been \(\vec{0}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4353832264766428554_2">
<input class="form-check-input" type="radio" name="radio_4353832264766428554" id="radio_4353832264766428554_2" value="2">
<span class="label-body px-1">
Linear means \(H\) is the \(0\) matrix, so \(g(\vec{x})\) is the constant \(f(\vec{c})\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4353832264766428554_3">
<input class="form-check-input" type="radio" name="radio_4353832264766428554" id="radio_4353832264766428554_3" value="3">
<span class="label-body px-1">
Linear means \(H\) is linear, so \(g(\vec{x})\) describes a plane
</span>
</label>
</div>
</div>
</div>
<div id="4353832264766428554_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_4353832264766428554"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('4353832264766428554_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_4353832264766428554")
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_4353832264766428554")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Suppose, <span class="math inline">\(H\)</span> has the magic property that for <em>any</em> vector <span class="math inline">\(\vec{v}^tH\vec{v} &lt; 0\)</span>. What does this imply:</p>
<div class="cell" data-hold="true" data-execution_count="121">
<div class="cell-output cell-output-display" data-execution_count="119">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="10042560973931259539" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_10042560973931259539">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_10042560973931259539_1">
<input class="form-check-input" type="radio" name="radio_10042560973931259539" id="radio_10042560973931259539_1" value="1">
<span class="label-body px-1">
That \(g(\vec{x}) \geq f(\vec{c})\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_10042560973931259539_2">
<input class="form-check-input" type="radio" name="radio_10042560973931259539" id="radio_10042560973931259539_2" value="2">
<span class="label-body px-1">
That \(g(\vec{x}) = f(\vec{c})\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_10042560973931259539_3">
<input class="form-check-input" type="radio" name="radio_10042560973931259539" id="radio_10042560973931259539_3" value="3">
<span class="label-body px-1">
That \(g(\vec{x}) \leq f(\vec{c})\)
</span>
</label>
</div>
</div>
</div>
<div id="10042560973931259539_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_10042560973931259539"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('10042560973931259539_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_10042560973931259539")
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_10042560973931259539")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-15" class="level6">
<h6 class="anchored" data-anchor-id="question-15">Question</h6>
<p>Let <span class="math inline">\(f(x,y) = x^3y^3\)</span>. Which partial derivative is identically <span class="math inline">\(0\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="122">
<div class="cell-output cell-output-display" data-execution_count="120">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="6745041520390343798" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_6745041520390343798">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_6745041520390343798_1">
<input class="form-check-input" type="radio" name="radio_6745041520390343798" id="radio_6745041520390343798_1" value="1">
<span class="label-body px-1">
\(\partial^4{f}/\partial{x^4}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6745041520390343798_2">
<input class="form-check-input" type="radio" name="radio_6745041520390343798" id="radio_6745041520390343798_2" value="2">
<span class="label-body px-1">
\(\partial^4{f}/\partial{x^3}\partial{y}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6745041520390343798_3">
<input class="form-check-input" type="radio" name="radio_6745041520390343798" id="radio_6745041520390343798_3" value="3">
<span class="label-body px-1">
\(\partial^4{f}/\partial{x^2}\partial{y^2}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6745041520390343798_4">
<input class="form-check-input" type="radio" name="radio_6745041520390343798" id="radio_6745041520390343798_4" value="4">
<span class="label-body px-1">
\(\partial^4{f}/\partial{x^1}\partial{y^3}\)
</span>
</label>
</div>
</div>
</div>
<div id="6745041520390343798_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_6745041520390343798"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('6745041520390343798_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_6745041520390343798")
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_6745041520390343798")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-16" class="level6">
<h6 class="anchored" data-anchor-id="question-16">Question</h6>
<p>Let <span class="math inline">\(f(x,y) = 3x^2 y\)</span>.</p>
<p>Which value is greater at the point <span class="math inline">\((1/2,2)\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="123">
<div class="cell-output cell-output-display" data-execution_count="121">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15515609716899502252" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_15515609716899502252">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_15515609716899502252_1">
<input class="form-check-input" type="radio" name="radio_15515609716899502252" id="radio_15515609716899502252_1" value="1">
<span class="label-body px-1">
\(f_x\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_15515609716899502252_2">
<input class="form-check-input" type="radio" name="radio_15515609716899502252" id="radio_15515609716899502252_2" value="2">
<span class="label-body px-1">
\(f_y\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_15515609716899502252_3">
<input class="form-check-input" type="radio" name="radio_15515609716899502252" id="radio_15515609716899502252_3" value="3">
<span class="label-body px-1">
\(f_{xx}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_15515609716899502252_4">
<input class="form-check-input" type="radio" name="radio_15515609716899502252" id="radio_15515609716899502252_4" value="4">
<span class="label-body px-1">
\(f_{xy}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_15515609716899502252_5">
<input class="form-check-input" type="radio" name="radio_15515609716899502252" id="radio_15515609716899502252_5" value="5">
<span class="label-body px-1">
\(f_{yy}\)
</span>
</label>
</div>
</div>
</div>
<div id="15515609716899502252_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_15515609716899502252"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('15515609716899502252_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_15515609716899502252")
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_15515609716899502252")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-17" class="level6">
<h6 class="anchored" data-anchor-id="question-17">Question</h6>
<p>The order of partial derivatives matters if the mixed partials are not continuous. Take</p>
<p><span class="math display">\[
f(x,y) = \frac{xy ( x^2 - y^2)}{x^2 + y^2}, \quad f(0,0) = 0
\]</span></p>
<p>Using the definition of the derivative from a limit, we have</p>
<p><span class="math display">\[
\frac{\partial \frac{\partial f}{\partial x}}{ \partial y} =
\lim_{\Delta y \rightarrow 0} \lim_{\Delta x \rightarrow 0}
\frac{f(x+\Delta x, y + \Delta y) - f(x, y+\Delta{y}) - f(x+\Delta x,y) + f(x,y)}{\Delta x \Delta y}.
\]</span></p>
<p>Whereas,</p>
<p><span class="math display">\[
\frac{\partial \frac{\partial f}{\partial y}}{ \partial x} =
\lim_{\Delta x \rightarrow 0} \lim_{\Delta y \rightarrow 0}
\frac{f(x+\Delta x, y + \Delta y) - f(x, y+\Delta{y}) - f(x+\Delta x,y) + f(x,y)}{\Delta x \Delta y}.
\]</span></p>
<p>At <span class="math inline">\((0,0)\)</span> what is $ $?</p>
<div class="cell" data-hold="true" data-execution_count="124">
<div class="cell-output cell-output-display" data-execution_count="122">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="14685159227922396948" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_14685159227922396948">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="14685159227922396948" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="14685159227922396948_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("14685159227922396948").addEventListener("change", function() {
var correct = (Math.abs(this.value - -1) <= 0);
var msgBox = document.getElementById('14685159227922396948_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_14685159227922396948")
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_14685159227922396948")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>At <span class="math inline">\((0,0)\)</span> what is $ $?</p>
<div class="cell" data-hold="true" data-execution_count="125">
<div class="cell-output cell-output-display" data-execution_count="123">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15032886581957936041" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_15032886581957936041">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="15032886581957936041" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="15032886581957936041_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("15032886581957936041").addEventListener("change", function() {
var correct = (Math.abs(this.value - 1) <= 0);
var msgBox = document.getElementById('15032886581957936041_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_15032886581957936041")
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_15032886581957936041")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>Away from <span class="math inline">\((0,0)\)</span> the mixed partial is <span class="math inline">\(\frac{x^{6} + 9 x^{4} y^{2} - 9 x^{2} y^{4} - y^{6}}{x^{6} + 3 x^{4} y^{2} + 3 x^{2} y^{4} + y^{6}}\)</span>.</p>
<div class="cell" data-hold="true" data-execution_count="126">
<div class="cell-output cell-output-display" data-execution_count="124">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="16518582389680812671" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_16518582389680812671">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_16518582389680812671_1">
<input class="form-check-input" type="radio" name="radio_16518582389680812671" id="radio_16518582389680812671_1" value="1">
<span class="label-body px-1">
This is not continuous at \((0,0)\), still the limit along the two paths \(x=0\) and \(y=0\) are equivalent.
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_16518582389680812671_2">
<input class="form-check-input" type="radio" name="radio_16518582389680812671" id="radio_16518582389680812671_2" value="2">
<span class="label-body px-1">
This is not continuous at \((0,0)\), as the limit along the two paths \(x=0\) and \(y=0\) are not equivalent.
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_16518582389680812671_3">
<input class="form-check-input" type="radio" name="radio_16518582389680812671" id="radio_16518582389680812671_3" value="3">
<span class="label-body px-1">
As this is the ratio of continuous functions, it is continuous at the origin
</span>
</label>
</div>
</div>
</div>
<div id="16518582389680812671_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_16518582389680812671"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('16518582389680812671_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_16518582389680812671")
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_16518582389680812671")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-18" class="level6">
<h6 class="anchored" data-anchor-id="question-18">Question</h6>
<p><a href="http://www.math.harvard.edu/~knill/teaching/summer2018/handouts/week3.pdf">Knill</a>. Clairauts theorem is the name given to the fact that if the partial derivatives are continuous, the mixed partials are equal, <span class="math inline">\(f_{xy} = f_{yx}\)</span>.</p>
<p>Consider the following code which computes the mixed partials for the discrete derivative:</p>
<div class="cell" data-hold="true" data-execution_count="127">
<div class="sourceCode cell-code" id="cb100"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb100-1"><a href="#cb100-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> x<span class="op">::</span><span class="dt">real </span>y<span class="op">::</span><span class="dt">real </span>Δ<span class="op">::</span><span class="dt">real </span><span class="fu">G</span>()</span>
<span id="cb100-2"><a href="#cb100-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb100-3"><a href="#cb100-3" aria-hidden="true" tabindex="-1"></a><span class="fu">Dx</span>(f,h) <span class="op">=</span> (<span class="fu">subs</span>(f, x<span class="op">=&gt;</span>x<span class="op">+</span>h) <span class="op">-</span> f)<span class="op">/</span>h</span>
<span id="cb100-4"><a href="#cb100-4" aria-hidden="true" tabindex="-1"></a><span class="fu">Dy</span>(f,h) <span class="op">=</span> (<span class="fu">subs</span>(f, y<span class="op">=&gt;</span>y<span class="op">+</span>h) <span class="op">-</span> f)<span class="op">/</span>h</span>
<span id="cb100-5"><a href="#cb100-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb100-6"><a href="#cb100-6" aria-hidden="true" tabindex="-1"></a><span class="fu">Dy</span>(<span class="fu">Dx</span>(<span class="fu">G</span>(x,y), Δ), Δ) <span class="op">-</span> <span class="fu">Dx</span>(<span class="fu">Dy</span>(<span class="fu">G</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="125">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
- \frac{- \frac{- G{\left(x,y \right)} + G{\left(x,y + Δ \right)}}{Δ} + \frac{- G{\left(x + Δ,y \right)} + G{\left(x + Δ,y + Δ \right)}}{Δ}}{Δ} + \frac{- \frac{- G{\left(x,y \right)} + G{\left(x + Δ,y \right)}}{Δ} + \frac{- G{\left(x,y + Δ \right)} + G{\left(x + Δ,y + Δ \right)}}{Δ}}{Δ}
\]
</span>
</div>
</div>
<p>What does this simplify to?</p>
<div class="cell" data-hold="true" data-execution_count="128">
<div class="cell-output cell-output-display" data-execution_count="126">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15618677061190170328" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_15618677061190170328">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="15618677061190170328" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="15618677061190170328_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("15618677061190170328").addEventListener("change", function() {
var correct = (Math.abs(this.value - 0) <= 0);
var msgBox = document.getElementById('15618677061190170328_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_15618677061190170328")
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_15618677061190170328")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>Is continuity required for this to be true?</p>
<div class="cell" data-hold="true" data-execution_count="129">
<div class="cell-output cell-output-display" data-execution_count="127">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="4744812119589472346" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_4744812119589472346">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_4744812119589472346_1">
<input class="form-check-input" type="radio" name="radio_4744812119589472346" id="radio_4744812119589472346_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4744812119589472346_2">
<input class="form-check-input" type="radio" name="radio_4744812119589472346" id="radio_4744812119589472346_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="4744812119589472346_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_4744812119589472346"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('4744812119589472346_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_4744812119589472346")
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_4744812119589472346")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-19" class="level6">
<h6 class="anchored" data-anchor-id="question-19">Question</h6>
<p>(Examples and descriptions from Krill)</p>
<p>What equation does the function <span class="math inline">\(f(x,y) = x^3 - 3xy^2\)</span> satisfy?</p>
<div class="cell" data-execution_count="130">
<div class="cell-output cell-output-display" data-execution_count="128">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="14612048179978979834" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_14612048179978979834">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_14612048179978979834_1">
<input class="form-check-input" type="radio" name="radio_14612048179978979834" id="radio_14612048179978979834_1" value="1">
<span class="label-body px-1">
The wave equation: \(f_{tt} = f_{xx}\); governs motion of light or sound
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14612048179978979834_2">
<input class="form-check-input" type="radio" name="radio_14612048179978979834" id="radio_14612048179978979834_2" value="2">
<span class="label-body px-1">
The heat equation: \(f_t = f_{xx}\); describes diffusion of heat
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14612048179978979834_3">
<input class="form-check-input" type="radio" name="radio_14612048179978979834" id="radio_14612048179978979834_3" value="3">
<span class="label-body px-1">
The Laplace equation: \(f_{xx} + f_{yy} = 0\); determines shape of a membrane
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14612048179978979834_4">
<input class="form-check-input" type="radio" name="radio_14612048179978979834" id="radio_14612048179978979834_4" value="4">
<span class="label-body px-1">
The advection equation: \(f_t = f_x\); is used to model transport in a wire
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14612048179978979834_5">
<input class="form-check-input" type="radio" name="radio_14612048179978979834" id="radio_14612048179978979834_5" value="5">
<span class="label-body px-1">
The eiconal equation: \(f_x^2 + f_y^2 = 1\); is used to model evolution of a wave front in optics
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14612048179978979834_6">
<input class="form-check-input" type="radio" name="radio_14612048179978979834" id="radio_14612048179978979834_6" value="6">
<span class="label-body px-1">
The Burgers equation: \(f_t + ff_x = f_{xx}\); describes waves at the beach which break
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14612048179978979834_7">
<input class="form-check-input" type="radio" name="radio_14612048179978979834" id="radio_14612048179978979834_7" value="7">
<span class="label-body px-1">
The KdV equation: \(f_t + 6ff_x+ f_{xxx} = 0\); models water waves in a narrow channel
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14612048179978979834_8">
<input class="form-check-input" type="radio" name="radio_14612048179978979834" id="radio_14612048179978979834_8" value="8">
<span class="label-body px-1">
The Schrodinger equation: \(f_t = (i\hbar/(2m))f_xx\); used to describe a quantum particle of mass \(m\)
</span>
</label>
</div>
</div>
</div>
<div id="14612048179978979834_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_14612048179978979834"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('14612048179978979834_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_14612048179978979834")
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_14612048179978979834")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>What equation does the function <span class="math inline">\(f(t, x) = sin(x-t) + sin(x+t)\)</span> satisfy?</p>
<div class="cell" data-hold="true" data-execution_count="131">
<div class="cell-output cell-output-display" data-execution_count="129">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="5806098301408463761" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_5806098301408463761">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_5806098301408463761_1">
<input class="form-check-input" type="radio" name="radio_5806098301408463761" id="radio_5806098301408463761_1" value="1">
<span class="label-body px-1">
The wave equation: \(f_{tt} = f_{xx}\); governs motion of light or sound
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5806098301408463761_2">
<input class="form-check-input" type="radio" name="radio_5806098301408463761" id="radio_5806098301408463761_2" value="2">
<span class="label-body px-1">
The heat equation: \(f_t = f_{xx}\); describes diffusion of heat
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5806098301408463761_3">
<input class="form-check-input" type="radio" name="radio_5806098301408463761" id="radio_5806098301408463761_3" value="3">
<span class="label-body px-1">
The Laplace equation: \(f_{xx} + f_{yy} = 0\); determines shape of a membrane
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5806098301408463761_4">
<input class="form-check-input" type="radio" name="radio_5806098301408463761" id="radio_5806098301408463761_4" value="4">
<span class="label-body px-1">
The advection equation: \(f_t = f_x\); is used to model transport in a wire
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5806098301408463761_5">
<input class="form-check-input" type="radio" name="radio_5806098301408463761" id="radio_5806098301408463761_5" value="5">
<span class="label-body px-1">
The eiconal equation: \(f_x^2 + f_y^2 = 1\); is used to model evolution of a wave front in optics
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5806098301408463761_6">
<input class="form-check-input" type="radio" name="radio_5806098301408463761" id="radio_5806098301408463761_6" value="6">
<span class="label-body px-1">
The Burgers equation: \(f_t + ff_x = f_{xx}\); describes waves at the beach which break
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5806098301408463761_7">
<input class="form-check-input" type="radio" name="radio_5806098301408463761" id="radio_5806098301408463761_7" value="7">
<span class="label-body px-1">
The KdV equation: \(f_t + 6ff_x+ f_{xxx} = 0\); models water waves in a narrow channel
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5806098301408463761_8">
<input class="form-check-input" type="radio" name="radio_5806098301408463761" id="radio_5806098301408463761_8" value="8">
<span class="label-body px-1">
The Schrodinger equation: \(f_t = (i\hbar/(2m))f_xx\); used to describe a quantum particle of mass \(m\)
</span>
</label>
</div>
</div>
</div>
<div id="5806098301408463761_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_5806098301408463761"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('5806098301408463761_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_5806098301408463761")
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_5806098301408463761")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>What equation does the function <span class="math inline">\(f(t, x) = e^{-(x+t)^2}\)</span> satisfy?</p>
<div class="cell" data-hold="true" data-execution_count="132">
<div class="cell-output cell-output-display" data-execution_count="130">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="1166259894140320945" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_1166259894140320945">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_1166259894140320945_1">
<input class="form-check-input" type="radio" name="radio_1166259894140320945" id="radio_1166259894140320945_1" value="1">
<span class="label-body px-1">
The wave equation: \(f_{tt} = f_{xx}\); governs motion of light or sound
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1166259894140320945_2">
<input class="form-check-input" type="radio" name="radio_1166259894140320945" id="radio_1166259894140320945_2" value="2">
<span class="label-body px-1">
The heat equation: \(f_t = f_{xx}\); describes diffusion of heat
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1166259894140320945_3">
<input class="form-check-input" type="radio" name="radio_1166259894140320945" id="radio_1166259894140320945_3" value="3">
<span class="label-body px-1">
The Laplace equation: \(f_{xx} + f_{yy} = 0\); determines shape of a membrane
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1166259894140320945_4">
<input class="form-check-input" type="radio" name="radio_1166259894140320945" id="radio_1166259894140320945_4" value="4">
<span class="label-body px-1">
The advection equation: \(f_t = f_x\); is used to model transport in a wire
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1166259894140320945_5">
<input class="form-check-input" type="radio" name="radio_1166259894140320945" id="radio_1166259894140320945_5" value="5">
<span class="label-body px-1">
The eiconal equation: \(f_x^2 + f_y^2 = 1\); is used to model evolution of a wave front in optics
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1166259894140320945_6">
<input class="form-check-input" type="radio" name="radio_1166259894140320945" id="radio_1166259894140320945_6" value="6">
<span class="label-body px-1">
The Burgers equation: \(f_t + ff_x = f_{xx}\); describes waves at the beach which break
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1166259894140320945_7">
<input class="form-check-input" type="radio" name="radio_1166259894140320945" id="radio_1166259894140320945_7" value="7">
<span class="label-body px-1">
The KdV equation: \(f_t + 6ff_x+ f_{xxx} = 0\); models water waves in a narrow channel
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1166259894140320945_8">
<input class="form-check-input" type="radio" name="radio_1166259894140320945" id="radio_1166259894140320945_8" value="8">
<span class="label-body px-1">
The Schrodinger equation: \(f_t = (i\hbar/(2m))f_xx\); used to describe a quantum particle of mass \(m\)
</span>
</label>
</div>
</div>
</div>
<div id="1166259894140320945_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_1166259894140320945"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 4;
var msgBox = document.getElementById('1166259894140320945_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_1166259894140320945")
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_1166259894140320945")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>What equation does the function <span class="math inline">\(f(x,y) = \cos(x) + \sin(y)\)</span> satisfy?</p>
<div class="cell" data-hold="true" data-execution_count="133">
<div class="cell-output cell-output-display" data-execution_count="131">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="5622076220283666509" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_5622076220283666509">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_5622076220283666509_1">
<input class="form-check-input" type="radio" name="radio_5622076220283666509" id="radio_5622076220283666509_1" value="1">
<span class="label-body px-1">
The wave equation: \(f_{tt} = f_{xx}\); governs motion of light or sound
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5622076220283666509_2">
<input class="form-check-input" type="radio" name="radio_5622076220283666509" id="radio_5622076220283666509_2" value="2">
<span class="label-body px-1">
The heat equation: \(f_t = f_{xx}\); describes diffusion of heat
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5622076220283666509_3">
<input class="form-check-input" type="radio" name="radio_5622076220283666509" id="radio_5622076220283666509_3" value="3">
<span class="label-body px-1">
The Laplace equation: \(f_{xx} + f_{yy} = 0\); determines shape of a membrane
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5622076220283666509_4">
<input class="form-check-input" type="radio" name="radio_5622076220283666509" id="radio_5622076220283666509_4" value="4">
<span class="label-body px-1">
The advection equation: \(f_t = f_x\); is used to model transport in a wire
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5622076220283666509_5">
<input class="form-check-input" type="radio" name="radio_5622076220283666509" id="radio_5622076220283666509_5" value="5">
<span class="label-body px-1">
The eiconal equation: \(f_x^2 + f_y^2 = 1\); is used to model evolution of a wave front in optics
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5622076220283666509_6">
<input class="form-check-input" type="radio" name="radio_5622076220283666509" id="radio_5622076220283666509_6" value="6">
<span class="label-body px-1">
The Burgers equation: \(f_t + ff_x = f_{xx}\); describes waves at the beach which break
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5622076220283666509_7">
<input class="form-check-input" type="radio" name="radio_5622076220283666509" id="radio_5622076220283666509_7" value="7">
<span class="label-body px-1">
The KdV equation: \(f_t + 6ff_x+ f_{xxx} = 0\); models water waves in a narrow channel
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5622076220283666509_8">
<input class="form-check-input" type="radio" name="radio_5622076220283666509" id="radio_5622076220283666509_8" value="8">
<span class="label-body px-1">
The Schrodinger equation: \(f_t = (i\hbar/(2m))f_xx\); used to describe a quantum particle of mass \(m\)
</span>
</label>
</div>
</div>
</div>
<div id="5622076220283666509_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_5622076220283666509"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 5;
var msgBox = document.getElementById('5622076220283666509_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_5622076220283666509")
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_5622076220283666509")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
</section>
</section>
</main> <!-- /main -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const clipboard = new window.ClipboardJS('.code-copy-button', {
target: function(trigger) {
return trigger.previousElementSibling;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
setTimeout(function() {
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
});
function tippyHover(el, contentFn) {
const config = {
allowHTML: true,
content: contentFn,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start'
};
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
let href = ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
return note.innerHTML;
});
}
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const cites = ref.parentNode.getAttribute('data-cites').split(' ');
tippyHover(ref, function() {
var popup = window.document.createElement('div');
cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
var filterRegex = new RegExp('/' + window.location.host + '/');
var isInternal = (href) => {
return filterRegex.test(href) || localhostRegex.test(href);
}
// Inspect non-navigation links and adorn them if external
var links = window.document.querySelectorAll('a:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external)');
for (var i=0; i<links.length; i++) {
const link = links[i];
if (!isInternal(link.href)) {
// target, if specified
link.setAttribute("target", "_blank");
}
}
});
</script>
<nav class="page-navigation">
<div class="nav-page nav-page-previous">
<a href="../differentiable_vector_calculus/vector_valued_functions.html" class="pagination-link">
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><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></span>
</a>
</div>
<div class="nav-page nav-page-next">
<a href="../differentiable_vector_calculus/scalar_functions_applications.html" class="pagination-link">
<span class="nav-page-text"><span class="chapter-number">56</span>&nbsp; <span class="chapter-title">Applications with scalar functions</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>