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

1915 lines
116 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 - 9&nbsp; Function manipulations</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="../precalc/inversefunctions.html" rel="next">
<link href="../precalc/plotting.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">9</span>&nbsp; <span class="chapter-title">Function manipulations</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" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="true">Precalculus Concepts</a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="true">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 show">
<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 active"><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 collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-6" aria-expanded="false">Differential vector calculus</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-6" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-6" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/polar_coordinates.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">52</span>&nbsp; <span class="chapter-title">Polar Coordinates and Curves</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/vectors.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">53</span>&nbsp; <span class="chapter-title">Vectors and matrices</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/vector_valued_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">54</span>&nbsp; <span class="chapter-title">Vector-valued functions, <span class="math inline">\(f:R \rightarrow R^n\)</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/scalar_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">55</span>&nbsp; <span class="chapter-title">Scalar functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/scalar_functions_applications.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">56</span>&nbsp; <span class="chapter-title">Applications with scalar functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/vector_fields.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">57</span>&nbsp; <span class="chapter-title">Functions <span class="math inline">\(R^n \rightarrow R^m\)</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/plots_plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">58</span>&nbsp; <span class="chapter-title">2D and 3D plots in Julia with Plots</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-7" aria-expanded="false">Integral vector calculus</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-7" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-7" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/double_triple_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">59</span>&nbsp; <span class="chapter-title">Multi-dimensional integrals</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/line_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">60</span>&nbsp; <span class="chapter-title">Line and Surface Integrals</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/div_grad_curl.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">61</span>&nbsp; <span class="chapter-title">The Gradient, Divergence, and Curl</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/stokes_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">62</span>&nbsp; <span class="chapter-title">Greens Theorem, Stokes Theorem, and the Divergence Theorem</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/review.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">63</span>&nbsp; <span class="chapter-title">Quick Review of Vector Calculus</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-8" aria-expanded="false">Alternatives</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-8" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-8" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../alternatives/plotly_plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">64</span>&nbsp; <span class="chapter-title">JavaScript based plotting libraries</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../alternatives/makie_plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">65</span>&nbsp; <span class="chapter-title">Calculus plots with Makie</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-9" aria-expanded="false">Appendices</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-9" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-9" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/getting_started_with_julia.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">66</span>&nbsp; <span class="chapter-title">Getting started with Julia</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/julia_interfaces.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">67</span>&nbsp; <span class="chapter-title">Julia interfaces</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/calculus_with_julia.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">68</span>&nbsp; <span class="chapter-title">The <code>CalculusWithJulia</code> package</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/unicode.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">69</span>&nbsp; <span class="chapter-title">Usages of Unicode symbols</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/quick_notes.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">70</span>&nbsp; <span class="chapter-title">Quick introduction to Calculus with Julia</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../references.html" class="sidebar-item-text sidebar-link">References</a>
</div>
</li>
</ul>
</div>
</nav>
<!-- margin-sidebar -->
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
<nav id="TOC" role="doc-toc">
<h2 id="toc-title">Table of contents</h2>
<ul>
<li><a href="#the-algebra-of-functions" id="toc-the-algebra-of-functions" class="nav-link active" data-scroll-target="#the-algebra-of-functions"> <span class="header-section-number">9.1</span> The algebra of functions</a>
<ul class="collapse">
<li><a href="#composition-of-functions" id="toc-composition-of-functions" class="nav-link" data-scroll-target="#composition-of-functions"> <span class="header-section-number">9.1.1</span> Composition of functions</a></li>
<li><a href="#shifting-and-scaling-graphs" id="toc-shifting-and-scaling-graphs" class="nav-link" data-scroll-target="#shifting-and-scaling-graphs"> <span class="header-section-number">9.1.2</span> Shifting and scaling graphs</a></li>
<li><a href="#operators" id="toc-operators" class="nav-link" data-scroll-target="#operators"> <span class="header-section-number">9.1.3</span> Operators</a></li>
</ul></li>
<li><a href="#questions" id="toc-questions" class="nav-link" data-scroll-target="#questions"> <span class="header-section-number">9.2</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/precalc/transformations.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">9</span>&nbsp; <span class="chapter-title">Function manipulations</span></h1>
</div>
<div class="quarto-title-meta">
</div>
</header>
<p>In this section we will use 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></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<hr>
<p>Thinking of functions as objects themselves that can be manipulated - rather than just blackboxes for evaluation - is a major abstraction of calculus. The main operations to come: the limit <em>of a function</em>, the derivative <em>of a function</em>, and the integral <em>of a function</em> all operate on functions. Hence the idea of an <a href="http://tinyurl.com/n5gp6mf">operator</a>. Here we discuss manipulations of functions from pre-calculus that have proven to be useful abstractions.</p>
<section id="the-algebra-of-functions" class="level2" data-number="9.1">
<h2 data-number="9.1" class="anchored" data-anchor-id="the-algebra-of-functions"><span class="header-section-number">9.1</span> The algebra of functions</h2>
<p>We can talk about the algebra of functions. For example, the sum of functions <span class="math inline">\(f\)</span> and <span class="math inline">\(g\)</span> would be a function whose value at <span class="math inline">\(x\)</span> was just <span class="math inline">\(f(x) + g(x)\)</span>. More formally, we would have:</p>
<p><span class="math display">\[
(f + g)(x) = f(x) + g(x),
\]</span></p>
<p>We have given meaning to a new function <span class="math inline">\(f+g\)</span> by defining what is does to <span class="math inline">\(x\)</span> with the rule on the right hand side. Similarly, we can define operations for subtraction, multiplication, addition, and powers.</p>
<p>These mathematical concepts arent defined for functions in base <code>Julia</code>, though they could be if desired, by a commands such as:</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="im">import</span> <span class="bu">Base</span>: +</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a>f<span class="op">::</span><span class="dt">Function </span><span class="op">+</span> g<span class="op">::</span><span class="dt">Function </span><span class="op">=</span> x <span class="op">-&gt;</span> <span class="fu">f</span>(x) <span class="op">+</span> <span class="fu">g</span>(x)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="5">
<pre><code>+ (generic function with 314 methods)</code></pre>
</div>
</div>
<p>This adds a method to the generic <code>+</code> function for functions. The type annotations <code>::Function</code> ensure this applies only to functions. To see that it would work, we could do odd-looking things like:</p>
<div class="cell" data-execution_count="5">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>ss <span class="op">=</span> sin <span class="op">+</span> sqrt</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="fu">ss</span>(<span class="fl">4</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="6">
<pre><code>1.2431975046920718</code></pre>
</div>
</div>
<p>Doing this works, as Julia treats functions as first class objects, lending itself to <a href="https://en.wikipedia.org/wiki/Higher-order_programming">higher</a> order programming. However, this definition in general is kind of limiting, as functions in mathematics and Julia can be much more varied than just the univariate functions we have defined addition for. We wont pursue this further.</p>
<section id="composition-of-functions" class="level3" data-number="9.1.1">
<h3 data-number="9.1.1" class="anchored" data-anchor-id="composition-of-functions"><span class="header-section-number">9.1.1</span> Composition of functions</h3>
<p>As seen, just like with numbers, it can make sense mathematically to define addition, subtraction, multiplication and division of functions. Unlike numbers though, we can also define a new operation on functions called <strong>composition</strong> that involves chaining the output of one function to the input of another. Composition is a common practice in life, where the result of some act is fed into another process. For example, making a pie from scratch involves first making a crust, then composing this with a filling. A better abstraction might be how we “surf” the web. The output of one search leads us to another search whose output then is a composition.</p>
<p>Mathematically, a composition of univariate functions <span class="math inline">\(f\)</span> and <span class="math inline">\(g\)</span> is written <span class="math inline">\(f \circ g\)</span> and defined by what it does to a value in the domain of <span class="math inline">\(g\)</span> by:</p>
<p><span class="math display">\[
(f \circ g)(x) = f(g(x)).
\]</span></p>
<p>The output of <span class="math inline">\(g\)</span> becomes the input of <span class="math inline">\(f\)</span>.</p>
<p>Composition depends on the order of things. There is no guarantee that <span class="math inline">\(f \circ g\)</span> should be the same as <span class="math inline">\(g \circ f\)</span>. (Putting on socks then shoes is quite different from putting on shoes then socks.) Mathematically, we can see this quite clearly with the functions <span class="math inline">\(f(x) = x^2\)</span> and <span class="math inline">\(g(x) = \sin(x)\)</span>. Algebraically we have:</p>
<p><span class="math display">\[
(f \circ g)(x) = \sin(x)^2, \quad (g \circ f)(x) = \sin(x^2).
\]</span></p>
<p>Though they may be <em>typographically</em> similar dont be fooled, the following graph shows that the two functions arent even close except for <span class="math inline">\(x\)</span> near <span class="math inline">\(0\)</span> (for example, one composition is always non-negative, whereas the other is not):</p>
<div class="cell" data-hold="true" data-execution_count="6">
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x) <span class="op">=</span> x<span class="op">^</span><span class="fl">2</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="fu">g</span>(x) <span class="op">=</span> <span class="fu">sin</span>(x)</span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a>fg <span class="op">=</span> f <span class="op"></span> g <span class="co"># typed as f \circ[tab] g</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a>gf <span class="op">=</span> g <span class="op"></span> f <span class="co"># typed as g \circ[tab] f</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(fg, <span class="op">-</span><span class="fl">2</span>, <span class="fl">2</span>, label<span class="op">=</span><span class="st">"f∘g"</span>)</span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(gf, label<span class="op">=</span><span class="st">"g∘f"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="7">
<p><img src="transformations_files/figure-html/cell-7-output-1.svg" class="img-fluid"></p>
</div>
</div>
<div class="callout-note callout callout-style-default callout-captioned">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-caption-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>Unlike how the basic arithmetic operations are treated, <code>Julia</code> defines the infix Unicode operator <code>\\circ[tab]</code> to represent composition of functions, mirroring mathematical notation. This infix operations takes in two functions and returns an anonymous function. It can be useful and will mirror standard mathematical usage up to issues with precedence rules.</p>
</div>
</div>
<p>Starting with two functions and composing them requires nothing more than a solid grasp of knowing the rules of function evaluation. If <span class="math inline">\(f(x)\)</span> is defined by some rule involving <span class="math inline">\(x\)</span>, then <span class="math inline">\(f(g(x))\)</span> just replaces each <span class="math inline">\(x\)</span> in the rule with a <span class="math inline">\(g(x)\)</span>.</p>
<p>So if <span class="math inline">\(f(x) = x^2 + 2x - 1\)</span> and <span class="math inline">\(g(x) = e^x - x\)</span> then <span class="math inline">\(f \circ g\)</span> would be (before any simplification)</p>
<p><span class="math display">\[
(f \circ g)(x) = (e^x - x)^2 + 2(e^x - x) - 1.
\]</span></p>
<p>If can be helpful to think of the argument to <span class="math inline">\(f\)</span> as a “box” that gets filled in by <span class="math inline">\(g\)</span>:</p>
<p><span class="math display">\[
\begin{align*}
g(x) &amp;=e^x - x\\
f(\square) &amp;= (\square)^2 + 2(\square) - 1\\
f(g(x)) &amp;= (g(x))^2 + 2(g(x)) - 1 = (e^x - x)^2 + 2(e^x - x) - 1.
\end{align*}
\]</span></p>
<p>Here we look at a few compositions:</p>
<ul>
<li>The function <span class="math inline">\(h(x) = \sqrt{1 - x^2}\)</span> can be seen as <span class="math inline">\(f\circ g\)</span> with <span class="math inline">\(f(x) = \sqrt{x}\)</span> and <span class="math inline">\(g(x) = 1-x^2\)</span>.</li>
<li>The function <span class="math inline">\(h(x) = \sin(x/3 + x^2)\)</span> can be viewed as <span class="math inline">\(f\circ g\)</span> with <span class="math inline">\(f(x) = \sin(x)\)</span> and <span class="math inline">\(g(x) = x/3 + x^2\)</span>.</li>
<li>The function <span class="math inline">\(h(x) = e^{-1/2 \cdot x^2}\)</span> can be viewed as <span class="math inline">\(f\circ g\)</span> with <span class="math inline">\(f(x) = e^{-x}\)</span> and <span class="math inline">\(g(x) = (1/2) \cdot x^2\)</span>.</li>
</ul>
<p>Decomposing a function into a composition of functions is not unique, other compositions could have been given above. For example, the last function is also <span class="math inline">\(f(x) = e^{-x/2}\)</span> composed with <span class="math inline">\(g(x) = x^2\)</span>.</p>
<div class="callout-note callout callout-style-default callout-captioned">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-caption-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>The real value of composition is to break down more complicated things into a sequence of easier steps. This is good mathematics, but also good practice more generally. For example, when we approach a problem with the computer, we generally use a smallish set of functions and piece them together (that is, compose them) to find a solution.</p>
</div>
</div>
</section>
<section id="shifting-and-scaling-graphs" class="level3" data-number="9.1.2">
<h3 data-number="9.1.2" class="anchored" data-anchor-id="shifting-and-scaling-graphs"><span class="header-section-number">9.1.2</span> Shifting and scaling graphs</h3>
<p>It is very useful to mentally categorize functions within families. The difference between <span class="math inline">\(f(x) = \cos(x)\)</span> and <span class="math inline">\(g(x) = 12\cos(2(x - \pi/4))\)</span> is not that much - both are cosine functions, one is just a simple enough transformation of the other. As such, we expect bounded, oscillatory behaviour with the details of how large and how fast the oscillations are to depend on the specifics of the function. Similarly, both these functions <span class="math inline">\(f(x) = 2^x\)</span> and <span class="math inline">\(g(x)=e^x\)</span> behave like exponential growth, the difference being only in the rate of growth. There are families of functions that are qualitatively similar, but quantitatively different, linked together by a few basic transformations.</p>
<p>There is a set of operations of functions, which does not really change the type of function. Rather, it basically moves and stretches how the functions are graphed. We discuss these four main transformations of <span class="math inline">\(f\)</span>:</p>
<div class="cell" data-execution_count="7">
<div class="cell-output cell-output-display" data-execution_count="8">
<div class="table-responsive">
<table class="table table-hover">
<tbody><tr><th>Transformation</th><th>Description</th></tr>
<tr><td><div class="markdown"><p><em>vertical shifts</em></p>
</div></td><td><div class="markdown"><p>The function \(h(x) = k + f(x)\) will have the same graph as \(f\) shifted up by \(k\) units.</p>
</div></td></tr>
<tr><td><div class="markdown"><p><em>horizontal shifts</em></p>
</div></td><td><div class="markdown"><p>The function \(h(x) = f(x - k)\) will have the same graph as \(f\) shifted right by \(k\) units.</p>
</div></td></tr>
<tr><td><div class="markdown"><p><em>stretching</em></p>
</div></td><td><div class="markdown"><p>The function \(h(x) = kf(x)\) will have the same graph as \(f\) stretched by a factor of \(k\) in the \(y\) direction.</p>
</div></td></tr>
<tr><td><div class="markdown"><p><em>scaling</em></p>
</div></td><td><div class="markdown"><p>The function \(h(x) = f(kx)\) will have the same graph as \(f\) compressed horizontally by a factor of \(1\) over \(k\).</p>
</div></td></tr>
</tbody></table>
</div>
</div>
</div>
<p>The functions <span class="math inline">\(h\)</span> are derived from <span class="math inline">\(f\)</span> in a predictable way. To implement these transformations within <code>Julia</code>, we define operators (functions which transform one function into another). As these return functions, the function bodies are anonymous functions. The basic definitions are similar, save for the <code>x -&gt; ...</code> part that signals the creation of an anonymous function to return:</p>
<div class="cell" data-execution_count="8">
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="fu">up</span>(f, k) <span class="op">=</span> x <span class="op">-&gt;</span> <span class="fu">f</span>(x) <span class="op">+</span> k</span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a><span class="fu">over</span>(f, k) <span class="op">=</span> x <span class="op">-&gt;</span> <span class="fu">f</span>(x <span class="op">-</span> k)</span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a><span class="fu">stretch</span>(f, k) <span class="op">=</span> x <span class="op">-&gt;</span> k <span class="op">*</span> <span class="fu">f</span>(x)</span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a><span class="fu">scale</span>(f, k) <span class="op">=</span> x <span class="op">-&gt;</span> <span class="fu">f</span>(k <span class="op">*</span> x)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="9">
<pre><code>scale (generic function with 1 method)</code></pre>
</div>
</div>
<p>To illustrate, lets define a hat-shaped function as follows:</p>
<div class="cell" data-execution_count="9">
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="fu">𝒇</span>(x) <span class="op">=</span> <span class="fu">max</span>(<span class="fl">0</span>, <span class="fl">1</span> <span class="op">-</span> <span class="fu">abs</span>(x))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="10">
<pre><code>𝒇 (generic function with 1 method)</code></pre>
</div>
</div>
<p>A plot over the interval <span class="math inline">\([-2,2]\)</span> is shown here:</p>
<div class="cell" data-execution_count="10">
<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">plot</span>(𝒇, <span class="op">-</span><span class="fl">2</span>,<span class="fl">2</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="11">
<p><img src="transformations_files/figure-html/cell-11-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The same graph of <span class="math inline">\(f\)</span> and its image shifted up by <span class="math inline">\(2\)</span> units would be given by:</p>
<div class="cell" data-execution_count="11">
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(𝒇, <span class="op">-</span><span class="fl">2</span>, <span class="fl">2</span>, label<span class="op">=</span><span class="st">"f"</span>)</span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(<span class="fu">up</span>(𝒇, <span class="fl">2</span>), label<span class="op">=</span><span class="st">"up"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="12">
<p><img src="transformations_files/figure-html/cell-12-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>A graph of <span class="math inline">\(f\)</span> and its shift over by <span class="math inline">\(2\)</span> units would be given by:</p>
<div class="cell" data-execution_count="12">
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(𝒇, <span class="op">-</span><span class="fl">2</span>, <span class="fl">4</span>, label<span class="op">=</span><span class="st">"f"</span>)</span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(<span class="fu">over</span>(𝒇, <span class="fl">2</span>), label<span class="op">=</span><span class="st">"over"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="13">
<p><img src="transformations_files/figure-html/cell-13-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>A graph of <span class="math inline">\(f\)</span> and it being stretched by <span class="math inline">\(2\)</span> units would be given by:</p>
<div class="cell" data-execution_count="13">
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(𝒇, <span class="op">-</span><span class="fl">2</span>, <span class="fl">2</span>, label<span class="op">=</span><span class="st">"f"</span>)</span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(<span class="fu">stretch</span>(𝒇, <span class="fl">2</span>), label<span class="op">=</span><span class="st">"stretch"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="14">
<p><img src="transformations_files/figure-html/cell-14-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Finally, a graph of <span class="math inline">\(f\)</span> and it being scaled by <span class="math inline">\(2\)</span> would be given by:</p>
<div class="cell" 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><span class="fu">plot</span>(𝒇, <span class="op">-</span><span class="fl">2</span>, <span class="fl">2</span>, label<span class="op">=</span><span class="st">"f"</span>)</span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(<span class="fu">scale</span>(𝒇, <span class="fl">2</span>), label<span class="op">=</span><span class="st">"scale"</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="transformations_files/figure-html/cell-15-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Scaling by <span class="math inline">\(2\)</span> shrinks the non-zero domain, scaling by <span class="math inline">\(1/2\)</span> would stretch it. If this is not intuitive, the defintion <code>x-&gt; f(x/c)</code> could have been used, which would have opposite behaviour for scaling.</p>
<hr>
<p>More exciting is what happens if we combine these operations.</p>
<p>A shift right by <span class="math inline">\(2\)</span> and up by <span class="math inline">\(1\)</span> is achieved through</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="fu">plot</span>(𝒇, <span class="op">-</span><span class="fl">2</span>, <span class="fl">4</span>, label<span class="op">=</span><span class="st">"f"</span>)</span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(<span class="fu">up</span>(<span class="fu">over</span>(𝒇,<span class="fl">2</span>), <span class="fl">1</span>), label<span class="op">=</span><span class="st">"over and up"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="16">
<p><img src="transformations_files/figure-html/cell-16-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Shifting and scaling can be confusing. Here we graph <code>scale(over(𝒇,2),1/3)</code>:</p>
<div class="cell" data-execution_count="16">
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(𝒇, <span class="op">-</span><span class="fl">1</span>,<span class="fl">9</span>, label<span class="op">=</span><span class="st">"f"</span>)</span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(<span class="fu">scale</span>(<span class="fu">over</span>(𝒇,<span class="fl">2</span>), <span class="fl">1</span><span class="op">/</span><span class="fl">3</span>), label<span class="op">=</span><span class="st">"over and scale"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="17">
<p><img src="transformations_files/figure-html/cell-17-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>This graph is over by <span class="math inline">\(6\)</span> with a width of <span class="math inline">\(3\)</span> on each side of the center. Mathematically, we have <span class="math inline">\(h(x) = f((1/3)\cdot x - 2)\)</span></p>
<p>Compare this to the same operations in opposite order:</p>
<div class="cell" data-execution_count="17">
<div class="sourceCode cell-code" id="cb18"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(𝒇, <span class="op">-</span><span class="fl">1</span>, <span class="fl">5</span>, label<span class="op">=</span><span class="st">"f"</span>)</span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(<span class="fu">over</span>(<span class="fu">scale</span>(𝒇, <span class="fl">1</span><span class="op">/</span><span class="fl">3</span>), <span class="fl">2</span>), label<span class="op">=</span><span class="st">"scale and over"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="18">
<p><img src="transformations_files/figure-html/cell-18-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>This graph first scales the symmetric graph, stretching from <span class="math inline">\(-3\)</span> to <span class="math inline">\(3\)</span>, then shifts over right by <span class="math inline">\(2\)</span>. The resulting function is <span class="math inline">\(f((1/3)\cdot (x-2))\)</span>.</p>
<p>As a last example, following up on the last example, a common transformation mathematically is</p>
<p><span class="math display">\[
h(x) = \frac{1}{a}f(\frac{x - b}{a}).
\]</span></p>
<p>We can view this as a composition of “scale” by <span class="math inline">\(1/a\)</span>, then “over” by <span class="math inline">\(b\)</span>, and finally “stretch” by <span class="math inline">\(1/a\)</span>:</p>
<div class="cell" data-hold="true" data-execution_count="18">
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a>a <span class="op">=</span> <span class="fl">2</span>; b <span class="op">=</span> <span class="fl">5</span></span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a><span class="fu">𝒉</span>(x) <span class="op">=</span> <span class="fu">stretch</span>(<span class="fu">over</span>(<span class="fu">scale</span>(𝒇, <span class="fl">1</span><span class="op">/</span>a), b), <span class="fl">1</span><span class="op">/</span>a)(x)</span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(𝒇, <span class="op">-</span><span class="fl">1</span>, <span class="fl">8</span>, label<span class="op">=</span><span class="st">"f"</span>)</span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(𝒉, label<span class="op">=</span><span class="st">"h"</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">
<p><img src="transformations_files/figure-html/cell-19-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>(This transformation keeps the same amount of area in the triangles, can you tell from the graph?)</p>
<section id="example" class="level5">
<h5 class="anchored" data-anchor-id="example">Example</h5>
<p>A model for the length of a day in New York City must take into account periodic seasonal effects. A simple model might be a sine curve. However, there would need to be many modifications: Obvious ones would be that the period would need to be about <span class="math inline">\(365\)</span> days, the oscillation around <span class="math inline">\(12\)</span> and the amplitude of the oscillations no more than <span class="math inline">\(12\)</span>.</p>
<p>We can be more precise. According to <a href="http://dateandtime.info/citysunrisesunset.php?id=5128581">dateandtime.info</a> in <span class="math inline">\(2015\)</span> the longest day will be June <span class="math inline">\(21\)</span>st when there will be <span class="math inline">\(15\)</span>h <span class="math inline">\(5\)</span>m <span class="math inline">\(46\)</span>s of sunlight, the shortest day will be December <span class="math inline">\(21\)</span>st when there will be <span class="math inline">\(9\)</span>h <span class="math inline">\(15\)</span>m <span class="math inline">\(19\)</span>s of sunlight. On January <span class="math inline">\(1\)</span>, there will be <span class="math inline">\(9\)</span>h <span class="math inline">\(19\)</span>m <span class="math inline">\(44\)</span>s of sunlight.</p>
<p>A model for a transformed sine curve is</p>
<p><span class="math display">\[
a + b\sin(d(x - c))
\]</span></p>
<p>Where <span class="math inline">\(b\)</span> is related to the amplitude, <span class="math inline">\(c\)</span> the shift and the period is <span class="math inline">\(T=2\pi/d\)</span>. We can find some of these easily from the above:</p>
<div class="cell" data-execution_count="19">
<div class="sourceCode cell-code" id="cb20"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a>a <span class="op">=</span> <span class="fl">12</span></span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a>b <span class="op">=</span> ((<span class="fl">15</span> <span class="op">+</span> <span class="fl">5</span><span class="op">/</span><span class="fl">60</span> <span class="op">+</span> <span class="fl">46</span><span class="op">/</span><span class="fl">60</span><span class="op">/</span><span class="fl">60</span>) <span class="op">-</span> (<span class="fl">9</span> <span class="op">+</span> <span class="fl">19</span><span class="op">/</span><span class="fl">60</span> <span class="op">+</span> <span class="fl">44</span><span class="op">/</span><span class="fl">60</span><span class="op">/</span><span class="fl">60</span>)) <span class="op">/</span> <span class="fl">2</span></span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a>d <span class="op">=</span> <span class="fl">2</span>pi<span class="op">/</span><span class="fl">365</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="20">
<pre><code>0.01721420632103996</code></pre>
</div>
</div>
<p>If we let January <span class="math inline">\(1\)</span> be <span class="math inline">\(x=0\)</span> then the first day of spring, March <span class="math inline">\(21\)</span>, is day <span class="math inline">\(80\)</span> (<code>Date(2017, 3, 21) - Date(2017, 1, 1) + 1</code>). This day aligns with the shift of the sine curve. This shift is <span class="math inline">\(80\)</span>:</p>
<div class="cell" data-execution_count="20">
<div class="sourceCode cell-code" id="cb22"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a>c <span class="op">=</span> <span class="fl">80</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="21">
<pre><code>80</code></pre>
</div>
</div>
<p>Putting this together, we have our graph is “scaled” by <span class="math inline">\(d\)</span>, “over” by <span class="math inline">\(c\)</span>, “stretched” by <span class="math inline">\(b\)</span> and “up” by <span class="math inline">\(a\)</span>. Here we plot it over slightly more than one year so that we can see that the shortest day of light is in late December (<span class="math inline">\(x \approx -10\)</span> or <span class="math inline">\(x \approx 355\)</span>).</p>
<div class="cell" data-execution_count="21">
<div class="sourceCode cell-code" id="cb24"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a><span class="fu">newyork</span>(t) <span class="op">=</span> <span class="fu">up</span>(<span class="fu">stretch</span>(<span class="fu">over</span>(<span class="fu">scale</span>(sin, d), c), b), a)(t)</span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(newyork, <span class="op">-</span><span class="fl">20</span>, <span class="fl">385</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="22">
<p><img src="transformations_files/figure-html/cell-22-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>To test, if we match up with the model powering <a href="http://dateandtime.info/citysunrisesunset.php?id=5128581">dateandtime.info</a> we note that it predicts “<span class="math inline">\(15\)</span>h <span class="math inline">\(0\)</span>m <span class="math inline">\(4\)</span>s” on July <span class="math inline">\(4\)</span>, <span class="math inline">\(2015\)</span>. This is day <span class="math inline">\(185\)</span> (<code>Date(2015, 7, 4) - Date(2015, 1, 1) + 1</code>). Our model prediction has a difference of</p>
<div class="cell" data-execution_count="22">
<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>datetime <span class="op">=</span> <span class="fl">15</span> <span class="op">+</span> <span class="fl">0</span><span class="op">/</span><span class="fl">60</span> <span class="op">+</span> <span class="fl">4</span><span class="op">/</span><span class="fl">60</span><span class="op">/</span><span class="fl">60</span></span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a>delta <span class="op">=</span> (<span class="fu">newyork</span>(<span class="fl">185</span>) <span class="op">-</span> datetime) <span class="op">*</span> <span class="fl">60</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="23">
<pre><code>-11.874016679895263</code></pre>
</div>
</div>
<p>This is off by a fair amount - almost <span class="math inline">\(12\)</span> minutes. Clearly a trigonometric model, based on the assumption of circular motion of the earth around the sun, is not accurate enough for precise work, but it does help one understand how summer days are longer than winter days and how the length of a day changes fastest at the spring and fall equinoxes.</p>
</section>
<section id="example-a-growth-model-in-fisheries" class="level5">
<h5 class="anchored" data-anchor-id="example-a-growth-model-in-fisheries">Example: a growth model in fisheries</h5>
<p>The von Bertanlaffy growth <a href="http://www.fao.org/docrep/W5449e/w5449e05.htm">equation</a> is <span class="math inline">\(L(t) =L_\infty \cdot (1 - e^{k\cdot(t-t_0)})\)</span>. This family of functions can be viewed as a transformation of the exponential function <span class="math inline">\(f(t)=e^t\)</span>. Part is a scaling and shifting (the <span class="math inline">\(e^{k \cdot (t - t_0)}\)</span>) along with some shifting and stretching. The various parameters have physical importance which can be measured: <span class="math inline">\(L_\infty\)</span> is a carrying capacity for the species or organism, and <span class="math inline">\(k\)</span> is a rate of growth. These parameters may be estimated from data by finding the “closest” curve to a given data set.</p>
</section>
<section id="example-the-pipeline-operator" class="level5">
<h5 class="anchored" data-anchor-id="example-the-pipeline-operator">Example: the pipeline operator</h5>
<p>In the last example, we described our sequence as scale, over, stretch, and up, but code this in reverse order, as the composition <span class="math inline">\(f \circ g\)</span> is done from right to left. A more convenient notation would be to have syntax that allows the composition of <span class="math inline">\(g\)</span> then <span class="math inline">\(f\)</span> to be written <span class="math inline">\(x \rightarrow g \rightarrow f\)</span>. <code>Julia</code> provides the <a href="http://julia.readthedocs.org/en/latest/stdlib/base/#Base.%7C%3E">pipeline</a> operator for chaining function calls together.</p>
<p>For example, if <span class="math inline">\(g(x) = \sqrt{x}\)</span> and <span class="math inline">\(f(x) =\sin(x)\)</span> we could call <span class="math inline">\(f(g(x))\)</span> through:</p>
<div class="cell" data-hold="true" data-execution_count="23">
<div class="sourceCode cell-code" id="cb27"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a><span class="fu">g</span>(x) <span class="op">=</span> <span class="fu">sqrt</span>(x)</span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x) <span class="op">=</span> <span class="fu">sin</span>(x)</span>
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true" tabindex="-1"></a><span class="cn">pi</span><span class="op">/</span><span class="fl">2</span> <span class="op">|&gt;</span> g <span class="op">|&gt;</span> f</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="24">
<pre><code>0.9500244274657834</code></pre>
</div>
</div>
<p>The output of the preceding expression is passed as the input to the next. This notation is especially convenient when the enclosing function is not the main focus. (Some programming languages have more developed <a href="https://en.wikipedia.org/wiki/Fluent_interface">fluent interfaces</a> for chaining function calls. Julia has more powerful chaining macros provided in packages, such as <code>DataPipes.jl</code> or <code>Chain.jl</code>.)</p>
</section>
</section>
<section id="operators" class="level3" data-number="9.1.3">
<h3 data-number="9.1.3" class="anchored" data-anchor-id="operators"><span class="header-section-number">9.1.3</span> Operators</h3>
<p>The functions <code>up</code>, <code>over</code>, etc. are operators that take a function as an argument and return a function. The use of operators fits in with the template <code>action(f, args...)</code>. The action is what we are doing, such as <code>plot</code>, <code>over</code>, and others to come. The function <code>f</code> here is just an object that we are performing the action on. For example, a plot takes a function and renders a graph using the additional arguments to select the domain to view, etc.</p>
<p>Creating operators that return functions involves the use of anonymous functions, using these operators is relatively straightforward. Two basic patterns are</p>
<ul>
<li>Storing the returned function, then calling it:</li>
</ul>
<div class="sourceCode cell-code" id="cb29"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a><span class="fu">l</span>(x) <span class="op">=</span> <span class="fu">action1</span>(f, args<span class="op">...</span>)(x)</span>
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a><span class="fu">l</span>(<span class="fl">10</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<ul>
<li>Composing two operators:</li>
</ul>
<div class="sourceCode cell-code" id="cb30"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a><span class="fu">action2</span>( <span class="fu">action1</span>(f, args<span class="op">..</span>), other_args<span class="op">...</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>Composition like the above is convenient, but can get confusing if more than one composition is involved.</p>
<section id="example-two-operators" class="level5">
<h5 class="anchored" data-anchor-id="example-two-operators">Example: two operators</h5>
<p>(See <a href="http://arxiv.org/abs/1403.5821">Krill</a> for background on this example.) Consider two operations on functions. The first takes the <em>difference</em> between adjacent points. We call this <code>D</code>:</p>
<div class="cell" data-execution_count="26">
<div class="sourceCode cell-code" id="cb31"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a><span class="fu">D</span>(f<span class="op">::</span><span class="dt">Function</span>) <span class="op">=</span> k <span class="op">-&gt;</span> <span class="fu">f</span>(k) <span class="op">-</span> <span class="fu">f</span>(k<span class="op">-</span><span class="fl">1</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="25">
<pre><code>D (generic function with 1 method)</code></pre>
</div>
</div>
<p>To see that it works, we take a typical function</p>
<div class="cell" data-execution_count="27">
<div class="sourceCode cell-code" id="cb33"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a><span class="fu">𝐟</span>(k) <span class="op">=</span> <span class="fl">1</span> <span class="op">+</span> k<span class="op">^</span><span class="fl">2</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="26">
<pre><code>𝐟 (generic function with 1 method)</code></pre>
</div>
</div>
<p>and check:</p>
<div class="cell" data-execution_count="28">
<div class="sourceCode cell-code" id="cb35"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a><span class="fu">D</span>(𝐟)(<span class="fl">3</span>), <span class="fu">𝐟</span>(<span class="fl">3</span>) <span class="op">-</span> <span class="fu">𝐟</span>(<span class="fl">3</span><span class="op">-</span><span class="fl">1</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="27">
<pre><code>(5, 5)</code></pre>
</div>
</div>
<p>That the two are the same value is no coincidence. (Again, pause for a second to make sure you understand why <code>D(f)(3)</code> makes sense. If this is unclear, you could name the function <code>D(f)</code> and then call this with a value of <code>3</code>.)</p>
<p>Now we want a function to cumulatively <em>sum</em> the values <span class="math inline">\(S(f)(k) = f(1) + f(2) + \cdots + f(k-1) + f(k)\)</span>, as a function of <span class="math inline">\(k\)</span>. Adding up <span class="math inline">\(k\)</span> terms is easy to do with a generator and the function <code>sum</code>:</p>
<div class="cell" data-execution_count="29">
<div class="sourceCode cell-code" id="cb37"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb37-1"><a href="#cb37-1" aria-hidden="true" tabindex="-1"></a><span class="fu">S</span>(f) <span class="op">=</span> k <span class="op">-&gt;</span> <span class="fu">sum</span>(<span class="fu">f</span>(i) <span class="cf">for</span> i <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span>k)</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>S (generic function with 1 method)</code></pre>
</div>
</div>
<p>To check if this works as expected, compare these two values:</p>
<div class="cell" data-execution_count="30">
<div class="sourceCode cell-code" id="cb39"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb39-1"><a href="#cb39-1" aria-hidden="true" tabindex="-1"></a><span class="fu">S</span>(𝐟)(<span class="fl">4</span>), <span class="fu">𝐟</span>(<span class="fl">1</span>) <span class="op">+</span> <span class="fu">𝐟</span>(<span class="fl">2</span>) <span class="op">+</span> <span class="fu">𝐟</span>(<span class="fl">3</span>) <span class="op">+</span> <span class="fu">𝐟</span>(<span class="fl">4</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="29">
<pre><code>(34, 34)</code></pre>
</div>
</div>
<p>So one function adds, the other subtracts. Addition and subtraction are somehow inverse to each other so should “cancel” out. This holds for these two operations as well, in the following sense: subtracting after adding leaves the function alone:</p>
<div class="cell" data-execution_count="31">
<div class="sourceCode cell-code" id="cb41"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb41-1"><a href="#cb41-1" aria-hidden="true" tabindex="-1"></a>k <span class="op">=</span> <span class="fl">10</span> <span class="co"># some arbitrary value k &gt;= 1</span></span>
<span id="cb41-2"><a href="#cb41-2" aria-hidden="true" tabindex="-1"></a><span class="fu">D</span>(<span class="fu">S</span>(𝐟))(k), <span class="fu">𝐟</span>(k)</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>(101, 101)</code></pre>
</div>
</div>
<p>Any positive integer value of <code>k</code> will give the same answer (up to overflow). This says the difference of the accumulation process is just the last value to accumulate.</p>
<p>Adding after subtracting also leaves the function alone, save for a vestige of <span class="math inline">\(f(0)\)</span>. For example, <code>k=15</code>:</p>
<div class="cell" data-execution_count="32">
<div class="sourceCode cell-code" id="cb43"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb43-1"><a href="#cb43-1" aria-hidden="true" tabindex="-1"></a><span class="fu">S</span>(<span class="fu">D</span>(𝐟))(<span class="fl">15</span>), <span class="fu">𝐟</span>(<span class="fl">15</span>) <span class="op">-</span> <span class="fu">𝐟</span>(<span class="fl">0</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="31">
<pre><code>(225, 225)</code></pre>
</div>
</div>
<p>That is the accumulation of differences is just the difference of the end values.</p>
<p>These two operations are discrete versions of the two main operations of calculus - the derivative and the integral. This relationship will be known as the “fundamental theorem of calculus.”</p>
</section>
</section>
</section>
<section id="questions" class="level2" data-number="9.2">
<h2 data-number="9.2" class="anchored" data-anchor-id="questions"><span class="header-section-number">9.2</span> Questions</h2>
<section id="question" class="level6">
<h6 class="anchored" data-anchor-id="question">Question</h6>
<p>If <span class="math inline">\(f(x) = 1/x\)</span> and <span class="math inline">\(g(x) = x-2\)</span>, what is <span class="math inline">\(g(f(x))\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="33">
<div class="cell-output cell-output-display" data-execution_count="32">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="10244402984081903401" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_10244402984081903401">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_10244402984081903401_1">
<input class="form-check-input" type="radio" name="radio_10244402984081903401" id="radio_10244402984081903401_1" value="1">
<span class="label-body px-1">
\(1/(x-2)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_10244402984081903401_2">
<input class="form-check-input" type="radio" name="radio_10244402984081903401" id="radio_10244402984081903401_2" value="2">
<span class="label-body px-1">
\(1/x - 2\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_10244402984081903401_3">
<input class="form-check-input" type="radio" name="radio_10244402984081903401" id="radio_10244402984081903401_3" value="3">
<span class="label-body px-1">
\(-2\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_10244402984081903401_4">
<input class="form-check-input" type="radio" name="radio_10244402984081903401" id="radio_10244402984081903401_4" value="4">
<span class="label-body px-1">
\(x - 2\)
</span>
</label>
</div>
</div>
</div>
<div id="10244402984081903401_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_10244402984081903401"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('10244402984081903401_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_10244402984081903401")
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_10244402984081903401")
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>If <span class="math inline">\(f(x) = e^{-x}\)</span> and <span class="math inline">\(g(x) = x^2\)</span> and <span class="math inline">\(h(x) = x-3\)</span>, what is <span class="math inline">\(f \circ g \circ h\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="34">
<div class="cell-output cell-output-display" data-execution_count="33">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="3530212526163171664" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_3530212526163171664">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_3530212526163171664_1">
<input class="form-check-input" type="radio" name="radio_3530212526163171664" id="radio_3530212526163171664_1" value="1">
<span class="label-body px-1">
\((e^x -3)^2\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_3530212526163171664_2">
<input class="form-check-input" type="radio" name="radio_3530212526163171664" id="radio_3530212526163171664_2" value="2">
<span class="label-body px-1">
\(e^{-(x-3)^2}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_3530212526163171664_3">
<input class="form-check-input" type="radio" name="radio_3530212526163171664" id="radio_3530212526163171664_3" value="3">
<span class="label-body px-1">
\(e^x+x^2+x-3\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_3530212526163171664_4">
<input class="form-check-input" type="radio" name="radio_3530212526163171664" id="radio_3530212526163171664_4" value="4">
<span class="label-body px-1">
\(e^{-x^2 - 3}\)
</span>
</label>
</div>
</div>
</div>
<div id="3530212526163171664_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_3530212526163171664"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('3530212526163171664_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_3530212526163171664")
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_3530212526163171664")
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>If <span class="math inline">\(h(x) = (f \circ g)(x) = \sin^2(x)\)</span> which is a possibility for <span class="math inline">\(f\)</span> and <span class="math inline">\(g\)</span>:</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="7900847219417625502" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_7900847219417625502">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_7900847219417625502_1">
<input class="form-check-input" type="radio" name="radio_7900847219417625502" id="radio_7900847219417625502_1" value="1">
<span class="label-body px-1">
\(f(x)=\sin(x); \quad g(x) = x^2\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7900847219417625502_2">
<input class="form-check-input" type="radio" name="radio_7900847219417625502" id="radio_7900847219417625502_2" value="2">
<span class="label-body px-1">
`\(f(x)=x^2; \quad g(x) = \sin(x)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7900847219417625502_3">
<input class="form-check-input" type="radio" name="radio_7900847219417625502" id="radio_7900847219417625502_3" value="3">
<span class="label-body px-1">
\(f(x)=x^2; \quad g(x) = \sin^2(x)\)
</span>
</label>
</div>
</div>
</div>
<div id="7900847219417625502_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_7900847219417625502"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('7900847219417625502_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_7900847219417625502")
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_7900847219417625502")
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>Which function would have the same graph as the sine curve shifted over by 4 and up by 6?</p>
<div class="cell" data-hold="true" data-execution_count="36">
<div class="cell-output cell-output-display" data-execution_count="35">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="5840031689433597806" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_5840031689433597806">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_5840031689433597806_1">
<input class="form-check-input" type="radio" name="radio_5840031689433597806" id="radio_5840031689433597806_1" value="1">
<span class="label-body px-1">
\(h(x) = 4 + \sin(6x)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5840031689433597806_2">
<input class="form-check-input" type="radio" name="radio_5840031689433597806" id="radio_5840031689433597806_2" value="2">
<span class="label-body px-1">
\(h(x) = 6 + \sin(x + 4)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5840031689433597806_3">
<input class="form-check-input" type="radio" name="radio_5840031689433597806" id="radio_5840031689433597806_3" value="3">
<span class="label-body px-1">
\(h(x) = 6 + \sin(x-4)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5840031689433597806_4">
<input class="form-check-input" type="radio" name="radio_5840031689433597806" id="radio_5840031689433597806_4" value="4">
<span class="label-body px-1">
\(h(x) = 6\sin(x-4)\)
</span>
</label>
</div>
</div>
</div>
<div id="5840031689433597806_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_5840031689433597806"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('5840031689433597806_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_5840031689433597806")
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_5840031689433597806")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-4" class="level6">
<h6 class="anchored" data-anchor-id="question-4">Question</h6>
<p>Let <span class="math inline">\(h(x) = 4x^2\)</span> and <span class="math inline">\(f(x) = x^2\)</span>. Which is <strong>not</strong> true:</p>
<div class="cell" data-hold="true" data-execution_count="37">
<div class="cell-output cell-output-display" data-execution_count="36">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="3814553912229533846" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_3814553912229533846">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_3814553912229533846_1">
<input class="form-check-input" type="radio" name="radio_3814553912229533846" id="radio_3814553912229533846_1" value="1">
<span class="label-body px-1">
The graph of \(h(x)\) is the graph of f(x) shifted up by \(4\) units
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_3814553912229533846_2">
<input class="form-check-input" type="radio" name="radio_3814553912229533846" id="radio_3814553912229533846_2" value="2">
<span class="label-body px-1">
The graph of \(h(x)\) is the graph of \(f(x)\) stretched by a factor of \(4\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_3814553912229533846_3">
<input class="form-check-input" type="radio" name="radio_3814553912229533846" id="radio_3814553912229533846_3" value="3">
<span class="label-body px-1">
The graph of \(h(x)\) is the graph of \(f(x)\) scaled by a factor of \(2\)
</span>
</label>
</div>
</div>
</div>
<div id="3814553912229533846_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_3814553912229533846"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('3814553912229533846_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_3814553912229533846")
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_3814553912229533846")
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>The transformation <span class="math inline">\(h(x) = (1/a) \cdot f((x-b)/a)\)</span> can be viewed in one sequence:</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="14896309504283607660" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_14896309504283607660">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_14896309504283607660_1">
<input class="form-check-input" type="radio" name="radio_14896309504283607660" id="radio_14896309504283607660_1" value="1">
<span class="label-body px-1">
shifting by \(a\), then scaling by \(b\), and then scaling by \(1/a\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14896309504283607660_2">
<input class="form-check-input" type="radio" name="radio_14896309504283607660" id="radio_14896309504283607660_2" value="2">
<span class="label-body px-1">
scaling by \(1/a\), then shifting by \(b\), then stretching by \(1/a\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14896309504283607660_3">
<input class="form-check-input" type="radio" name="radio_14896309504283607660" id="radio_14896309504283607660_3" value="3">
<span class="label-body px-1">
shifting by \(a\), then scaling by \(a\), and then scaling by \(b\)
</span>
</label>
</div>
</div>
</div>
<div id="14896309504283607660_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_14896309504283607660"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('14896309504283607660_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_14896309504283607660")
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_14896309504283607660")
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>This is the graph of a transformed sine curve.</p>
<div class="cell" data-hold="true" data-execution_count="39">
<div class="cell-output cell-output-display" data-execution_count="38">
<p><img src="transformations_files/figure-html/cell-40-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>What is the period of the graph?</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="6237328593075020092" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_6237328593075020092">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="6237328593075020092" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="6237328593075020092_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("6237328593075020092").addEventListener("change", function() {
var correct = (Math.abs(this.value - 2) <= 0);
var msgBox = document.getElementById('6237328593075020092_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_6237328593075020092")
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_6237328593075020092")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>What is the amplitude of the graph?</p>
<div class="cell" data-hold="true" data-execution_count="41">
<div class="cell-output cell-output-display" data-execution_count="40">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="17904918937983810955" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_17904918937983810955">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="17904918937983810955" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="17904918937983810955_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("17904918937983810955").addEventListener("change", function() {
var correct = (Math.abs(this.value - 2) <= 0);
var msgBox = document.getElementById('17904918937983810955_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_17904918937983810955")
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_17904918937983810955")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>What is the form of the function graphed?</p>
<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="6186988253861359898" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_6186988253861359898">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_6186988253861359898_1">
<input class="form-check-input" type="radio" name="radio_6186988253861359898" id="radio_6186988253861359898_1" value="1">
<span class="label-body px-1">
\(\sin(2x)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6186988253861359898_2">
<input class="form-check-input" type="radio" name="radio_6186988253861359898" id="radio_6186988253861359898_2" value="2">
<span class="label-body px-1">
\(\sin(\pi x)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6186988253861359898_3">
<input class="form-check-input" type="radio" name="radio_6186988253861359898" id="radio_6186988253861359898_3" value="3">
<span class="label-body px-1">
\(2 \sin(x)\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6186988253861359898_4">
<input class="form-check-input" type="radio" name="radio_6186988253861359898" id="radio_6186988253861359898_4" value="4">
<span class="label-body px-1">
\(2 \sin(\pi x)\)
</span>
</label>
</div>
</div>
</div>
<div id="6186988253861359898_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_6186988253861359898"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 4;
var msgBox = document.getElementById('6186988253861359898_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_6186988253861359898")
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_6186988253861359898")
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 this expression</p>
<p><span class="math display">\[
\left(f(1) - f(0)\right) + \left(f(2) - f(1)\right) + \cdots + \left(f(n) - f(n-1)\right) =
-f(0) + f(1) - f(1) + f(2) - f(2) + \cdots + f(n-1) - f(n-1) + f(n) =
f(n) - f(0).
\]</span></p>
<p>Referring to the definitions of <code>D</code> and <code>S</code> in the example on operators, which relationship does this support:</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="6897584011008966106" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_6897584011008966106">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_6897584011008966106_1">
<input class="form-check-input" type="radio" name="radio_6897584011008966106" id="radio_6897584011008966106_1" value="1">
<span class="label-body px-1">
<code>D(S(f))(n) = f(n)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6897584011008966106_2">
<input class="form-check-input" type="radio" name="radio_6897584011008966106" id="radio_6897584011008966106_2" value="2">
<span class="label-body px-1">
<code>S(D(f))(n) = f(n) - f(0)</code>
</span>
</label>
</div>
</div>
</div>
<div id="6897584011008966106_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_6897584011008966106"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('6897584011008966106_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_6897584011008966106")
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_6897584011008966106")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-8" class="level6">
<h6 class="anchored" data-anchor-id="question-8">Question</h6>
<p>Consider this expression:</p>
<p><span class="math display">\[
\left(f(1) + f(2) + \cdots + f(n-1) + f(n)\right) - \left(f(1) + f(2) + \cdots + f(n-1)\right) = f(n).
\]</span></p>
<p>Referring to the definitions of <code>D</code> and <code>S</code> in the example on operators, which relationship does this support:</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="358862707920644459" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_358862707920644459">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_358862707920644459_1">
<input class="form-check-input" type="radio" name="radio_358862707920644459" id="radio_358862707920644459_1" value="1">
<span class="label-body px-1">
<code>D(S(f))(n) = f(n)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_358862707920644459_2">
<input class="form-check-input" type="radio" name="radio_358862707920644459" id="radio_358862707920644459_2" value="2">
<span class="label-body px-1">
<code>S(D(f))(n) = f(n) - f(0)</code>
</span>
</label>
</div>
</div>
</div>
<div id="358862707920644459_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_358862707920644459"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('358862707920644459_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_358862707920644459")
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_358862707920644459")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
</section>
</main> <!-- /main -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const clipboard = new window.ClipboardJS('.code-copy-button', {
target: function(trigger) {
return trigger.previousElementSibling;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
setTimeout(function() {
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
});
function tippyHover(el, contentFn) {
const config = {
allowHTML: true,
content: contentFn,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start'
};
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
let href = ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
return note.innerHTML;
});
}
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const cites = ref.parentNode.getAttribute('data-cites').split(' ');
tippyHover(ref, function() {
var popup = window.document.createElement('div');
cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
var filterRegex = new RegExp('/' + window.location.host + '/');
var isInternal = (href) => {
return filterRegex.test(href) || localhostRegex.test(href);
}
// Inspect non-navigation links and adorn them if external
var links = window.document.querySelectorAll('a:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external)');
for (var i=0; i<links.length; i++) {
const link = links[i];
if (!isInternal(link.href)) {
// target, if specified
link.setAttribute("target", "_blank");
}
}
});
</script>
<nav class="page-navigation">
<div class="nav-page nav-page-previous">
<a href="../precalc/plotting.html" class="pagination-link">
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">The Graph of a Function</span></span>
</a>
</div>
<div class="nav-page nav-page-next">
<a href="../precalc/inversefunctions.html" class="pagination-link">
<span class="nav-page-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">The Inverse of a Function</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>