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

2445 lines
165 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 - 57&nbsp; Functions \(R^n \rightarrow R^m\)</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/plots_plotting.html" rel="next">
<link href="../differentiable_vector_calculus/scalar_functions_applications.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">57</span>&nbsp; <span class="chapter-title">Functions <span class="math inline">\(R^n \rightarrow R^m\)</span></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"><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 active"><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="#vector-fields" id="toc-vector-fields" class="nav-link active" data-scroll-target="#vector-fields"> <span class="header-section-number">57.1</span> Vector fields</a></li>
<li><a href="#parametrically-defined-surfaces" id="toc-parametrically-defined-surfaces" class="nav-link" data-scroll-target="#parametrically-defined-surfaces"> <span class="header-section-number">57.2</span> Parametrically defined surfaces</a>
<ul class="collapse">
<li><a href="#plotting-parametrized-surfaces-in-julia" id="toc-plotting-parametrized-surfaces-in-julia" class="nav-link" data-scroll-target="#plotting-parametrized-surfaces-in-julia"> <span class="header-section-number">57.2.1</span> Plotting parametrized surfaces in <code>Julia</code></a></li>
</ul></li>
<li><a href="#the-total-derivative" id="toc-the-total-derivative" class="nav-link" data-scroll-target="#the-total-derivative"> <span class="header-section-number">57.3</span> The total derivative</a></li>
<li><a href="#the-chain-rule" id="toc-the-chain-rule" class="nav-link" data-scroll-target="#the-chain-rule"> <span class="header-section-number">57.4</span> The chain rule</a>
<ul class="collapse">
<li><a href="#examples" id="toc-examples" class="nav-link" data-scroll-target="#examples"> <span class="header-section-number">57.4.1</span> Examples</a></li>
</ul></li>
<li><a href="#questions" id="toc-questions" class="nav-link" data-scroll-target="#questions"> <span class="header-section-number">57.5</span> Questions</a></li>
</ul>
<div class="toc-actions"><div><i class="bi bi-github"></i></div><div class="action-links"><p><a href="https://github.com/jverzani/CalculusWithJuliaNotes.jl/edit/main/quarto/differentiable_vector_calculus/vector_fields.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">57</span>&nbsp; <span class="chapter-title">Functions <span class="math inline">\(R^n \rightarrow R^m\)</span></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">SymPy</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">ForwardDiff</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">LinearAlgebra</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>For a scalar function <span class="math inline">\(f: R^n \rightarrow R\)</span>, the gradient of <span class="math inline">\(f\)</span>, <span class="math inline">\(\nabla{f}\)</span>, is a function from <span class="math inline">\(R^n \rightarrow R^n\)</span>. Specializing to <span class="math inline">\(n=2\)</span>, a function that for each point, <span class="math inline">\((x,y)\)</span>, assigns a vector <span class="math inline">\(\vec{v}\)</span>. This is an example of vector field. More generally, we could have a <a href="https://en.wikipedia.org/wiki/Multivariable_calculus">function</a> <span class="math inline">\(f: R^n \rightarrow R^m\)</span>, of which we have discussed many already:</p>
<table class="table">
<colgroup>
<col style="width: 27%">
<col style="width: 16%">
<col style="width: 31%">
<col style="width: 24%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: center;">Mapping</th>
<th style="text-align: center;">Name</th>
<th style="text-align: center;">Visualize with</th>
<th style="text-align: center;">Notation</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center;"><span class="math inline">\(f: R\rightarrow R\)</span></td>
<td style="text-align: center;">univariate</td>
<td style="text-align: center;">familiar graph of function</td>
<td style="text-align: center;"><span class="math inline">\(f\)</span></td>
</tr>
<tr class="even">
<td style="text-align: center;"><span class="math inline">\(f: R\rightarrow R^m\)</span></td>
<td style="text-align: center;">vector-valued</td>
<td style="text-align: center;">space curve when n=2 or 3</td>
<td style="text-align: center;"><span class="math inline">\(\vec{r}\)</span>, <span class="math inline">\(\vec{N}\)</span></td>
</tr>
<tr class="odd">
<td style="text-align: center;"><span class="math inline">\(f: R^n\rightarrow R\)</span></td>
<td style="text-align: center;">scalar</td>
<td style="text-align: center;">a surface when n=2</td>
<td style="text-align: center;"><span class="math inline">\(f\)</span></td>
</tr>
<tr class="even">
<td style="text-align: center;"><span class="math inline">\(F: R^n\rightarrow R^n\)</span></td>
<td style="text-align: center;">vector field</td>
<td style="text-align: center;">a vector field when n=2</td>
<td style="text-align: center;"><span class="math inline">\(F\)</span></td>
</tr>
<tr class="odd">
<td style="text-align: center;"><span class="math inline">\(F: R^n\rightarrow R^m\)</span></td>
<td style="text-align: center;">multivariable</td>
<td style="text-align: center;">n=2,m=3 describes a surface</td>
<td style="text-align: center;"><span class="math inline">\(F\)</span>, <span class="math inline">\(\Phi\)</span></td>
</tr>
</tbody>
</table>
<p>After an example where the use of a multivariable function is of necessity, we discuss differentiation in general for a multivariable functions.</p>
<section id="vector-fields" class="level2" data-number="57.1">
<h2 data-number="57.1" class="anchored" data-anchor-id="vector-fields"><span class="header-section-number">57.1</span> Vector fields</h2>
<p>We have seen that the gradient of a scalar function, <span class="math inline">\(f:R^2 \rightarrow R\)</span>, takes a point in <span class="math inline">\(R^2\)</span> and associates a vector in <span class="math inline">\(R^2\)</span>. As such <span class="math inline">\(\nabla{f}:R^2 \rightarrow R^2\)</span> is a vector field. A vector field can be visualized by sampling a region and representing the field at those points. The details, as previously mentioned, are in the <code>vectorfieldplot</code> function of <code>CalculusWithJulia</code>.</p>
<div class="cell" data-execution_count="4">
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="fu">F</span>(u,v) <span class="op">=</span> [<span class="op">-</span>v, u]</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="fu">vectorfieldplot</span>(F, 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>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="5">
<p><img src="vector_fields_files/figure-html/cell-5-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The optional arguments <code>nx=10</code> and <code>ny=10</code> determine the number of points on the grid that a vector will be plotted. These vectors are scaled to not overlap.</p>
<p>Vector field plots are useful for visualizing velocity fields, where a velocity vector is associated to each point; or streamlines, curves whose tangents are follow the velocity vector of a flow. Vector fields are used in physics to model the electric field and the magnetic field. These are used to describe forces on objects within the field.</p>
<p>The three dimensional vector field is one way to illustrate a vector field, but there is an alternate using field lines. Like Eulers method, imagine starting at some point, <span class="math inline">\(\vec{r}\)</span> in <span class="math inline">\(R^3\)</span>. The field at that point is a vector indicating a direction of motion. Follow that vector for some infinitesimal amount, <span class="math inline">\(d\vec{r}\)</span>. From here repeat. The field curve would satisfy <span class="math inline">\(\vec{r}'(t) = F(\vec{r}(t))\)</span>. Field curves only show direction, to indicate magnitude at a point, the convention is to use denser lines when the field is stronger.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../differentiable_vector_calculus/figures/magnetic-field.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Illustration of the magnetic field of the earth using field lines to indicate the field. From <a href="https://en.wikipedia.org/wiki/Magnetic_field">Wikipedia</a>.</figcaption><p></p>
</figure>
</div>
<hr>
<p>Vector fields are also useful for other purposes, such as transformations, examples of which are a rotation or the conversion from polar to rectangular coordinates.</p>
<p>For transformations, a useful visualization is to plot curves where one variables is fixed. Consider the transformation from polar coordinates to cartesian coordinates <span class="math inline">\(F(r, \theta) = r \langle\cos(\theta),\sin(\theta)\rangle\)</span>. The following plot will show in blue fixed values of <span class="math inline">\(r\)</span> (circles) and in red fixed values of <span class="math inline">\(\theta\)</span> (rays).</p>
<div class="cell" data-hold="true" data-execution_count="6">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fu">F</span>(r,theta) <span class="op">=</span> r<span class="op">*</span>[<span class="fu">cos</span>(theta), <span class="fu">sin</span>(theta)]</span>
<span id="cb3-2"><a href="#cb3-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="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a>rs <span class="op">=</span> <span class="fu">range</span>(<span class="fl">0</span>, <span class="fl">2</span>, length<span class="op">=</span><span class="fl">5</span>)</span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a>thetas <span class="op">=</span> <span class="fu">range</span>(<span class="fl">0</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, length<span class="op">=</span><span class="fl">9</span>)</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(legend<span class="op">=</span><span class="cn">false</span>, aspect_ratio<span class="op">=:</span>equal)</span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(<span class="fu">unzip</span>(<span class="fu">F</span>.(rs, thetas<span class="op">'</span>))<span class="op">...</span>, color<span class="op">=:</span>red)</span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(<span class="fu">unzip</span>(<span class="fu">F</span>.(rs<span class="op">'</span>, thetas))<span class="op">...</span>, color<span class="op">=:</span>blue)</span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a>pt <span class="op">=</span> [<span class="fl">1</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">4</span>]</span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a>J <span class="op">=</span> ForwardDiff.<span class="fu">jacobian</span>(F, pt)</span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(<span class="fu">F</span>(pt<span class="op">...</span>), J[<span class="op">:</span>,<span class="fl">1</span>], linewidth<span class="op">=</span><span class="fl">5</span>, color<span class="op">=:</span>red)</span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(<span class="fu">F</span>(pt<span class="op">...</span>), J[<span class="op">:</span>,<span class="fl">2</span>], linewidth<span class="op">=</span><span class="fl">5</span>, color<span class="op">=:</span>blue)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="7">
<p><img src="vector_fields_files/figure-html/cell-7-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>To the plot, we added the partial derivatives with respect to <span class="math inline">\(r\)</span> (in red) and with respect to <span class="math inline">\(\theta\)</span> (in blue). These are found with the soon-to-be discussed Jacobian. From the graph, you can see that these vectors are tangent vectors to the drawn curves.</p>
</section>
<section id="parametrically-defined-surfaces" class="level2" data-number="57.2">
<h2 data-number="57.2" class="anchored" data-anchor-id="parametrically-defined-surfaces"><span class="header-section-number">57.2</span> Parametrically defined surfaces</h2>
<p>For a one-dimensional curve we have several descriptions. For example, as the graph of a function <span class="math inline">\(y=f(x)\)</span>; as a parametrically defined curve <span class="math inline">\(\vec{r}(t) = \langle x(t), y(t)\rangle\)</span>; or as a level curve of a scalar function <span class="math inline">\(f(x,y) = c\)</span>.</p>
<p>For two-dimensional surfaces in three dimensions, we have discussed describing these in terms of a function <span class="math inline">\(z = f(x,y)\)</span> and as level curves of scalar functions: <span class="math inline">\(c = f(x,y,z)\)</span>. They can also be described parametrically.</p>
<p>We pick a familiar case, to make this concrete: the unit sphere in <span class="math inline">\(R^3\)</span>. We have</p>
<ul>
<li>It is described by two functions through <span class="math inline">\(f(x,y) = \pm \sqrt{1 - (x^2 + y^2)}\)</span>.</li>
<li>It is described by <span class="math inline">\(f(x,y,z) = 1\)</span>, where <span class="math inline">\(f(x,y,z) = x^2 + y^2 + z^2\)</span>.</li>
<li>It can be described in terms of <a href="https://en.wikipedia.org/wiki/Spherical_coordinate_system">spherical coordinates</a>:</li>
</ul>
<p><span class="math display">\[
\Phi(\theta, \phi) = \langle \sin(\phi)\cos(\theta), \sin(\phi)\sin(\theta), \cos(\phi) \rangle,
\]</span></p>
<p>with <span class="math inline">\(\theta\)</span> the <em>azimuthal</em> angle and <span class="math inline">\(\phi\)</span> the polar angle (measured down from the <span class="math inline">\(z\)</span> axis).</p>
<p>The function <span class="math inline">\(\Phi\)</span> takes <span class="math inline">\(R^2\)</span> into <span class="math inline">\(R^3\)</span>, so is a multivariable function.</p>
<p>When a surface is described by a function, <span class="math inline">\(z=f(x,y)\)</span>, then the gradient points (in the <span class="math inline">\(x-y\)</span> plane) in the direction of greatest increase of <span class="math inline">\(f\)</span>. The vector <span class="math inline">\(\langle -f_x, -f_y, 1\rangle\)</span> is a normal.</p>
<p>When a surface is described as a level curve, <span class="math inline">\(f(x,y,z) = c\)</span>, then the gradient is <em>normal</em> to the surface.</p>
<p>When a surface is described parametrically, there is no “gradient.” The <em>partial</em> derivatives are of interest, e.g., <span class="math inline">\(\partial{F}/\partial{\theta}\)</span> and <span class="math inline">\(\partial{F}/\partial{\phi}\)</span>, vectors defined componentwise. These will be lie in the tangent plane of the surface, as they can be viewed as tangent vectors for parametrically defined curves on the surface. Their cross product will be <em>normal</em> to the surface. The magnitude of the cross product, which reflects the angle between the two partial derivatives, will be informative as to the surface area.</p>
<section id="plotting-parametrized-surfaces-in-julia" class="level3" data-number="57.2.1">
<h3 data-number="57.2.1" class="anchored" data-anchor-id="plotting-parametrized-surfaces-in-julia"><span class="header-section-number">57.2.1</span> Plotting parametrized surfaces in <code>Julia</code></h3>
<p>Consider the parametrically described surface above. How would it be plotted? Using the <code>Plots</code> package, the process is quite similar to how a surface described by a function is plotted, but the <span class="math inline">\(z\)</span> values must be computed prior to plotting.</p>
<p>Here we define the parameterization using functions to represent each component:</p>
<div class="cell" data-execution_count="7">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="fu">X</span>(theta,phi) <span class="op">=</span> <span class="fu">sin</span>(phi) <span class="op">*</span> <span class="fu">cos</span>(theta)</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="fu">Y</span>(theta,phi) <span class="op">=</span> <span class="fu">sin</span>(phi) <span class="op">*</span> <span class="fu">sin</span>(theta)</span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="fu">Z</span>(theta,phi) <span class="op">=</span> <span class="fu">cos</span>(phi)</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>Z (generic function with 1 method)</code></pre>
</div>
</div>
<p>Then:</p>
<div class="cell" data-execution_count="8">
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>thetas <span class="op">=</span> <span class="fu">range</span>(<span class="fl">0</span>, stop<span class="op">=</span><span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, length<span class="op">=</span><span class="fl">50</span>)</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a>phis <span class="op">=</span> <span class="fu">range</span>(<span class="fl">0</span>, stop<span class="op">=</span><span class="cn">pi</span>, length<span class="op">=</span><span class="fl">50</span>)</span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> [<span class="fu">X</span>(theta, phi) for theta <span class="kw">in</span> thetas, phi <span class="kw">in</span> phis]</span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a>ys <span class="op">=</span> [<span class="fu">Y</span>(theta, phi) for theta <span class="kw">in</span> thetas, phi <span class="kw">in</span> phis]</span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a>zs <span class="op">=</span> [<span class="fu">Z</span>(theta, phi) for theta <span class="kw">in</span> thetas, phi <span class="kw">in</span> phis]</span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, zs) <span class="co">## see note</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">
<p><img src="vector_fields_files/figure-html/cell-9-output-1.svg" class="img-fluid"></p>
</div>
</div>
<div class="callout-note callout callout-style-default callout-captioned">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-caption-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
</div>
</div>
<p>Only <em>some</em> backends for <code>Plots</code> will produce this type of plot. Both <code>plotly()</code> and <code>pyplot()</code> will, but not <code>gr()</code>.</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>PyPlot can be used directly to make these surface plots: `import PyPlot; PyPlot.plot_surface(xs,ys,zs).</p>
</div>
</div>
<p>Instead of the comprehension, broadcasting can be used</p>
<div class="cell" data-execution_count="9">
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(<span class="fu">X</span>.(thetas, phis<span class="op">'</span>), <span class="fu">Y</span>.(thetas, phis<span class="op">'</span>), <span class="fu">Z</span>.(thetas, phis<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="10">
<p><img src="vector_fields_files/figure-html/cell-10-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>If the parameterization is presented as a function, broadcasting can be used to succintly plot</p>
<div class="cell" data-execution_count="10">
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">Phi</span>(theta, phi) <span class="op">=</span> [<span class="fu">X</span>(theta, phi), <span class="fu">Y</span>(theta, phi), <span class="fu">Z</span>(theta, phi)]</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(<span class="fu">unzip</span>(<span class="fu">Phi</span>.(thetas, phis<span class="op">'</span>))<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="11">
<p><img src="vector_fields_files/figure-html/cell-11-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The partial derivatives of each component, <span class="math inline">\(\partial{\Phi}/\partial{\theta}\)</span> and <span class="math inline">\(\partial{\Phi}/\partial{\phi}\)</span>, can be computed directly:</p>
<p><span class="math display">\[
\begin{align*}
\partial{\Phi}/\partial{\theta} &amp;= \langle -\sin(\phi)\sin(\theta), \sin(\phi)\cos(\theta),0 \rangle,\\
\partial{\Phi}/\partial{\phi} &amp;= \langle \cos(\phi)\cos(\theta), \cos(\phi)\sin(\theta), -\sin(\phi) \rangle.
\end{align*}
\]</span></p>
<p>Using <code>SymPy</code>, we can compute through:</p>
<div class="cell" data-execution_count="11">
<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="pp">@syms</span> theta phi</span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>out <span class="op">=</span> [<span class="fu">diff</span>.(<span class="fu">Phi</span>(theta, phi), theta) <span class="fu">diff</span>.(<span class="fu">Phi</span>(theta, phi), phi)]</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>3×2 Matrix{Sym}:
-sin(φ)⋅sin(θ) cos(φ)⋅cos(θ)
sin(φ)⋅cos(θ) sin(θ)⋅cos(φ)
0 -sin(φ)</code></pre>
</div>
</div>
<p>At the point <span class="math inline">\((\theta, \phi) = (\pi/12, \pi/6)\)</span> this evaluates to the following.</p>
<div class="cell" data-execution_count="12">
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="fu">subs</span>.(out, theta<span class="op">.=&gt;</span> PI<span class="op">/</span><span class="fl">12</span>, phi<span class="op">.=&gt;</span>PI<span class="op">/</span><span class="fl">6</span>) <span class="op">.|&gt;</span> N</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>3×2 Matrix{Real}:
-0.12941 0.836516
0.482963 0.224144
0 -1//2</code></pre>
</div>
</div>
<p>We found numeric values, so that we can compare to the numerically identical values computed by the <code>jacobian</code> function from <code>ForwardDiff</code>:</p>
<div class="cell" data-execution_count="13">
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>pt <span class="op">=</span> [<span class="cn">pi</span><span class="op">/</span><span class="fl">12</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">6</span>]</span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a>out₁ <span class="op">=</span> ForwardDiff.<span class="fu">jacobian</span>(v <span class="op">-&gt;</span> <span class="fu">Phi</span>(v<span class="op">...</span>), pt)</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>3×2 Matrix{Float64}:
-0.12941 0.836516
0.482963 0.224144
-0.0 -0.5</code></pre>
</div>
</div>
<p>What this function computes exactly will be described next, but here we visualize the partial derivatives and see they lie in the tangent plane at the point:</p>
<div class="cell" data-hold="true" data-execution_count="14">
<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>us, vs <span class="op">=</span> <span class="fu">range</span>(<span class="fl">0</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, length<span class="op">=</span><span class="fl">25</span>), <span class="fu">range</span>(<span class="fl">0</span>, <span class="cn">pi</span>, length<span class="op">=</span><span class="fl">25</span>)</span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>xs, ys, zs <span class="op">=</span> <span class="fu">unzip</span>(<span class="fu">Phi</span>.(us, vs<span class="op">'</span>))</span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, zs, legend<span class="op">=</span><span class="cn">false</span>)</span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(<span class="fu">Phi</span>(pt<span class="op">...</span>), out₁[<span class="op">:</span>,<span class="fl">1</span>], linewidth<span class="op">=</span><span class="fl">3</span>)</span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(<span class="fu">Phi</span>(pt<span class="op">...</span>), out₁[<span class="op">:</span>,<span class="fl">2</span>], linewidth<span class="op">=</span><span class="fl">3</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="15">
<p><img src="vector_fields_files/figure-html/cell-15-output-1.svg" class="img-fluid"></p>
</div>
</div>
</section>
</section>
<section id="the-total-derivative" class="level2" data-number="57.3">
<h2 data-number="57.3" class="anchored" data-anchor-id="the-total-derivative"><span class="header-section-number">57.3</span> The total derivative</h2>
<p>Informally, the <a href="https://en.wikipedia.org/wiki/Total_derivative">total derivative</a> at <span class="math inline">\(a\)</span> is the best linear approximation of the value of a function, <span class="math inline">\(F\)</span>, near <span class="math inline">\(a\)</span> with respect to its arguments. If it exists, denote it <span class="math inline">\(dF_a\)</span>.</p>
<p>For a function <span class="math inline">\(F: R^n \rightarrow R^m\)</span> we have the total derivative at <span class="math inline">\(\vec{a}\)</span> (a point or vector in <span class="math inline">\(R^n\)</span>) is a matrix <span class="math inline">\(J\)</span> (a linear transformation) taking vectors in <span class="math inline">\(R^n\)</span> and returning, under multiplication, vectors in <span class="math inline">\(R^m\)</span> (this matrix will be <span class="math inline">\(m \times n\)</span>), such that for some neighborhood of <span class="math inline">\(\vec{a}\)</span>, we have:</p>
<p><span class="math display">\[
\lim_{\vec{x} \rightarrow \vec{a}} \frac{\|F(\vec{x}) - F(\vec{a}) - J\cdot(\vec{x}-\vec{a})\|}{\|\vec{x} - \vec{a}\|} = \vec{0}.
\]</span></p>
<p>(That is <span class="math inline">\(\|F(\vec{x}) - F(\vec{a}) - J\cdot(\vec{x}-\vec{a})\|=\mathcal{o}(\|\vec{x}-\vec{a}\|)\)</span>.)</p>
<p>If for some <span class="math inline">\(J\)</span> the above holds, the function <span class="math inline">\(F\)</span> is said to be totally differentiable, and the matrix <span class="math inline">\(J =J_F=dF_a\)</span> is the total derivative.</p>
<p>For a multivariable function <span class="math inline">\(F:R^n \rightarrow R^m\)</span>, we may express the function in vector-valued form <span class="math inline">\(F(\vec{x}) = \langle f_1(\vec{x}), f_2(\vec{x}),\dots,f_m(\vec{x})\rangle\)</span>, each component a scalar function. Then, if the total derivative exists, it can be expressed by the <a href="https://en.wikipedia.org/wiki/Jacobian_matrix_and_determinant">Jacobian</a>:</p>
<p><span class="math display">\[
J = \left[
\begin{align*}
\frac{\partial f_1}{\partial x_1} &amp;\quad \frac{\partial f_1}{\partial x_2} &amp;\dots&amp;\quad\frac{\partial f_1}{\partial x_n}\\
\frac{\partial f_2}{\partial x_1} &amp;\quad \frac{\partial f_2}{\partial x_2} &amp;\dots&amp;\quad\frac{\partial f_2}{\partial x_n}\\
&amp;&amp;\vdots&amp;\\
\frac{\partial f_m}{\partial x_1} &amp;\quad \frac{\partial f_m}{\partial x_2} &amp;\dots&amp;\quad\frac{\partial f_m}{\partial x_n}
\end{align*}
\right].
\]</span></p>
<p>This may also be viewed as:</p>
<p><span class="math display">\[
J = \left[
\begin{align*}
&amp;\nabla{f_1}'\\
&amp;\nabla{f_2}'\\
&amp;\quad\vdots\\
&amp;\nabla{f_m}'
\end{align*}
\right] =
\left[
\frac{\partial{F}}{\partial{x_1}}\quad
\frac{\partial{F}}{\partial{x_2}} \cdots
\frac{\partial{F}}{\partial{x_n}}
\right].
\]</span></p>
<p>The latter representing a matrix of <span class="math inline">\(m\)</span> row vectors, each with <span class="math inline">\(n\)</span> components or as a matrix of <span class="math inline">\(n\)</span> column vectors, each with <span class="math inline">\(m\)</span> components.</p>
<hr>
<p>After specializing the total derivative to the cases already discussed, we have:</p>
<ul>
<li>Univariate functions. Here <span class="math inline">\(f'(t)\)</span> is also univariate. Identifying <span class="math inline">\(J\)</span> with the <span class="math inline">\(1 \times 1\)</span> matrix with component <span class="math inline">\(f'(t)\)</span>, then the total derivative is just a restatement of the derivative existing.</li>
<li>Vector-valued functions <span class="math inline">\(\vec{f}(t) = \langle f_1(t), f_2(t), \dots, f_m(t) \rangle\)</span>, each component univariate. Then the derivative, <span class="math inline">\(\vec{f}'(t) = \langle \frac{df_1}{dt}, \frac{df_2}{dt}, \dots, \frac{df_m}{dt} \rangle\)</span>. The total derivative in this case, is a a <span class="math inline">\(m \times 1\)</span> vector of partial derivatives, and since there is only <span class="math inline">\(1\)</span> variable, would be written without partials. So the two agree.</li>
<li>Scalar functions <span class="math inline">\(f(\vec{x}) = a\)</span> of type <span class="math inline">\(R^n \rightarrow R\)</span>. The</li>
</ul>
<p>definition of differentiability for <span class="math inline">\(f\)</span> involved existence of the partial derivatives and moreover, the fact that a limit like the above held with <span class="math inline">\(\nabla{f}(C) \cdot \vec{h}\)</span> in place of <span class="math inline">\(J\cdot(\vec{x}-\vec{a})\)</span>. Here <span class="math inline">\(\vec{h}\)</span> and <span class="math inline">\(\vec{x}-\vec{a}\)</span> are vectors in <span class="math inline">\(R^n\)</span>. Were the dot product in <span class="math inline">\(\nabla{f}(C) \cdot \vec{h}\)</span> expressed in matrix multiplication we would have for this case a <span class="math inline">\(1 \times n\)</span> matrix of the correct form:</p>
<p><span class="math display">\[
J = [\nabla{f}'].
\]</span></p>
<ul>
<li>For <span class="math inline">\(f:R^2 \rightarrow R\)</span>, the Hessian matrix, was the matrix of <span class="math inline">\(2\)</span>nd partial derivatives. This may be viewed as the total derivative of the the gradient function, <span class="math inline">\(\nabla{f}\)</span>:</li>
</ul>
<p><span class="math display">\[
\text{Hessian} =
\left[
\begin{align*}
\frac{\partial^2 f}{\partial x^2} &amp;\quad \frac{\partial^2 f}{\partial x \partial y}\\
\frac{\partial^2 f}{\partial y \partial x} &amp;\quad \frac{\partial^2 f}{\partial y \partial y}
\end{align*}
\right]
\]</span></p>
<p>This is equivalent to:</p>
<p><span class="math display">\[
\left[
\begin{align*}
\frac{\partial \frac{\partial f}{\partial x}}{\partial x} &amp;\quad \frac{\partial \frac{\partial f}{\partial x}}{\partial y}\\
\frac{\partial \frac{\partial f}{\partial y}}{\partial x} &amp;\quad \frac{\partial \frac{\partial f}{\partial y}}{\partial y}\\
\end{align*}
\right].
\]</span></p>
<p>As such, the total derivative is a generalization of what we have previously discussed.</p>
</section>
<section id="the-chain-rule" class="level2" data-number="57.4">
<h2 data-number="57.4" class="anchored" data-anchor-id="the-chain-rule"><span class="header-section-number">57.4</span> The chain rule</h2>
<p>If <span class="math inline">\(G:R^k \rightarrow R^n\)</span> and <span class="math inline">\(F:R^n \rightarrow R^m\)</span>, then the composition <span class="math inline">\(F\circ G\)</span> takes <span class="math inline">\(R^k \rightarrow R^m\)</span>. If all three functions are totally differentiable, then a chain rule will hold (total derivative of <span class="math inline">\(F\circ G\)</span> at point <span class="math inline">\(a\)</span>):</p>
<p>$$ d(FG)<em>a = dF</em>{G(a)} dG_a</p>
<p>$$</p>
<p>If correct, this has the same formulation as the chain rule for the univariate case: derivative of outer at the inner <em>times</em> the derivative of the inner.</p>
<p>First we check that the dimensions are correct: We have <span class="math inline">\(dF_{G(a)}\)</span> (the total derivative of <span class="math inline">\(F\)</span> at the point <span class="math inline">\(G(a)\)</span>) is an <span class="math inline">\(m \times n\)</span> matrix and <span class="math inline">\(dG_a\)</span> (the total derivative of <span class="math inline">\(G\)</span> at the point <span class="math inline">\(a\)</span>) is a <span class="math inline">\(n \times k\)</span> matrix. The product of a <span class="math inline">\(m \times n\)</span> matrix with a <span class="math inline">\(n \times k\)</span> matrix is defined, and is a <span class="math inline">\(m \times k\)</span> matrix, as is <span class="math inline">\(d(F \circ G)_a\)</span>.</p>
<p>The proof that the formula is correct uses the definition of totally differentiable written as</p>
<p><span class="math display">\[
F(b + \vec{h}) - F(b) - dF_b\cdot \vec{h} = \epsilon(\vec{h}) \vec{h},
\]</span></p>
<p>where <span class="math inline">\(\epsilon(h) \rightarrow \vec{0}\)</span> as <span class="math inline">\(h \rightarrow \vec{0}\)</span>.</p>
<p>We have, using this for <em>both</em> <span class="math inline">\(F\)</span> and <span class="math inline">\(G\)</span>:</p>
<p><span class="math display">\[
\begin{align*}
F(G(a + \vec{h})) - F(G(a)) &amp;=
F(G(a) + (dG_a \cdot \vec{h} + \epsilon_G \vec{h})) - F(G(a))\\
&amp;= F(G(a)) + dF_{G(a)} \cdot (dG_a \cdot \vec{h} + \epsilon_G \vec{h}) \\
&amp;+ \quad\epsilon_F (dG_a \cdot \vec{h} + \epsilon_G \vec{h}) - F(G(a))\\
&amp;= dF_{G(a)} \cdot (dG_a \cdot \vec{h}) + dF_{G(a)} \cdot (\epsilon_G \vec{h}) + \epsilon_F (dG_a \cdot \vec{h}) + (\epsilon_F \cdot \epsilon_G\vec{h})
\end{align*}
\]</span></p>
<p>The last line uses the linearity of <span class="math inline">\(dF\)</span> to isolate <span class="math inline">\(dF_{G(a)} \cdot (dG_a \cdot \vec{h})\)</span>. Factoring out <span class="math inline">\(\vec{h}\)</span> and taking norms gives:</p>
<p><span class="math display">\[
\begin{align*}
\frac{\| F(G(a+\vec{h})) - F(G(a)) - dF_{G(a)}dG_a \cdot \vec{h} \|}{\| \vec{h} \|} &amp;=
\frac{\| dF_{G(a)}\cdot(\epsilon_G\vec{h}) + \epsilon_F (dG_a\cdot \vec{h}) + (\epsilon_F\cdot\epsilon_G\vec{h}) \|}{\| \vec{h} \|} \\
&amp;\leq \| dF_{G(a)}\cdot\epsilon_G + \epsilon_F (dG_a) + \epsilon_F\cdot\epsilon_G \|\frac{\|\vec{h}\|}{\| \vec{h} \|}\\
&amp;\rightarrow 0.
\end{align*}
\]</span></p>
<section id="examples" class="level3" data-number="57.4.1">
<h3 data-number="57.4.1" class="anchored" data-anchor-id="examples"><span class="header-section-number">57.4.1</span> Examples</h3>
<p>Our main use of the total derivative will be the change of variables in integration.</p>
<section id="example-polar-coordinates" class="level5">
<h5 class="anchored" data-anchor-id="example-polar-coordinates">Example: polar coordinates</h5>
<p>A point <span class="math inline">\((a,b)\)</span> in the plane can be described in polar coordinates by a radius <span class="math inline">\(r\)</span> and polar angle <span class="math inline">\(\theta\)</span>. We can express this formally by <span class="math inline">\(F:(a,b) \rightarrow (r, \theta)\)</span> with</p>
<p><span class="math display">\[
r(a,b) = \sqrt{a^2 + b^2}, \quad
\theta(a,b) = \tan^{-1}(b/a),
\]</span></p>
<p>the latter assuming the point is in quadrant I or IV (though <code>atan(y,x)</code> will properly handle the other quadrants). The Jacobian of this transformation may be found with</p>
<div class="cell" data-execution_count="15">
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> a<span class="op">::</span><span class="dt">real </span>b<span class="op">::</span><span class="dt">real</span></span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a>rⱼ <span class="op">=</span> <span class="fu">sqrt</span>(a<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> b<span class="op">^</span><span class="fl">2</span>)</span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a>θⱼ <span class="op">=</span> <span class="fu">atan</span>(b<span class="op">/</span>a)</span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true" tabindex="-1"></a>Jac <span class="op">=</span> Sym[<span class="fu">diff</span>.(rⱼ, [a,b])<span class="ch">'; # [∇f_1'</span>; ∇f_2<span class="op">'</span>]</span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">diff</span>.(θⱼ, [a,b])<span class="ch">']</span></span>
<span id="cb16-8"><a href="#cb16-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-9"><a href="#cb16-9" aria-hidden="true" tabindex="-1"></a><span class="fu">simplify</span>.(Jac)</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>2×2 Matrix{Sym}:
a*conjugate(1/sqrt(a^2 + b^2)) b*conjugate(1/sqrt(a^2 + b^2))
-b/(a^2 + b^2) a/(a^2 + b^2)</code></pre>
</div>
</div>
<p><code>SymPy</code> array objects have a <code>jacobian</code> method to make this easier to do. The calling style is Python-like, using <code>object.method(...)</code>:</p>
<div class="cell" data-execution_count="16">
<div class="sourceCode cell-code" id="cb18"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>[rⱼ, θⱼ].<span class="fu">jacobian</span>([a, b])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="17">
<pre><code>2×2 Matrix{Sym}:
a/sqrt(a^2 + b^2) b/sqrt(a^2 + b^2)
-b/(a^2*(1 + b^2/a^2)) 1/(a*(1 + b^2/a^2))</code></pre>
</div>
</div>
<p>The determinant, of geometric interest, will be</p>
<div class="cell" data-execution_count="17">
<div class="sourceCode cell-code" id="cb20"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a><span class="fu">det</span>(Jac) <span class="op">|&gt;</span> simplify</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="18">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
\overline{\frac{1}{\sqrt{a^{2} + b^{2}}}}
\]
</span>
</div>
</div>
<p>The determinant is of interest, as the linear mapping represented by the Jacobian changes the area of the associated coordinate vectors. The determinant describes ow this area changes, as a multiplying factor.</p>
</section>
<section id="example-spherical-coordinates" class="level5">
<h5 class="anchored" data-anchor-id="example-spherical-coordinates">Example Spherical Coordinates</h5>
<p>In <span class="math inline">\(3\)</span> dimensions a point can be described by (among other ways):</p>
<ul>
<li>Cartesian coordinates: three coordinates relative to the <span class="math inline">\(x\)</span>, <span class="math inline">\(y\)</span>, and <span class="math inline">\(z\)</span> axes as <span class="math inline">\((a,b,c)\)</span>.</li>
<li>Spherical coordinates: a radius, <span class="math inline">\(r\)</span>, an azimuthal angle <span class="math inline">\(\theta\)</span>, and a polar angle</li>
</ul>
<p><span class="math display">\[
\phi
\]</span></p>
<p>measured down from the <span class="math inline">\(z\)</span> axes. (We use the mathematics naming convention, the physics one has <span class="math inline">\(\phi\)</span> and <span class="math inline">\(\theta\)</span> reversed.)</p>
<ul>
<li>Cylindrical coordinates: a radius, <span class="math inline">\(r\)</span>, a polar angle <span class="math inline">\(\theta\)</span>, and height <span class="math inline">\(z\)</span>.</li>
</ul>
<p>Some mappings are:</p>
<table class="table">
<colgroup>
<col style="width: 21%">
<col style="width: 39%">
<col style="width: 38%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: center;">Cartesian (x,y,z)</th>
<th style="text-align: center;">Spherical (<span class="math inline">\(r\)</span>, <span class="math inline">\(\theta\)</span>, <span class="math inline">\(\phi\)</span>)</th>
<th style="text-align: center;">Cylindrical (<span class="math inline">\(r\)</span>, <span class="math inline">\(\theta\)</span>, <span class="math inline">\(z\)</span>)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center;">(1, 1, 0)</td>
<td style="text-align: center;"><span class="math inline">\((\sqrt{2}, \pi/4, \pi/2)\)</span></td>
<td style="text-align: center;"><span class="math inline">\((\sqrt{2},\pi/4, 0)\)</span></td>
</tr>
<tr class="even">
<td style="text-align: center;">(0, 1, 1)</td>
<td style="text-align: center;"><span class="math inline">\((\sqrt{2}, 0, \pi/4)\)</span></td>
<td style="text-align: center;"><span class="math inline">\((\sqrt{2}, 0, 1)\)</span></td>
</tr>
</tbody>
</table>
<hr>
<p>Formulas can be found to convert between the different systems, here are a few written as multivariable functions:</p>
<div class="cell" data-execution_count="18">
<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="kw">function</span> <span class="fu">spherical_from_cartesian</span>(x,y,z)</span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a> r <span class="op">=</span> <span class="fu">sqrt</span>(x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> z<span class="op">^</span><span class="fl">2</span>)</span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a> theta <span class="op">=</span> <span class="fu">atan</span>(y<span class="op">/</span>x)</span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a> phi <span class="op">=</span> <span class="fu">acos</span>(z<span class="op">/</span>r)</span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a> [r, theta, phi]</span>
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span>
<span id="cb21-7"><a href="#cb21-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-8"><a href="#cb21-8" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span> <span class="fu">cartesian_from_spherical</span>(r, theta, phi)</span>
<span id="cb21-9"><a href="#cb21-9" aria-hidden="true" tabindex="-1"></a> x <span class="op">=</span> <span class="fu">r*sin</span>(phi)<span class="fu">*cos</span>(theta)</span>
<span id="cb21-10"><a href="#cb21-10" aria-hidden="true" tabindex="-1"></a> y <span class="op">=</span> <span class="fu">r*sin</span>(phi)<span class="fu">*sin</span>(theta)</span>
<span id="cb21-11"><a href="#cb21-11" aria-hidden="true" tabindex="-1"></a> z <span class="op">=</span> <span class="fu">r*cos</span>(phi)</span>
<span id="cb21-12"><a href="#cb21-12" aria-hidden="true" tabindex="-1"></a> [x, y, z]</span>
<span id="cb21-13"><a href="#cb21-13" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span>
<span id="cb21-14"><a href="#cb21-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-15"><a href="#cb21-15" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span> <span class="fu">cylindrical_from_cartesian</span>(x, y, z)</span>
<span id="cb21-16"><a href="#cb21-16" aria-hidden="true" tabindex="-1"></a> r <span class="op">=</span> <span class="fu">sqrt</span>(x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">2</span>)</span>
<span id="cb21-17"><a href="#cb21-17" aria-hidden="true" tabindex="-1"></a> theta <span class="op">=</span> <span class="fu">atan</span>(y<span class="op">/</span>x)</span>
<span id="cb21-18"><a href="#cb21-18" aria-hidden="true" tabindex="-1"></a> z <span class="op">=</span> z</span>
<span id="cb21-19"><a href="#cb21-19" aria-hidden="true" tabindex="-1"></a> [r, theta, z]</span>
<span id="cb21-20"><a href="#cb21-20" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span>
<span id="cb21-21"><a href="#cb21-21" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-22"><a href="#cb21-22" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span> <span class="fu">cartesian_from_cylindrical</span>(r, theta, z)</span>
<span id="cb21-23"><a href="#cb21-23" aria-hidden="true" tabindex="-1"></a> x <span class="op">=</span> <span class="fu">r*cos</span>(theta)</span>
<span id="cb21-24"><a href="#cb21-24" aria-hidden="true" tabindex="-1"></a> y <span class="op">=</span> <span class="fu">r*sin</span>(theta)</span>
<span id="cb21-25"><a href="#cb21-25" aria-hidden="true" tabindex="-1"></a> z <span class="op">=</span> z</span>
<span id="cb21-26"><a href="#cb21-26" aria-hidden="true" tabindex="-1"></a> [x, y, z]</span>
<span id="cb21-27"><a href="#cb21-27" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span>
<span id="cb21-28"><a href="#cb21-28" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-29"><a href="#cb21-29" aria-hidden="true" tabindex="-1"></a><span class="fu">spherical_from_cartesian</span>(v) <span class="op">=</span> <span class="fu">spherical_from_cartesian</span>(v<span class="op">...</span>)</span>
<span id="cb21-30"><a href="#cb21-30" aria-hidden="true" tabindex="-1"></a><span class="fu">cartesian_from_spherical</span>(v) <span class="op">=</span> <span class="fu">cartesian_from_spherical</span>(v<span class="op">...</span>)</span>
<span id="cb21-31"><a href="#cb21-31" aria-hidden="true" tabindex="-1"></a><span class="fu">cylindrical_from_cartesian</span>(v)<span class="op">=</span> <span class="fu">cylindrical_from_cartesian</span>(v<span class="op">...</span>)</span>
<span id="cb21-32"><a href="#cb21-32" aria-hidden="true" tabindex="-1"></a><span class="fu">cartesian_from_cylindrical</span>(v) <span class="op">=</span> <span class="fu">cartesian_from_cylindrical</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="19">
<pre><code>cartesian_from_cylindrical (generic function with 2 methods)</code></pre>
</div>
</div>
<p>The Jacobian of a transformation can be found from these conversions. For example, the conversion from spherical to cartesian would have Jacobian computed by:</p>
<div class="cell" data-execution_count="19">
<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="pp">@syms</span> r<span class="op">::</span><span class="dt">real</span></span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a>ex1 <span class="op">=</span> <span class="fu">cartesian_from_spherical</span>(r, theta, phi)</span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a>J1 <span class="op">=</span> ex1.<span class="fu">jacobian</span>([r, theta, phi])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="20">
<pre><code>3×3 Matrix{Sym}:
sin(φ)⋅cos(θ) -r⋅sin(φ)⋅sin(θ) r⋅cos(φ)⋅cos(θ)
sin(φ)⋅sin(θ) r⋅sin(φ)⋅cos(θ) r⋅sin(θ)⋅cos(φ)
cos(φ) 0 -r⋅sin(φ)</code></pre>
</div>
</div>
<p>This has determinant:</p>
<div class="cell" data-execution_count="20">
<div class="sourceCode cell-code" id="cb25"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="fu">det</span>(J1) <span class="op">|&gt;</span> simplify</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="21">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
- r^{2} \sin{\left(\phi \right)}
\]
</span>
</div>
</div>
<p>There is no function to convert from spherical to cylindrical above, but clearly one can be made by <em>composition</em>:</p>
<div class="cell" data-execution_count="21">
<div class="sourceCode cell-code" id="cb26"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cylindrical_from_spherical</span>(r, theta, phi) <span class="op">=</span></span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">cylindrical_from_cartesian</span>(<span class="fu">cartesian_from_spherical</span>(r, theta, phi)<span class="op">...</span>)</span>
<span id="cb26-3"><a href="#cb26-3" aria-hidden="true" tabindex="-1"></a><span class="fu">cylindrical_from_spherical</span>(v) <span class="op">=</span> <span class="fu">cylindrical_from_spherical</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="22">
<pre><code>cylindrical_from_spherical (generic function with 2 methods)</code></pre>
</div>
</div>
<p>From this composition, we could compute the Jacobian directly, as with:</p>
<div class="cell" data-execution_count="22">
<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>ex2 <span class="op">=</span> <span class="fu">cylindrical_from_spherical</span>(r, theta, phi)</span>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a>J2 <span class="op">=</span> ex2.<span class="fu">jacobian</span>([r, theta, phi])</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">
<pre><code>3×3 Matrix{Sym}:
(r*sin(phi)^2*sin(theta)^2 + r*sin(phi)^2*cos(theta)^2)/sqrt(r^2*sin(phi)^2*sin(theta)^2 + r^2*sin(phi)^2*cos(theta)^2) … (r^2*sin(phi)*sin(theta)^2*cos(phi) + r^2*sin(phi)*cos(phi)*cos(theta)^2)/sqrt(r^2*sin(phi)^2*sin(theta)^2 + r^2*sin(phi)^2*cos(theta)^2)
0 0
cos(φ) -r⋅sin(φ)</code></pre>
</div>
</div>
<p>Now to see that this last expression could have been found by the <em>chain rule</em>. To do this we need to find the Jacobian of each function; evaluate them at the proper places; and, finally, multiply the matrices. The <code>J1</code> object, found above, does one Jacobian. We now need to find that of <code>cylindrical_from_cartesian</code>:</p>
<div class="cell" data-execution_count="23">
<div class="sourceCode cell-code" id="cb30"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> x<span class="op">::</span><span class="dt">real </span>y<span class="op">::</span><span class="dt">real </span>z<span class="op">::</span><span class="dt">real</span></span>
<span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a>ex3 <span class="op">=</span> <span class="fu">cylindrical_from_cartesian</span>(x, y, z)</span>
<span id="cb30-3"><a href="#cb30-3" aria-hidden="true" tabindex="-1"></a>J3 <span class="op">=</span> ex3.<span class="fu">jacobian</span>([x,y,z])</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="24">
<pre><code>3×3 Matrix{Sym}:
x/sqrt(x^2 + y^2) y/sqrt(x^2 + y^2) 0
-y/(x^2*(1 + y^2/x^2)) 1/(x*(1 + y^2/x^2)) 0
0 0 1</code></pre>
</div>
</div>
<p>The chain rule is not simply <code>J3 * J1</code> in the notation above, as the <code>J3</code> matrix must be evaluated at “<code>G(a)</code>”, which is <code>ex1</code> from above:</p>
<div class="cell" data-execution_count="24">
<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>J3_Ga <span class="op">=</span> <span class="fu">subs</span>.(J3, x <span class="op">=&gt;</span> ex1[<span class="fl">1</span>], y <span class="op">=&gt;</span> ex1[<span class="fl">2</span>], z <span class="op">=&gt;</span> ex1[<span class="fl">3</span>]) <span class="op">.|&gt;</span> simplify <span class="co"># the dots are important</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="25">
<pre><code>3×3 Matrix{Sym}:
r*sin(phi)*cos(theta)/(sqrt(sin(phi)^2)*Abs(r)) … 0
-sin(theta)/(r*sin(phi)) 0
0 1</code></pre>
</div>
</div>
<p>The chain rule now says this product should be equivalent to <code>J2</code> above:</p>
<div class="cell" data-execution_count="25">
<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>J3_Ga <span class="op">*</span> J1</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="26">
<pre><code>3×3 Matrix{Sym}:
r*sin(phi)^2*sin(theta)^2/(sqrt(sin(phi)^2)*Abs(r)) + r*sin(phi)^2*cos(theta)^2/(sqrt(sin(phi)^2)*Abs(r)) … r^2*sin(phi)*sin(theta)^2*cos(phi)/(sqrt(sin(phi)^2)*Abs(r)) + r^2*sin(phi)*cos(phi)*cos(theta)^2/(sqrt(sin(phi)^2)*Abs(r))
0 0
cos(φ) -r⋅sin(φ)</code></pre>
</div>
</div>
<p>The two are equivalent after simplification, as seen here:</p>
<div class="cell" data-execution_count="26">
<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>J3_Ga <span class="op">*</span> J1 <span class="op">-</span> J2 <span class="op">.|&gt;</span> simplify</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">
<pre><code>3×3 Matrix{Sym}:
0 0 0
0 0 0
0 0 0</code></pre>
</div>
</div>
</section>
<section id="example" class="level5">
<h5 class="anchored" data-anchor-id="example">Example</h5>
<p>The above examples were done symbolically. Performing the calculation numerically is quite similar. The <code>ForwardDiff</code> package has a gradient function to find the gradient at a point. The <code>CalculusWithJulia</code> package extends this to take a gradient of a function and return a function, also called <code>gradient</code>. This is defined along the lines of:</p>
<div class="sourceCode cell-code" id="cb38"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb38-1"><a href="#cb38-1" aria-hidden="true" tabindex="-1"></a><span class="fu">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>(though more flexibly, as either vector or a separate arguments can be used.)</p>
<p>With this, defining a Jacobian function <em>could</em> be done like:</p>
<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="kw">function</span> <span class="fu">Jacobian</span>(F, x)</span>
<span id="cb39-2"><a href="#cb39-2" aria-hidden="true" tabindex="-1"></a> n <span class="op">=</span> <span class="fu">length</span>(<span class="fu">F</span>(x<span class="op">...</span>))</span>
<span id="cb39-3"><a href="#cb39-3" aria-hidden="true" tabindex="-1"></a> grads <span class="op">=</span> [<span class="fu">gradient</span>(x <span class="op">-&gt;</span> <span class="fu">F</span>(x<span class="op">...</span>)[i])(x) for i <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span>n]</span>
<span id="cb39-4"><a href="#cb39-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">vcat</span>(grads<span class="op">'...</span>)</span>
<span id="cb39-5"><a href="#cb39-5" 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>But, like <code>SymPy</code>, <code>ForwardDiff</code> provides a <code>jacobian</code> function directly, so we will use that; it requires a function definition where a vector is passed in and is called by <code>ForwardDiff.jacobian</code>. (The <code>ForwardDiff</code> package does not export its methods, they are qualified using the module name.)</p>
<p>Using the above functions, we can verify the last example at a point:</p>
<div class="cell" data-execution_count="29">
<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>rtp <span class="op">=</span> [<span class="fl">1</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">3</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">4</span>]</span>
<span id="cb40-2"><a href="#cb40-2" aria-hidden="true" tabindex="-1"></a>ForwardDiff.<span class="fu">jacobian</span>(cylindrical_from_spherical, rtp)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="28">
<pre><code>3×3 Matrix{Float64}:
0.707107 0.0 0.707107
0.0 1.0 0.0
0.707107 0.0 -0.707107</code></pre>
</div>
</div>
<p>The chain rule gives the same answer up to roundoff error:</p>
<div class="cell" data-execution_count="30">
<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>ForwardDiff.<span class="fu">jacobian</span>(cylindrical_from_cartesian, <span class="fu">cartesian_from_spherical</span>(rtp)) <span class="op">*</span> ForwardDiff.<span class="fu">jacobian</span>(cartesian_from_spherical, rtp)</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">
<pre><code>3×3 Matrix{Float64}:
0.707107 0.0 0.707107
5.55112e-17 1.0 5.55112e-17
0.707107 0.0 -0.707107</code></pre>
</div>
</div>
</section>
<section id="example-the-inverse-function-theorem" class="level5">
<h5 class="anchored" data-anchor-id="example-the-inverse-function-theorem">Example: The Inverse Function Theorem</h5>
<p>For a change of variable problem, <span class="math inline">\(F:R^n \rightarrow R^n\)</span>, the determinant of the Jacobian quantifies how volumes get modified under the transformation. When this determinant is <em>non</em>zero, then more can be said. The <a href="https://en.wikipedia.org/wiki/Inverse_function_theorem">Inverse Function Theorem</a> states</p>
<blockquote class="blockquote">
<p>if <span class="math inline">\(F\)</span> is a continuously differentiable function from an open set of <span class="math inline">\(R^n\)</span> into <span class="math inline">\(R^n\)</span>and the total derivative is invertible at a point <span class="math inline">\(p\)</span> (i.e., the Jacobian determinant of <span class="math inline">\(F\)</span> at <span class="math inline">\(p\)</span> is non-zero), then <span class="math inline">\(F\)</span> is invertible near <span class="math inline">\(p\)</span>. That is, an inverse function to <span class="math inline">\(F\)</span> is defined on some neighborhood of <span class="math inline">\(q\)</span>, where <span class="math inline">\(q=F(p)\)</span>. Further, <span class="math inline">\(F^{-1}\)</span> will be continuously differentiable at <span class="math inline">\(q\)</span> with <span class="math inline">\(J_{F^{-1}}(q) = [J_F(p)]^{-1}\)</span>, the latter being the matrix inverse. Taking determinants, <span class="math inline">\(\det(J_{F^{-1}}(q)) = 1/\det(J_F(p))\)</span>.</p>
</blockquote>
<p>Assuming <span class="math inline">\(F^{-1}\)</span> exists, we can verify the last part from the chain rule, in an identical manner to the univariate case, starting with <span class="math inline">\(F^{-1} \circ F\)</span> being the identity, we would have:</p>
<p><span class="math display">\[
J_{F^{-1}\circ F}(p) = I,
\]</span></p>
<p>where <span class="math inline">\(I\)</span> is the <em>identity</em> matrix with entry <span class="math inline">\(a_{ij} = 1\)</span> when <span class="math inline">\(i=j\)</span> and <span class="math inline">\(0\)</span> otherwise.</p>
<p>But the chain rule then says <span class="math inline">\(J_{F^{-1}}(F(p)) J_F(p) = I\)</span>. This implies the two matrices are inverses to each other, and using the multiplicative mapping property of the determinant will also imply the determinant relationship.</p>
<p>The theorem is an existential theorem, in that it implies <span class="math inline">\(F^{-1}\)</span> exists, but doesnt indicate how to find it. When we have an inverse though, we can verify the properties implied.</p>
<p>The transformation examples have inverses indicated. Using one of these we can verify things at a point, as done in the following:</p>
<div class="cell" data-execution_count="31">
<div class="sourceCode cell-code" id="cb44"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb44-1"><a href="#cb44-1" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> [<span class="fl">1</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">3</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">4</span>]</span>
<span id="cb44-2"><a href="#cb44-2" aria-hidden="true" tabindex="-1"></a>q <span class="op">=</span> <span class="fu">cartesian_from_spherical</span>(p)</span>
<span id="cb44-3"><a href="#cb44-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-4"><a href="#cb44-4" aria-hidden="true" tabindex="-1"></a>A1 <span class="op">=</span> ForwardDiff.<span class="fu">jacobian</span>(spherical_from_cartesian, q) <span class="co"># J_F⁻¹(q)</span></span>
<span id="cb44-5"><a href="#cb44-5" aria-hidden="true" tabindex="-1"></a>A2 <span class="op">=</span> ForwardDiff.<span class="fu">jacobian</span>(cartesian_from_spherical, p) <span class="co"># J_F(p)</span></span>
<span id="cb44-6"><a href="#cb44-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-7"><a href="#cb44-7" aria-hidden="true" tabindex="-1"></a>A1 <span class="op">*</span> A2</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="30">
<pre><code>3×3 Matrix{Float64}:
1.0 0.0 0.0
5.55112e-17 1.0 5.55112e-17
0.0 0.0 1.0</code></pre>
</div>
</div>
<p>Up to roundoff error, this is the identity matrix. As for the relationship between the determinants, up to roundoff error the two are related, as expected:</p>
<div class="cell" data-execution_count="32">
<div class="sourceCode cell-code" id="cb46"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb46-1"><a href="#cb46-1" aria-hidden="true" tabindex="-1"></a><span class="fu">det</span>(A1), <span class="fl">1</span><span class="op">/</span><span class="fu">det</span>(A2)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="31">
<pre><code>(-1.4142135623730956, -1.4142135623730951)</code></pre>
</div>
</div>
</section>
<section id="example-implicit-differentiation-the-implicit-function-theorem" class="level5">
<h5 class="anchored" data-anchor-id="example-implicit-differentiation-the-implicit-function-theorem">Example: Implicit Differentiation, the Implicit Function Theorem</h5>
<p>The technique of <em>implicit differentiation</em> is a useful one, as it allows derivatives of more complicated expressions to be found. The main idea, expressed here with three variables is if an equation may be viewed as <span class="math inline">\(F(x,y,z) = c\)</span>, <span class="math inline">\(c\)</span> a constant, then <span class="math inline">\(z=\phi(x,y)\)</span> may be viewed as a function of <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span>. Hence, we can use the chain rule to find: <span class="math inline">\(\partial z / \partial x\)</span> and <span class="math inline">\(\partial z /\partial x\)</span>. Let <span class="math inline">\(G(x,y) = \langle x, y, \phi(x,y) \rangle\)</span> and then differentiation <span class="math inline">\((F \circ G)(x,y) = c\)</span>:</p>
<p><span class="math display">\[
\begin{align*}
0 &amp;= dF_{G(x,y)} \circ dG_{\langle x, y\rangle}\\
&amp;= [\frac{\partial F}{\partial x}\quad \frac{\partial F}{\partial y}\quad \frac{\partial F}{\partial z}](G(x,y)) \cdot
\left[\begin{array}{}
1 &amp; 0\\
0 &amp; 1\\
\frac{\partial \phi}{\partial x} &amp; \frac{\partial \phi}{\partial y}
\end{array}\right].
\end{align*}
\]</span></p>
<p>Solving yields</p>
<p><span class="math display">\[
\frac{\partial \phi}{\partial x} = -\frac{\partial F/\partial x}{\partial F/\partial z},\quad
\frac{\partial \phi}{\partial y} = -\frac{\partial F/\partial y}{\partial F/\partial z}.
\]</span></p>
<p>Where the right hand side of each is evaluated at <span class="math inline">\(G(x,y)\)</span>.</p>
<p>When can it be reasonably assumed that such a function <span class="math inline">\(z= \phi(x,y)\)</span> exists?</p>
<p>The <a href="https://en.wikipedia.org/wiki/Implicit_function_theorem">Implicit Function Theorem</a> provides a statement (slightly abridged here):</p>
<blockquote class="blockquote">
<p>Let <span class="math inline">\(F:R^{n+m} \rightarrow R^m\)</span> be a continuously differentiable function and let <span class="math inline">\(R^{n+m}\)</span> have (compactly defined) coordinates <span class="math inline">\(\langle \vec{x}, \vec{y} \rangle\)</span>, Fix a point <span class="math inline">\(\langle \vec{a}, \vec{b} \rangle\)</span> with <span class="math inline">\(F(\vec{a}, \vec{b}) = \vec{0}\)</span>. Let <span class="math inline">\(J_{F, \vec{y}}(\vec{a}, \vec{b})\)</span> be the Jacobian restricted to <em>just</em> the <span class="math inline">\(y\)</span> variables. (<span class="math inline">\(J\)</span> is <span class="math inline">\(m \times m\)</span>.) If this matrix has non-zero determinant (it is invertible), then there exists an open set <span class="math inline">\(U\)</span> containing <span class="math inline">\(\vec{a}\)</span> and a <em>unique</em> continuously differentiable function <span class="math inline">\(G: U \subset R^n \rightarrow R^m\)</span> such that <span class="math inline">\(G(\vec{a}) = \vec{b}\)</span>, <span class="math inline">\(F(\vec{x}, G(\vec{x})) = 0\)</span> for <span class="math inline">\(\vec x\)</span> in <span class="math inline">\(U\)</span>. Moreover, the partial derivatives of <span class="math inline">\(G\)</span> are given by the matrix product:</p>
<p><span class="math inline">\(\frac{\partial G}{\partial x_j}(\vec{x}) = - [J_{F, \vec{y}}(x, F(\vec{x}))]^{-1} \left[\frac{\partial F}{\partial x_j}(x, G(\vec{x}))\right].\)</span></p>
</blockquote>
<hr>
<p>Specializing to our case above, we have <span class="math inline">\(f:R^{2+1}\rightarrow R^1\)</span> and <span class="math inline">\(\vec{x} = \langle a, b\rangle\)</span> and <span class="math inline">\(\phi:R^2 \rightarrow R\)</span>. Then</p>
<p><span class="math display">\[
[J_{f, \vec{y}}(x, g(\vec{x}))] = [\frac{\partial f}{\partial z}(a, b, \phi(a,b)],
\]</span></p>
<p>a <span class="math inline">\(1\times 1\)</span> matrix, identified as a scalar, so inversion is just the reciprocal. So the formula, becomes, say for <span class="math inline">\(x_1 = x\)</span>:</p>
<p><span class="math display">\[
\frac{\partial \phi}{\partial x}(a, b) = - \frac{\frac{\partial{f}}{\partial{x}}(a, b,\phi(a,b))}{\frac{\partial{f}}{\partial{z}}(a, b, \phi(a,b))},
\]</span></p>
<p>as expressed above. Here invertibility is simply a non-zero value, and is needed for the division. In general, we see inverse (the <span class="math inline">\(J^{-1}\)</span>) is necessary to express the answer.</p>
<p>Using this, we can answer questions like the following (as we did before) on a more solid ground:</p>
<p>Let <span class="math inline">\(x^2/a^2 + y^2/b^2 + z^2/c^2 = 1\)</span> be an equation describing an ellipsoid. Describe the tangent plane at a point on the ellipse.</p>
<p>We would like to express the tangent plane in terms of <span class="math inline">\(\partial{z}/\partial{x}\)</span> and <span class="math inline">\(\partial{z}/\partial{y}\)</span>, which we can do through:</p>
<p><span class="math display">\[
\frac{2x}{a^2} + \frac{2z}{c^2} \frac{\partial{z}}{\partial{x}} = 0, \quad
\frac{2y}{a^2} + \frac{2z}{c^2} \frac{\partial{z}}{\partial{y}} = 0.
\]</span></p>
<p>Solving, we get</p>
<p><span class="math display">\[
\frac{\partial{z}}{\partial{x}} = -\frac{2x}{a^2}\frac{c^2}{2z},
\quad
\frac{\partial{z}}{\partial{y}} = -\frac{2y}{a^2}\frac{c^2}{2z},
\]</span></p>
<p><em>provided</em> <span class="math inline">\(z \neq 0\)</span>. At <span class="math inline">\(z=0\)</span> the tangent plane exists, but we cant describe it in this manner, as it is vertical. However, the choice of variables to use is not fixed in the theorem, so if <span class="math inline">\(x \neq 0\)</span> we can express <span class="math inline">\(x = x(y,z)\)</span> and express the tangent plane in terms of <span class="math inline">\(\partial{x}/\partial{y}\)</span> and <span class="math inline">\(\partial{x}/\partial{z}\)</span>. The answer is similar to the above, and we wont repeat. Similarly, should <span class="math inline">\(x = z = 0\)</span>, the <span class="math inline">\(y \neq 0\)</span> and we can use an implicit definition <span class="math inline">\(y = y(x,z)\)</span> and express the tangent plane through <span class="math inline">\(\partial{y}/\partial{x}\)</span> and <span class="math inline">\(\partial{y}/\partial{z}\)</span>.</p>
</section>
<section id="example-lagrange-multipliers-in-more-dimensions" class="level5">
<h5 class="anchored" data-anchor-id="example-lagrange-multipliers-in-more-dimensions">Example: Lagrange multipliers in more dimensions</h5>
<p>Consider now the problem of maximizing <span class="math inline">\(f:R^n \rightarrow R\)</span> subject to <span class="math inline">\(k &lt; n\)</span> constraints <span class="math inline">\(g_1(\vec{x}) = c_1, g_2(\vec{x}) = c_2, \dots, g_{k}(\vec{x}) = c_{k}\)</span>. For <span class="math inline">\(n=1\)</span> and <span class="math inline">\(2\)</span>, we saw that if all derivatives exist, then a <em>necessary</em> condition to be at a maximum is that <span class="math inline">\(\nabla{f}\)</span> can be written as <span class="math inline">\(\lambda_1 \nabla{g_1}\)</span> (<span class="math inline">\(n=1\)</span>) or <span class="math inline">\(\lambda_1 \nabla{g_1} + \lambda_2 \nabla{g_2}\)</span>. The key observation is that the gradient of <span class="math inline">\(f\)</span> must have no projection on the intersection of the tangent planes found by linearizing <span class="math inline">\(g_i\)</span>.</p>
<p>The same thing holds in dimension <span class="math inline">\(n &gt; 2\)</span>: Let <span class="math inline">\(\vec{x}_0\)</span> be a point where <span class="math inline">\(f(\vec{x})\)</span> is maximum subject to the <span class="math inline">\(p\)</span> constraints. We want to show that <span class="math inline">\(\vec{x}_0\)</span> must satisfy:</p>
<p><span class="math display">\[
\nabla{f}(\vec{x}_0) = \sum \lambda_i \nabla{g_i}(\vec{x}_0).
\]</span></p>
<p>By considering <span class="math inline">\(-f\)</span>, the same holds for a minimum.</p>
<p>We follow the sketch of <a href="https://www.math.wustl.edu/~sawyer/handouts/LagrangeMult.pdf">Sawyer</a>.</p>
<p>Using Taylors theorem, we have <span class="math inline">\(f(\vec{x} + h \vec{y}) = f(\vec{x}) + h \vec{y}\cdot\nabla{f} + h^2\vec{c}\)</span>, for some <span class="math inline">\(\vec{c}\)</span>. If <span class="math inline">\(h\)</span> is small enough, this term can be ignored.</p>
<p>The tangent “plane” for each constraint, <span class="math inline">\(g_i(\vec{x}) = c_i\)</span>, is orthogonal to the gradient vector <span class="math inline">\(\nabla{g_i}(\vec{x})\)</span>. That is, <span class="math inline">\(\nabla{g_i}(\vec{x})\)</span> is orthogonal to the level-surface formed by the constraint <span class="math inline">\(g_i(\vec{x}) = 0\)</span>. Let <span class="math inline">\(A\)</span> be the set of all <em>linear</em> combinations of <span class="math inline">\(\nabla{g_i}\)</span>, that are possible: <span class="math inline">\(\lambda_1 g_1(\vec{x}) + \lambda_2 g_2(\vec{x}) + \cdots + \lambda_p g_p(\vec{x})\)</span>, as in the statement. Through projection, we can write <span class="math inline">\(\nabla{f}(\vec{x}_0) = \vec{a} + \vec{b}\)</span>, where <span class="math inline">\(\vec{a}\)</span> is in <span class="math inline">\(A\)</span> and <span class="math inline">\(\vec{b}\)</span> is <em>orthogonal</em> to <span class="math inline">\(A\)</span>.</p>
<p>Let <span class="math inline">\(\vec{r}(t)\)</span> be a parameterization of a path through the intersection of the <span class="math inline">\(p\)</span> tangent planes that goes through <span class="math inline">\(\vec{x}_0\)</span> at <span class="math inline">\(t_0\)</span> <em>and</em> <span class="math inline">\(\vec{b}\)</span> is parallel to <span class="math inline">\(\vec{x}_0'(t_0)\)</span>. (The implicit function theorem would guarantee this path.)</p>
<p>If we consider <span class="math inline">\(f(\vec{x}_0 + h \vec{b})\)</span> for small <span class="math inline">\(h\)</span>, then unless <span class="math inline">\(\vec{b} \cdot \nabla{f} = 0\)</span>, the function would increase in the direction of <span class="math inline">\(\vec{b}\)</span> due to the <span class="math inline">\(h \vec{b}\cdot\nabla{f}\)</span> term in the approximating Taylor series. That is, <span class="math inline">\(\vec{x}_0\)</span> would not be a maximum on the constraint. So at <span class="math inline">\(\vec{x}_0\)</span> this directional derivative is <span class="math inline">\(0\)</span>.</p>
<p>Then we have the directional derivative in the direction of <span class="math inline">\(b\)</span> is <span class="math inline">\(\vec{0}\)</span>, as the gradient</p>
<p><span class="math display">\[
\vec{0} = \vec{b} \cdot \nabla{f}(\vec{x}_0) = \vec{b} \cdot (\vec{a} + \vec{b}) = \vec{b}\cdot \vec{a} + \vec{b}\cdot\vec{b} = \vec{b}\cdot\vec{b},
\]</span></p>
<p>or <span class="math inline">\(\| \vec{b} \| = 0\)</span> and <span class="math inline">\(\nabla{f}(\vec{x}_0)\)</span> must lie in the plane <span class="math inline">\(A\)</span>.</p>
<hr>
<p>How does the implicit function theorem guarantee a parameterization of a curve along the constraint in the direction of <span class="math inline">\(b\)</span>?</p>
<p>A formal proof requires a bit of linear algebra, but here we go. Let <span class="math inline">\(G(\vec{x}) = \langle g_1(\vec{x}), g_2(\vec{x}), \dots, g_k(\vec{x}) \rangle\)</span>. Then <span class="math inline">\(G(\vec{x}) = \vec{c}\)</span> encodes the constraint. The tangent planes are orthogonal to each <span class="math inline">\(\nabla{g_i}\)</span>, so using matrix notation, the intersection of the tangent planes is any vector <span class="math inline">\(\vec{h}\)</span> satisfying <span class="math inline">\(J_G(\vec{x}_0) \vec{h} = 0\)</span>. Let <span class="math inline">\(k = n - 1 - p\)</span>. If <span class="math inline">\(k &gt; 0\)</span>, there will be <span class="math inline">\(k\)</span> vectors <em>orthogonal</em> to each of <span class="math inline">\(\nabla{g_i}\)</span> and <span class="math inline">\(\vec{b}\)</span>. Call these <span class="math inline">\(\vec{v}_j\)</span>. Then define additional constraints <span class="math inline">\(h_j(\vec{x}) = \vec{v}_j \cdot \vec{x} = 0\)</span>. Let <span class="math inline">\(H(x_1, x_2, \dots, x_n) = \langle g_1, g_2, \dots, g_p, h_1, \dots, h_{n-1-p}\rangle\)</span>. <span class="math inline">\(H:R^{1 + (n-1)} \rightarrow R^{n-1}\)</span>. Let <span class="math inline">\(H(x_1, \dots, x_n) = H(x, \vec{y})\)</span> The <span class="math inline">\(H\)</span> <em>restricted</em> to the <span class="math inline">\(\vec{y}\)</span> variables is a function from <span class="math inline">\(R^{n-1}\rightarrow R^{n-1}\)</span>. <em>If</em> this restricted function has a Jacobian with non-zero determinant, then there exists a <span class="math inline">\(\vec\phi(x): R \rightarrow R^{n-1}\)</span> with <span class="math inline">\(H(x, \vec\phi(x)) = \vec{c}\)</span>. Let <span class="math inline">\(\vec{r}(t) = \langle t, \phi_1(t), \dots, \phi_{n-1}(t)\rangle\)</span>. Then <span class="math inline">\((H\circ\vec{r})(t) = \vec{c}\)</span>, so by the chain rule <span class="math inline">\(d_H(\vec{r}) d\vec{r} = 0\)</span>. But <span class="math inline">\(dH = [\nabla{g_1}'; \nabla{g_2}' \dots;\nabla{g_p}', v_1';\dots;v_{n-1-p}']\)</span> (A matrix of row vectors). The condition <span class="math inline">\(dH(\vec{r}) d\vec{r} = \vec{0}\)</span> is equivalent to saying <span class="math inline">\(d\vec{r}\)</span> is <em>orthogonal</em> to the row vectors in <span class="math inline">\(dH\)</span>. A <em>basis</em> for <span class="math inline">\(R^n\)</span> are these vectors and <span class="math inline">\(\vec{b}\)</span>, so <span class="math inline">\(\vec{r}\)</span> and <span class="math inline">\(\vec{b}\)</span> must be parallel.</p>
</section>
<section id="example-1" class="level5">
<h5 class="anchored" data-anchor-id="example-1">Example</h5>
<p>We apply this to two problems, also from Sawyer. First, let <span class="math inline">\(n &gt; 1\)</span> and <span class="math inline">\(f(x_1, \dots, x_n) = \sum x_i^2\)</span>. Minimize this subject to the constraint <span class="math inline">\(\sum x_i = 1\)</span>. This one constraint means an answer must satisfy <span class="math inline">\(\nabla{L} = \vec{0}\)</span> where</p>
<p><span class="math display">\[
L(x_1, \dots, x_n, \lambda) = \sum x_i^2 + \lambda \sum x_i - 1.
\]</span></p>
<p>Taking <span class="math inline">\(\partial/\partial{x_i}\)</span> we have <span class="math inline">\(2x_i + \lambda = 0\)</span>, so <span class="math inline">\(x_i = \lambda/2\)</span>, a constant. From the constraint, we see <span class="math inline">\(x_i = 1/n\)</span>. This does not correspond to a maximum, but a minimum. A maximum would be at point on the constraint such as <span class="math inline">\(\langle 1, 0, \dots, 0\rangle\)</span>, which gives a value of <span class="math inline">\(1\)</span> for <span class="math inline">\(f\)</span>, not <span class="math inline">\(n \times 1/n^2 = 1/n\)</span>.</p>
</section>
<section id="example-2" class="level5">
<h5 class="anchored" data-anchor-id="example-2">Example</h5>
<p>In statistics, there are different ways to define the best estimate for a population parameter based on the data. That is, suppose <span class="math inline">\(X_1, X_2, \dots, X_n\)</span> are random variables. The population parameters of interest here are the mean <span class="math inline">\(E(X_i) = \mu\)</span> and the variance <span class="math inline">\(Var(X_i) = \sigma_i^2\)</span>. (The mean is assumed to be the same for all, but the variance need not be.) What should someone use to <em>estimate</em> <span class="math inline">\(\mu\)</span> using just the sample values <span class="math inline">\(X_1, X_2, \dots, X_n\)</span>? The average, <span class="math inline">\((X_1 + \cdots + X_n)/n\)</span> is a well known estimate, but is it the “best” in some sense for this set up? Here some variables are more variable, should they count the same, more, or less in the weighting for the estimate?</p>
<p>In Sawyer, we see an example of applying the Lagrange multiplier method to the best linear unbiased estimator (BLUE). The BLUE is a choice of coefficients <span class="math inline">\(a_i\)</span> such that <span class="math inline">\(Var(\sum a_i X_i)\)</span> is smallest subject to the constraint <span class="math inline">\(E(\sum a_i X_i) = \mu\)</span>.</p>
<p>The BLUE <em>minimizes</em> the <em>variance</em> of the estimator. (This is the <em>B</em>est part of BLUE). The estimator, <span class="math inline">\(\sum a_i X_i\)</span>, is <em>L</em>inear. The constraint is that the estimator has theoretical mean given by <span class="math inline">\(\mu\)</span>. (This is the <em>Un</em>biased part of BLUE.)</p>
<p>Going from statistics to mathematics, we use formulas for <em>independent</em> random variables to restate this problem mathematically as:</p>
<p><span class="math display">\[
\text{Minimize } \sum a_i^2 \sigma_i^2 \text{ subject to } \sum a_i = 1.
\]</span></p>
<p>This problem is similar now to the last one, save the sum to minimize includes the sigmas. Set <span class="math inline">\(L = \sum a_i^2 \sigma_i^2 + \lambda\sum a_i - 1\)</span></p>
<p>Taking <span class="math inline">\(\partial/\partial{a_i}\)</span> gives equations <span class="math inline">\(2a_i\sigma_i^2 + \lambda = 0\)</span>, <span class="math inline">\(a_i = -\lambda/(2\sigma_i^2) = c/\sigma_i^2\)</span>. The constraint implies <span class="math inline">\(c = 1/\sum(1/\sigma_i)^2\)</span>. So variables with <em>more</em> variance, get smaller weights.</p>
<p>For the special case of a common variance, <span class="math inline">\(\sigma_i=\sigma\)</span>, the above simplifies to <span class="math inline">\(a_i = 1/n\)</span> and the estimator is <span class="math inline">\(\sum X_i/n\)</span>, the familiar sample mean, <span class="math inline">\(\bar{X}\)</span>.</p>
</section>
</section>
</section>
<section id="questions" class="level2" data-number="57.5">
<h2 data-number="57.5" class="anchored" data-anchor-id="questions"><span class="header-section-number">57.5</span> Questions</h2>
<section id="question" class="level6">
<h6 class="anchored" data-anchor-id="question">Question</h6>
<p>The following plots a surface defined by a (hidden) function <span class="math inline">\(F: R^2 \rightarrow R^3\)</span>:</p>
<div class="cell" data-execution_count="33">
<div class="cell-output cell-output-display" data-execution_count="32">
<pre><code>𝑭 (generic function with 1 method)</code></pre>
</div>
</div>
<div class="cell" data-hold="true" data-execution_count="34">
<div class="sourceCode cell-code" id="cb49"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb49-1"><a href="#cb49-1" aria-hidden="true" tabindex="-1"></a>us, vs <span class="op">=</span> <span class="fu">range</span>(<span class="fl">0</span>, <span class="fl">1</span>, length<span class="op">=</span><span class="fl">25</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">25</span>)</span>
<span id="cb49-2"><a href="#cb49-2" aria-hidden="true" tabindex="-1"></a>xs, ys, zs <span class="op">=</span> <span class="fu">unzip</span>(<span class="fu">𝑭</span>.(us, vs<span class="op">'</span>))</span>
<span id="cb49-3"><a href="#cb49-3" 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="33">
<p><img src="vector_fields_files/figure-html/cell-35-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Is this the surface generated by <span class="math inline">\(F(u,v) = \langle u\cos(v), u\sin(v), 2v\rangle\)</span>? This functions surface is termed a helicoid.</p>
<div class="cell" data-hold="true" data-execution_count="35">
<div class="cell-output cell-output-display" data-execution_count="34">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="8589866647376903529" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_8589866647376903529">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_8589866647376903529_1">
<input class="form-check-input" type="radio" name="radio_8589866647376903529" id="radio_8589866647376903529_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_8589866647376903529_2">
<input class="form-check-input" type="radio" name="radio_8589866647376903529" id="radio_8589866647376903529_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="8589866647376903529_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_8589866647376903529"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('8589866647376903529_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_8589866647376903529")
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_8589866647376903529")
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>The following plots a surface defined by a (hidden) function <span class="math inline">\(F: R^2 \rightarrow R^3\)</span> of the form <span class="math inline">\(F(u,v) = \langle r(u)\cos(v), r(u)\sin(v), u\rangle\)</span></p>
<div class="cell" data-execution_count="36">
<div class="cell-output cell-output-display" data-execution_count="35">
<pre><code> (generic function with 1 method)</code></pre>
</div>
</div>
<div class="cell" data-hold="true" data-execution_count="37">
<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>us, vs <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">25</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">25</span>)</span>
<span id="cb51-2"><a href="#cb51-2" aria-hidden="true" tabindex="-1"></a>xs, ys, zs <span class="op">=</span> <span class="fu">unzip</span>(<span class="fu"></span>.(us, vs<span class="op">'</span>))</span>
<span id="cb51-3"><a href="#cb51-3" 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="36">
<p><img src="vector_fields_files/figure-html/cell-38-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Is this the surface generated by <span class="math inline">\(r(u) = 1+u^2\)</span>? This form of a function is for a surface of revolution about the <span class="math inline">\(z\)</span> axis.</p>
<div class="cell" data-hold="true" data-execution_count="38">
<div class="cell-output cell-output-display" data-execution_count="37">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="13703474247715626601" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_13703474247715626601">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_13703474247715626601_1">
<input class="form-check-input" type="radio" name="radio_13703474247715626601" id="radio_13703474247715626601_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13703474247715626601_2">
<input class="form-check-input" type="radio" name="radio_13703474247715626601" id="radio_13703474247715626601_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="13703474247715626601_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_13703474247715626601"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('13703474247715626601_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_13703474247715626601")
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_13703474247715626601")
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 transformation <span class="math inline">\(F(x, y) = \langle 2x + 3y + 1, 4x + y + 2\rangle\)</span> is an example of an affine transformation. Is this the <em>Jacobian</em> of <span class="math inline">\(F\)</span></p>
<p><span class="math display">\[
J = \left[
\begin{array}{}
2 &amp; 4\\
3 &amp; 1
\end{array}
\right].
\]</span></p>
<div class="cell" data-hold="true" data-execution_count="39">
<div class="cell-output cell-output-display" data-execution_count="38">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="8004413114410941174" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_8004413114410941174">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_8004413114410941174_1">
<input class="form-check-input" type="radio" name="radio_8004413114410941174" id="radio_8004413114410941174_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_8004413114410941174_2">
<input class="form-check-input" type="radio" name="radio_8004413114410941174" id="radio_8004413114410941174_2" value="2">
<span class="label-body px-1">
No, it is the transpose
</span>
</label>
</div>
</div>
</div>
<div id="8004413114410941174_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_8004413114410941174"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('8004413114410941174_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_8004413114410941174")
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_8004413114410941174")
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>Does the transformation <span class="math inline">\(F(u,v) = \langle u^2 - v^2, u^2 + v^2 \rangle\)</span> have Jacobian</p>
<p><span class="math display">\[
J = \left[
\begin{array}{}
2u &amp; -2v\\
2u &amp; 2v
\end{array}
\right]?
\]</span></p>
<div class="cell" data-hold="true" data-execution_count="40">
<div class="cell-output cell-output-display" data-execution_count="39">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15614370043605729475" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_15614370043605729475">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_15614370043605729475_1">
<input class="form-check-input" type="radio" name="radio_15614370043605729475" id="radio_15614370043605729475_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_15614370043605729475_2">
<input class="form-check-input" type="radio" name="radio_15614370043605729475" id="radio_15614370043605729475_2" value="2">
<span class="label-body px-1">
No, it is the transpose
</span>
</label>
</div>
</div>
</div>
<div id="15614370043605729475_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_15614370043605729475"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('15614370043605729475_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_15614370043605729475")
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_15614370043605729475")
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>Fix constants <span class="math inline">\(\lambda_0\)</span> and <span class="math inline">\(\phi_0\)</span> and define a transformation</p>
<p><span class="math display">\[
F(\lambda, \phi) = \langle \cos(\phi)\sin(\lambda - \lambda_0),
\cos(\phi_0)\sin(\phi) - \sin(\phi_0)\cos(\phi)\cos(\lambda - \lambda_0) \rangle
\]</span></p>
<p>What does the following <code>SymPy</code> code compute?</p>
<div class="cell" data-hold="true" data-execution_count="41">
<div class="sourceCode cell-code" id="cb52"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb52-1"><a href="#cb52-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> lambda lambda_0 phi phi_0</span>
<span id="cb52-2"><a href="#cb52-2" aria-hidden="true" tabindex="-1"></a><span class="fu">F</span>(lambda,phi) <span class="op">=</span> [<span class="fu">cos</span>(phi)<span class="fu">*sin</span>(lambda<span class="op">-</span>lambda_0), <span class="fu">cos</span>(phi_0)<span class="fu">*sin</span>(phi) <span class="op">-</span> <span class="fu">sin</span>(phi_0)<span class="fu">*cos</span>(phi)<span class="fu">*cos</span>(lambda<span class="op">-</span>lambda_0)]</span>
<span id="cb52-3"><a href="#cb52-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb52-4"><a href="#cb52-4" aria-hidden="true" tabindex="-1"></a>out <span class="op">=</span> [<span class="fu">diff</span>.(<span class="fu">F</span>(lambda, phi), lambda) <span class="fu">diff</span>.(<span class="fu">F</span>(lambda, phi), phi)]</span>
<span id="cb52-5"><a href="#cb52-5" aria-hidden="true" tabindex="-1"></a><span class="fu">det</span>(out) <span class="op">|&gt;</span> simplify</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="40">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
\left(\sin{\left(\phi \right)} \sin{\left(\phi_{0} \right)} + \cos{\left(\phi \right)} \cos{\left(\phi_{0} \right)} \cos{\left(\lambda - \lambda_{0} \right)}\right) \cos{\left(\phi \right)}
\]
</span>
</div>
</div>
<div class="cell" data-hold="true" data-execution_count="42">
<div class="cell-output cell-output-display" data-execution_count="41">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12145389244230523099" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_12145389244230523099">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_12145389244230523099_1">
<input class="form-check-input" type="radio" name="radio_12145389244230523099" id="radio_12145389244230523099_1" value="1">
<span class="label-body px-1">
The determinant of the Jacobian.
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12145389244230523099_2">
<input class="form-check-input" type="radio" name="radio_12145389244230523099" id="radio_12145389244230523099_2" value="2">
<span class="label-body px-1">
The determinant of the Hessian.
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12145389244230523099_3">
<input class="form-check-input" type="radio" name="radio_12145389244230523099" id="radio_12145389244230523099_3" value="3">
<span class="label-body px-1">
The determinant of the gradient.
</span>
</label>
</div>
</div>
</div>
<div id="12145389244230523099_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_12145389244230523099"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('12145389244230523099_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_12145389244230523099")
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_12145389244230523099")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>What would be a more direct method:</p>
<div class="cell" data-hold="true" data-execution_count="43">
<div class="cell-output cell-output-display" data-execution_count="42">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="3355295605918831792" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_3355295605918831792">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_3355295605918831792_1">
<input class="form-check-input" type="radio" name="radio_3355295605918831792" id="radio_3355295605918831792_1" value="1">
<span class="label-body px-1">
<code>det(F(lambda, phi).jacobian([lambda, phi]))</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_3355295605918831792_2">
<input class="form-check-input" type="radio" name="radio_3355295605918831792" id="radio_3355295605918831792_2" value="2">
<span class="label-body px-1">
<code>det(hessian(F(lambda, phi), [lambda, phi]))</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_3355295605918831792_3">
<input class="form-check-input" type="radio" name="radio_3355295605918831792" id="radio_3355295605918831792_3" value="3">
<span class="label-body px-1">
<code>det(gradient(F(lambda, phi), [lambda, phi]))</code>
</span>
</label>
</div>
</div>
</div>
<div id="3355295605918831792_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_3355295605918831792"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('3355295605918831792_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_3355295605918831792")
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_3355295605918831792")
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">\(z\sin(z) = x^3y^2 + z\)</span>. Compute <span class="math inline">\(\partial{z}/\partial{x}\)</span> implicitly.</p>
<div class="cell" data-hold="true" data-execution_count="44">
<div class="cell-output cell-output-display" data-execution_count="43">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="7018523299067317149" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_7018523299067317149">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_7018523299067317149_1">
<input class="form-check-input" type="radio" name="radio_7018523299067317149" id="radio_7018523299067317149_1" value="1">
<span class="label-body px-1">
\(3x^2y^2/(z\cos(z) + \sin(z) + 1)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7018523299067317149_2">
<input class="form-check-input" type="radio" name="radio_7018523299067317149" id="radio_7018523299067317149_2" value="2">
<span class="label-body px-1">
\(2x^3y/ (z\cos(z) + \sin(z) + 1)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7018523299067317149_3">
<input class="form-check-input" type="radio" name="radio_7018523299067317149" id="radio_7018523299067317149_3" value="3">
<span class="label-body px-1">
\(3x^2y^2\)
</span>
</label>
</div>
</div>
</div>
<div id="7018523299067317149_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_7018523299067317149"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('7018523299067317149_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_7018523299067317149")
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_7018523299067317149")
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">\(x^4 + y^4 + z^4 + x^2y^2z^2 = 1\)</span>. Compute <span class="math inline">\(\partial{z}/\partial{y}\)</span> implicitly.</p>
<div class="cell" data-hold="true" data-execution_count="45">
<div class="cell-output cell-output-display" data-execution_count="44">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="16018344788696371314" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_16018344788696371314">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_16018344788696371314_1">
<input class="form-check-input" type="radio" name="radio_16018344788696371314" id="radio_16018344788696371314_1" value="1">
<span class="label-body px-1">
\(\frac{y \left(- x^{2} z^{2}{\left (x,y \right )} + 2 y^{2}\right)}{\left(x^{2} y^{2} - 2 z^{2}{\left (x,y \right )}\right) z{\left (x,y \right )}}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_16018344788696371314_2">
<input class="form-check-input" type="radio" name="radio_16018344788696371314" id="radio_16018344788696371314_2" value="2">
<span class="label-body px-1">
\(\frac{x \left(2 x^{2} - z^{2}{\left (x,y \right )}\right)}{\left(x^{2} - 2 z^{2}{\left (x,y \right )}\right) z{\left (x,y \right )}}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_16018344788696371314_3">
<input class="form-check-input" type="radio" name="radio_16018344788696371314" id="radio_16018344788696371314_3" value="3">
<span class="label-body px-1">
\(\frac{x \left(2 x^{2} - y^{2} z^{2}{\left (x,y \right )}\right)}{\left(x^{2} y^{2} - 2 z^{2}{\left (x,y \right )}\right) z{\left (x,y \right )}}\)
</span>
</label>
</div>
</div>
</div>
<div id="16018344788696371314_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_16018344788696371314"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('16018344788696371314_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_16018344788696371314")
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_16018344788696371314")
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>Consider the vector field <span class="math inline">\(R:R^2 \rightarrow R^2\)</span> defined by <span class="math inline">\(R(x,y) = \langle x, y\rangle\)</span> and the vector field <span class="math inline">\(S:R^2\rightarrow R^2\)</span> defined by <span class="math inline">\(S(x,y) = \langle -y, x\rangle\)</span>. Let <span class="math inline">\(r = \|R\| = \sqrt{x^2 + y^2}\)</span>. <span class="math inline">\(R\)</span> is a radial field, <span class="math inline">\(S\)</span> a spin field.</p>
<p>What is <span class="math inline">\(\nabla{r}\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="46">
<div class="cell-output cell-output-display" data-execution_count="45">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="10473163402909219208" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_10473163402909219208">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_10473163402909219208_1">
<input class="form-check-input" type="radio" name="radio_10473163402909219208" id="radio_10473163402909219208_1" value="1">
<span class="label-body px-1">
\(S/r\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_10473163402909219208_2">
<input class="form-check-input" type="radio" name="radio_10473163402909219208" id="radio_10473163402909219208_2" value="2">
<span class="label-body px-1">
\(R/r\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_10473163402909219208_3">
<input class="form-check-input" type="radio" name="radio_10473163402909219208" id="radio_10473163402909219208_3" value="3">
<span class="label-body px-1">
\(R\)
</span>
</label>
</div>
</div>
</div>
<div id="10473163402909219208_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_10473163402909219208"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('10473163402909219208_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_10473163402909219208")
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_10473163402909219208")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Let <span class="math inline">\(\phi = r^k\)</span>. What is <span class="math inline">\(\nabla{\phi}\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="47">
<div class="cell-output cell-output-display" data-execution_count="46">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12745285107291524259" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_12745285107291524259">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_12745285107291524259_1">
<input class="form-check-input" type="radio" name="radio_12745285107291524259" id="radio_12745285107291524259_1" value="1">
<span class="label-body px-1">
\(k r^{k-2} S\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12745285107291524259_2">
<input class="form-check-input" type="radio" name="radio_12745285107291524259" id="radio_12745285107291524259_2" value="2">
<span class="label-body px-1">
\(k r^{k-2} R\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12745285107291524259_3">
<input class="form-check-input" type="radio" name="radio_12745285107291524259" id="radio_12745285107291524259_3" value="3">
<span class="label-body px-1">
\(kr^k R\)
</span>
</label>
</div>
</div>
</div>
<div id="12745285107291524259_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_12745285107291524259"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('12745285107291524259_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_12745285107291524259")
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_12745285107291524259")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Based on your last answer, are all radial fields <span class="math inline">\(R/r^n\)</span>, <span class="math inline">\(n\geq 0\)</span> gradients of scalar functions?</p>
<div class="cell" data-hold="true" data-execution_count="48">
<div class="cell-output cell-output-display" data-execution_count="47">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15009571912454716101" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_15009571912454716101">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_15009571912454716101_1">
<input class="form-check-input" type="radio" name="radio_15009571912454716101" id="radio_15009571912454716101_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_15009571912454716101_2">
<input class="form-check-input" type="radio" name="radio_15009571912454716101" id="radio_15009571912454716101_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="15009571912454716101_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_15009571912454716101"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('15009571912454716101_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_15009571912454716101")
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_15009571912454716101")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Let <span class="math inline">\(\phi = \tan^{-1}(y/x)\)</span>. What is <span class="math inline">\(\nabla{\phi}\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="49">
<div class="cell-output cell-output-display" data-execution_count="48">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="2311634974099888162" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_2311634974099888162">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_2311634974099888162_1">
<input class="form-check-input" type="radio" name="radio_2311634974099888162" id="radio_2311634974099888162_1" value="1">
<span class="label-body px-1">
\(S/r^2\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2311634974099888162_2">
<input class="form-check-input" type="radio" name="radio_2311634974099888162" id="radio_2311634974099888162_2" value="2">
<span class="label-body px-1">
\(S\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2311634974099888162_3">
<input class="form-check-input" type="radio" name="radio_2311634974099888162" id="radio_2311634974099888162_3" value="3">
<span class="label-body px-1">
\(S/r\)
</span>
</label>
</div>
</div>
</div>
<div id="2311634974099888162_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_2311634974099888162"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('2311634974099888162_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_2311634974099888162")
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_2311634974099888162")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Express <span class="math inline">\(S/r^n = \langle F_x, F_y\rangle\)</span>. For which <span class="math inline">\(n\)</span> is <span class="math inline">\(\partial{F_y}/\partial{x} - \partial{F_x}/\partial{y} = 0\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="50">
<div class="cell-output cell-output-display" data-execution_count="49">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="402570775875494483" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_402570775875494483">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_402570775875494483_1">
<input class="form-check-input" type="radio" name="radio_402570775875494483" id="radio_402570775875494483_1" value="1">
<span class="label-body px-1">
All \(n \geq 0\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_402570775875494483_2">
<input class="form-check-input" type="radio" name="radio_402570775875494483" id="radio_402570775875494483_2" value="2">
<span class="label-body px-1">
As the left-hand side becomes \((-n+2)r^{-n}\), only \(n=2\).
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_402570775875494483_3">
<input class="form-check-input" type="radio" name="radio_402570775875494483" id="radio_402570775875494483_3" value="3">
<span class="label-body px-1">
No values of \(n\)
</span>
</label>
</div>
</div>
</div>
<div id="402570775875494483_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_402570775875494483"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('402570775875494483_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_402570775875494483")
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_402570775875494483")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>(The latter is of interest, as only when the expression is <span class="math inline">\(0\)</span> will the vector field be the gradient of a scalar function.)</p>
</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/scalar_functions_applications.html" class="pagination-link">
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">56</span>&nbsp; <span class="chapter-title">Applications with scalar functions</span></span>
</a>
</div>
<div class="nav-page nav-page-next">
<a href="../differentiable_vector_calculus/plots_plotting.html" class="pagination-link">
<span class="nav-page-text"><span class="chapter-number">58</span>&nbsp; <span class="chapter-title">2D and 3D plots in Julia with Plots</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>