CalculusWithJuliaNotes.jl/quarto/308797b5/precalc/plotting.html

2401 lines
156 KiB
HTML
Raw Normal View History

2022-08-11 19:00:43 +02:00
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.0.32">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>Calculus with Julia - 8&nbsp; The Graph of a Function</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/transformations.html" rel="next">
<link href="../precalc/functions.html" rel="prev">
<script src="../site_libs/quarto-html/quarto.js"></script>
<script src="../site_libs/quarto-html/popper.min.js"></script>
<script src="../site_libs/quarto-html/tippy.umd.min.js"></script>
<script src="../site_libs/quarto-html/anchor.min.js"></script>
<link href="../site_libs/quarto-html/tippy.css" rel="stylesheet">
<link href="../site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="../site_libs/bootstrap/bootstrap.min.js"></script>
<link href="../site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="../site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
<script id="quarto-search-options" type="application/json">{
"location": "navbar",
"copy-button": false,
"collapse-after": 3,
"panel-placement": "end",
"type": "overlay",
"limit": 20,
"language": {
"search-no-results-text": "No results",
"search-matching-documents-text": "matching documents",
"search-copy-link-title": "Copy link to search",
"search-hide-matches-text": "Hide additional matches",
"search-more-match-text": "more match in this document",
"search-more-matches-text": "more matches in this document",
"search-clear-button-title": "Clear",
"search-detached-cancel-button-title": "Cancel",
"search-submit-button-title": "Submit"
}
}</script>
<script async="" src="https://hypothes.is/embed.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" integrity="sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script>
<script type="application/javascript">define('jquery', [],function() {return window.jQuery;})</script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js" type="text/javascript"></script>
</head>
<body class="nav-sidebar floating nav-fixed">
<div id="quarto-search-results"></div>
<header id="quarto-header" class="headroom fixed-top">
<nav class="navbar navbar-expand-lg navbar-dark ">
<div class="navbar-container container-fluid">
<a class="navbar-brand" href="../index.html">
<img src="../logo.png" alt="">
<span class="navbar-title">Calculus with Julia</span>
</a>
<div id="quarto-search" class="" title="Search"></div>
</div> <!-- /container-fluid -->
</nav>
<nav class="quarto-secondary-nav" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
<div class="container-fluid d-flex justify-content-between">
<h1 class="quarto-secondary-nav-title"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">The Graph of a Function</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 active"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">The Graph of a Function</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/transformations.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Function manipulations</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/inversefunctions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">The Inverse of a Function</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/polynomial.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Polynomials</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/polynomial_roots.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">12</span>&nbsp; <span class="chapter-title">Roots of a polynomial</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/polynomials_package.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">13</span>&nbsp; <span class="chapter-title">The Polynomials package</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/rational_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">14</span>&nbsp; <span class="chapter-title">Rational functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/exp_log_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">15</span>&nbsp; <span class="chapter-title">Exponential and logarithmic functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/trig_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">16</span>&nbsp; <span class="chapter-title">Trigonometric functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/julia_overview.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">17</span>&nbsp; <span class="chapter-title">Overview of Julia commands</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" aria-expanded="false">Limits</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-2" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/limits.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">18</span>&nbsp; <span class="chapter-title">Limits</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/limits_extensions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">19</span>&nbsp; <span class="chapter-title">Limits, issues, extensions of the concept</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/continuity.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">20</span>&nbsp; <span class="chapter-title">Continuity</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/intermediate_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">21</span>&nbsp; <span class="chapter-title">Implications of continuity</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="false">Derivatives</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-3" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">22</span>&nbsp; <span class="chapter-title">Derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/numeric_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">23</span>&nbsp; <span class="chapter-title">Numeric derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/symbolic_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">24</span>&nbsp; <span class="chapter-title">Symbolic derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/mean_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">25</span>&nbsp; <span class="chapter-title">The mean value theorem for differentiable functions.</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/optimization.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">26</span>&nbsp; <span class="chapter-title">Optimization</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/first_second_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">27</span>&nbsp; <span class="chapter-title">The first and second derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/curve_sketching.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">28</span>&nbsp; <span class="chapter-title">Curve Sketching</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/linearization.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">29</span>&nbsp; <span class="chapter-title">Linearization</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/newtons_method.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">30</span>&nbsp; <span class="chapter-title">Newtons method</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/more_zeros.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">31</span>&nbsp; <span class="chapter-title">Derivative-free alternatives to Newtons method</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/lhospitals_rule.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">32</span>&nbsp; <span class="chapter-title">LHospitals Rule</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/implicit_differentiation.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">33</span>&nbsp; <span class="chapter-title">Implicit Differentiation</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/related_rates.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">34</span>&nbsp; <span class="chapter-title">Related rates</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/taylor_series_polynomials.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">35</span>&nbsp; <span class="chapter-title">Taylor Polynomials and other Approximating Polynomials</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-4" aria-expanded="false">Integrals</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-4" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-4" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/area.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">36</span>&nbsp; <span class="chapter-title">Area under a curve</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/ftc.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">37</span>&nbsp; <span class="chapter-title">Fundamental Theorem or Calculus</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/substitution.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">38</span>&nbsp; <span class="chapter-title">Substitution</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/integration_by_parts.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">39</span>&nbsp; <span class="chapter-title">Integration By Parts</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/partial_fractions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">40</span>&nbsp; <span class="chapter-title">Partial Fractions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/improper_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">41</span>&nbsp; <span class="chapter-title">Improper Integrals</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/mean_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">42</span>&nbsp; <span class="chapter-title">Mean value theorem for integrals</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/area_between_curves.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">43</span>&nbsp; <span class="chapter-title">Area between two curves</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/center_of_mass.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">44</span>&nbsp; <span class="chapter-title">Center of Mass</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/volumes_slice.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">45</span>&nbsp; <span class="chapter-title">Volumes by slicing</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/arc_length.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">46</span>&nbsp; <span class="chapter-title">Arc length</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/surface_area.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">47</span>&nbsp; <span class="chapter-title">Surface Area</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-5" aria-expanded="false">ODEs</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-5" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-5" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../ODEs/odes.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">48</span>&nbsp; <span class="chapter-title">ODEs</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../ODEs/euler.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">49</span>&nbsp; <span class="chapter-title">Eulers method</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../ODEs/solve.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">50</span>&nbsp; <span class="chapter-title">The problem-algorithm-solve interface</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../ODEs/differential_equations.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">51</span>&nbsp; <span class="chapter-title">The <code>DifferentialEquations</code> suite</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start 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="#graphing-a-function-with-julia" id="toc-graphing-a-function-with-julia" class="nav-link active" data-scroll-target="#graphing-a-function-with-julia"> <span class="header-section-number">8.1</span> Graphing a function with Julia</a></li>
<li><a href="#the-details-of-graph-making" id="toc-the-details-of-graph-making" class="nav-link" data-scroll-target="#the-details-of-graph-making"> <span class="header-section-number">8.2</span> The details of graph making</a></li>
<li><a href="#layers" id="toc-layers" class="nav-link" data-scroll-target="#layers"> <span class="header-section-number">8.3</span> Layers</a></li>
<li><a href="#additional-arguments" id="toc-additional-arguments" class="nav-link" data-scroll-target="#additional-arguments"> <span class="header-section-number">8.4</span> Additional arguments</a></li>
<li><a href="#graphs-of-parametric-equations" id="toc-graphs-of-parametric-equations" class="nav-link" data-scroll-target="#graphs-of-parametric-equations"> <span class="header-section-number">8.5</span> Graphs of parametric equations</a></li>
<li><a href="#questions" id="toc-questions" class="nav-link" data-scroll-target="#questions"> <span class="header-section-number">8.6</span> Questions</a></li>
<li><a href="#technical-note" id="toc-technical-note" class="nav-link" data-scroll-target="#technical-note"> <span class="header-section-number">8.7</span> Technical note</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/plotting.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">8</span>&nbsp; <span class="chapter-title">The Graph of a Function</span></h1>
</div>
<div class="quarto-title-meta">
</div>
</header>
<p>This section will use the following 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>A scalar, univariate function, such as <span class="math inline">\(f(x) = 1 - x^2/2\)</span>, can be thought of in many different ways. For example:</p>
<ul>
<li>It can be represented through a rule of what it does to <span class="math inline">\(x\)</span>, as above. This is useful for computing numeric values.</li>
<li>it can be interpreted verbally, as in <em>square</em> <span class="math inline">\(x\)</span>, take half then <em>subtract</em> from one. This can give clarity to what the function does.</li>
<li>It can be thought of in terms of its properties: a polynomial, continuous, <span class="math inline">\(U\)</span>-shaped, an approximation for <span class="math inline">\(\cos(x)\)</span> near <span class="math inline">\(0\)</span>, <span class="math inline">\(\dots\)</span></li>
<li>it can be visualized graphically. This is useful for seeing the qualitative behavior of a function.</li>
</ul>
<p>The graph of a univariate function is just a set of points in the Cartesian plane. These points come from the relation <span class="math inline">\((x,f(x))\)</span> that defines the function. Operationally, a sketch of the graph will consider a handful of such pairs and then the rest of the points will be imputed.</p>
<p>For example, a typical approach to plot <span class="math inline">\(f(x) = 1 - x^2/2\)</span> would be to choose some values for <span class="math inline">\(x\)</span> and find the corresponding values of <span class="math inline">\(y\)</span>. This might be organized in a “T”-table:</p>
<pre class="{verbatim}"><code> x | y
--------
-2 | -1
-1 | 1/2
0 | 1
1 | 1/2
2 | -1
3 | -7/2</code></pre>
<p>These pairs would be plotted in a Cartesian plane and then connected with curved lines. A good sketch is aided by knowing ahead of time that this function describes a parabola which is curving downwards.</p>
<p>We note that this sketch would not include <em>all</em> the pairs <span class="math inline">\((x,f(x))\)</span>, as their extent is infinite, rather a well chosen collection of points over some finite domain.</p>
<section id="graphing-a-function-with-julia" class="level2" data-number="8.1">
<h2 data-number="8.1" class="anchored" data-anchor-id="graphing-a-function-with-julia"><span class="header-section-number">8.1</span> Graphing a function with Julia</h2>
<p><code>Julia</code> has several different options for rendering graphs, all in external packages. We will focus in these notes on the <code>Plots</code> package, which provides a common interface to several different plotting backends. (Click through for instructions for plotting with the <a href="../alternatives/makie_plotting.html">Makie</a> package or the <a href="alternatives/plotly_plotting.html">PlotlyLight</a> package.) At the top of this section the accompanying <code>CalculusWithJulia</code> package and the <code>Plots</code> package were loaded with the <code>using</code> command, like this:</p>
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">CalculusWithJulia</span></span>
<span id="cb3-2"><a href="#cb3-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>
<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><code>Plots</code> is a frontend for one of several backends. <code>Plots</code> comes with a backend for web-based graphics (call <code>plotly()</code> to specify that); a backend for static graphs (call <code>gr()</code> for that). If the <code>PyPlot</code> package is installed, calling <code>pyplot()</code> will set that as a backend. For terminal usage, if the <code>UnicodePlots</code> package is installed, calling <code>unicodeplots()</code> will enable that usage. There are still other backends.</p>
</div>
</div>
<p>The <code>plotly</code> backend is part of the <code>Plots</code> package, as is <code>gr</code>. Other backends require installation, such as <code>PyPlot</code> and <code>PlotlyJS</code>. We use <code>gr</code> in these notes, for the most part. (The <code>plotly</code> backend is also quite nice for interactive usage, but doesnt work as well with the static HTML pages.)</p>
<p>With <code>Plots</code> loaded, it is straightforward to graph a function.</p>
<p>For example, to graph <span class="math inline">\(f(x) = 1 - x^2/2\)</span> over the interval <span class="math inline">\([-3,3]\)</span> we have:</p>
<div class="cell" data-execution_count="5">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x) <span class="op">=</span> <span class="fl">1</span> <span class="op">-</span> x<span class="op">^</span><span class="fl">2</span><span class="op">/</span><span class="fl">2</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(f, <span class="op">-</span><span class="fl">3</span>, <span class="fl">3</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="5">
<p><img src="plotting_files/figure-html/cell-6-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The <code>plot</code> command does the hard work behind the scenes. It needs <span class="math inline">\(2\)</span> pieces of information declared:</p>
<ul>
<li><strong>What</strong> to plot. With this invocation, this detail is expressed by passing a function object to <code>plot</code></li>
<li><strong>Where</strong> to plot; the <code>xmin</code> and <code>xmax</code> values. As with a sketch, it is impossible in this case to render a graph with all possible <span class="math inline">\(x\)</span> values in the domain of <span class="math inline">\(f\)</span>, so we need to pick some viewing window. In the example this is <span class="math inline">\([-3,3]\)</span> which is expressed by passing the two endpoints as the second and third arguments.</li>
</ul>
<p>Plotting a function is then this simple: <code>plot(f, xmin, xmax)</code>.</p>
<blockquote class="blockquote">
<p><em>A basic template:</em> Many operations we meet will take the form <code>action(function, args...)</code>, as the call to <code>plot</code> does. The template shifts the focus to the action to be performed. This is a <a href="http://en.wikipedia.org/wiki/Declarative_programming">declarative</a> style, where the details to execute the action are only exposed as needed.</p>
</blockquote>
<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 time to first plot can feel sluggish, but subsequent plots will be speedy. See the technical note at the end of this section for an explanation.</p>
</div>
</div>
<p>Lets see some other graphs.</p>
<p>The <code>sin</code> function over one period is plotted through:</p>
<div class="cell" data-execution_count="6">
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(sin, <span class="fl">0</span>, <span class="fl">2</span>pi)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="6">
<p><img src="plotting_files/figure-html/cell-7-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>We can make a graph of <span class="math inline">\(f(x) = (1+x^2)^{-1}\)</span> over <span class="math inline">\([-3,3]\)</span> with</p>
<div class="cell" data-hold="true" data-execution_count="7">
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x) <span class="op">=</span> <span class="fl">1</span> <span class="op">/</span> (<span class="fl">1</span> <span class="op">+</span> x<span class="op">^</span><span class="fl">2</span>)</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(f, <span class="op">-</span><span class="fl">3</span>, <span class="fl">3</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="7">
<p><img src="plotting_files/figure-html/cell-8-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>A graph of <span class="math inline">\(f(x) = e^{-x^2/2}\)</span> over <span class="math inline">\([-2,2]\)</span> is produced with:</p>
<div class="cell" data-hold="true" data-execution_count="8">
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x) <span class="op">=</span> <span class="fu">exp</span>(<span class="op">-</span>x<span class="op">^</span><span class="fl">2</span><span class="op">/</span><span class="fl">2</span>)</span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(f, <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="8">
<p><img src="plotting_files/figure-html/cell-9-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>We could skip the first step of defining a function by using an <em>anonymous function</em>. For example, to plot <span class="math inline">\(f(x) = \cos(x) - x\)</span> over <span class="math inline">\([0, \pi/2]\)</span> we could do:</p>
<div class="cell" data-execution_count="9">
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(x <span class="op">-&gt;</span> <span class="fu">cos</span>(x) <span class="op">-</span> x, <span class="fl">0</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="9">
<p><img src="plotting_files/figure-html/cell-10-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Anonymous functions are especially helpful when parameterized functions are involved:</p>
<div class="cell" data-hold="true" data-execution_count="10">
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mxplusb</span>(x; m<span class="op">=</span><span class="fl">1</span>, b<span class="op">=</span><span class="fl">0</span>) <span class="op">=</span> m<span class="op">*</span>x <span class="op">+</span> b</span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(x <span class="op">-&gt;</span> <span class="fu">mxplusb</span>(x; m<span class="op">=-</span><span class="fl">1</span>, b<span class="op">=</span><span class="fl">1</span>), <span class="op">-</span><span class="fl">1</span>, <span class="fl">2</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="10">
<p><img src="plotting_files/figure-html/cell-11-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Had we parameterized using the <code>f(x,p)</code> style, the result would be similar:</p>
<div class="cell" data-execution_count="11">
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span> <span class="fu">mxplusb</span>(x, p)</span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> m, b <span class="op">=</span> p.m, p.b</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a> m <span class="op">*</span> x <span class="op">+</span> b</span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(x <span class="op">-&gt;</span> <span class="fu">mxplusb</span>(x, (m<span class="op">=-</span><span class="fl">1</span>, b<span class="op">=</span><span class="fl">1</span>)), <span class="op">-</span><span class="fl">1</span>, <span class="fl">2</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="11">
<p><img src="plotting_files/figure-html/cell-12-output-1.svg" class="img-fluid"></p>
</div>
</div>
<div class="callout-note callout callout-style-default callout-captioned">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-caption-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>The function object in the general pattern <code>action(function, args...)</code> is commonly specified in one of three ways: by a name, as with <code>f</code>; as an anonymous function; or as the return value of some other action through composition.</p>
</div>
</div>
<p>Anonymous functions are also created by <code>Julia's</code> <code>do</code> notation, which is useful when the first argument to function (like <code>plot</code>) accepts a function:</p>
<div class="cell" data-execution_count="12">
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fl">0</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>) <span class="cf">do</span> x</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">cos</span>(x) <span class="op">-</span> x</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a><span class="cf">end</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="12">
<p><img src="plotting_files/figure-html/cell-13-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The <code>do</code> notation can be a bit confusing to read when unfamiliar, though its convenience makes it appealing.</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>Some types we will encounter, such as the one for symbolic values or the special polynomial one, have their own <code>plot</code> recipes that allow them to be plotted similarly as above, even though they are not functions.</p>
</div>
</div>
<hr>
<p>Making a graph with <code>Plots</code> is easy, but producing a graph that is informative can be a challenge, as the choice of a viewing window can make a big difference in what is seen. For example, trying to make a graph of <span class="math inline">\(f(x) = \tan(x)\)</span>, as below, will result in a bit of a mess - the chosen viewing window crosses several places where the function blows up:</p>
<div class="cell" data-hold="true" data-execution_count="13">
<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">f</span>(x) <span class="op">=</span> <span class="fu">tan</span>(x)</span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(f, <span class="op">-</span><span class="fl">10</span>, <span class="fl">10</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="13">
<p><img src="plotting_files/figure-html/cell-14-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Though this graph shows the asymptote structure and periodicity, it doesnt give much insight into each period or even into the fact that the function is periodic.</p>
</section>
<section id="the-details-of-graph-making" class="level2" data-number="8.2">
<h2 data-number="8.2" class="anchored" data-anchor-id="the-details-of-graph-making"><span class="header-section-number">8.2</span> The details of graph making</h2>
<p>The actual details of making a graph of <span class="math inline">\(f\)</span> over <span class="math inline">\([a,b]\)</span> are pretty simple and follow the steps in making a “T”-table:</p>
<ul>
<li>A set of <span class="math inline">\(x\)</span> values are created between <span class="math inline">\(a\)</span> and <span class="math inline">\(b\)</span>.</li>
<li>A corresponding set of <span class="math inline">\(y\)</span> values are created.</li>
<li>The pairs <span class="math inline">\((x,y)\)</span> are plotted as points and connected with straight lines.</li>
</ul>
<p>The only real difference is that when drawing by hand, we might know to curve the lines connecting points based on an analysis of the function. As <code>Julia</code> doesnt consider this, the points are connected with straight lines like a dot-to-dot puzzle.</p>
<p>In general, the <code>x</code> values are often generated by <code>range</code> or the <code>colon</code> operator and the <code>y</code> values produced by mapping or broadcasting a function over the generated <code>x</code> values.</p>
<p>However, the plotting directive <code>plot(f, xmin, xmax)</code> calls an adaptive algorithm to use more points where needed, as judged by <code>PlotUtils.adapted_grid(f, (xmin, xmax))</code>. It computes both the <code>x</code> and <code>y</code> values. This algorithm is wrapped up into the <code>unzip(f, xmin, xmax)</code> function from <code>CalculusWithJulia</code>. The algorithm adds more points where the function is more “curvy” and uses fewer points where it is “straighter.” Here we see the linear function is identified as needing far fewer points than the oscillating function when plotted over the same range:</p>
<div class="cell" data-execution_count="14">
<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">pts_needed</span>(f, xmin, xmax) <span class="op">=</span> <span class="fu">length</span>(<span class="fu">unzip</span>(f, xmin, xmax)[<span class="fl">1</span>])</span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a><span class="fu">pts_needed</span>(x <span class="op">-&gt;</span> <span class="fl">10</span>x, <span class="fl">0</span>, <span class="fl">10</span>), <span class="fu">pts_needed</span>(x <span class="op">-&gt;</span> <span class="fu">sin</span>(<span class="fl">10</span>x), <span class="fl">0</span>, <span class="fl">10</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="14">
<pre><code>(31, 1605)</code></pre>
</div>
</div>
<p>(In fact, the <code>21</code> is the minimum number of points used for any function; a linear function only needs two.)</p>
<hr>
<p>For instances where a <em>specific</em> set of <span class="math inline">\(x\)</span> values is desired to be used, the <code>range</code> function or colon operator can be used to create the <span class="math inline">\(x\)</span> values and broadcasting used to create the <span class="math inline">\(y\)</span> values. For example, if we were to plot <span class="math inline">\(f(x) = \sin(x)\)</span> over <span class="math inline">\([0,2\pi]\)</span> using <span class="math inline">\(10\)</span> points, we might do:</p>
<div class="cell" data-execution_count="15">
<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>𝒙s <span class="op">=</span> <span class="fu">range</span>(<span class="fl">0</span>, <span class="fl">2</span>pi, length<span class="op">=</span><span class="fl">10</span>)</span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>𝒚s <span class="op">=</span> <span class="fu">sin</span>.(𝒙s)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="15">
<pre><code>10-element Vector{Float64}:
0.0
0.6427876096865393
0.984807753012208
0.8660254037844387
0.3420201433256689
-0.34202014332566866
-0.8660254037844385
-0.9848077530122081
-0.6427876096865396
-2.4492935982947064e-16</code></pre>
</div>
</div>
<p>Finally, to plot the set of points and connect with lines, the <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span> values are passed along as vectors:</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>(𝒙s, 𝒚s)</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="plotting_files/figure-html/cell-17-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>This plots the points as pairs and then connects them in order using straight lines. Basically, it creates a dot-to-dot graph. The above graph looks primitive, as it doesnt utilize enough points.</p>
<section id="example-reflections" class="level5">
<h5 class="anchored" data-anchor-id="example-reflections">Example: Reflections</h5>
<p>The graph of a function may be reflected through a line, as those seen with a mirror. For example, a reflection through the <span class="math inline">\(y\)</span> axis takes a point <span class="math inline">\((x,y)\)</span> to the point <span class="math inline">\((-x, y)\)</span>. We can easily see this graphically, when we have sets of <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span> values through a judiciously placed minus sign.</p>
<p>For example, to plot <span class="math inline">\(\sin(x)\)</span> over <span class="math inline">\((-\pi,\pi)\)</span> we might do:</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>xs <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="cn">pi</span>, <span class="cn">pi</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a>ys <span class="op">=</span> <span class="fu">sin</span>.(xs)</span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(xs, ys)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="17">
<p><img src="plotting_files/figure-html/cell-18-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>To reflect this graph through the <span class="math inline">\(y\)</span> axis, we only need to plot <code>-xs</code> and not <code>xs</code>:</p>
<div class="cell" data-execution_count="18">
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="op">-</span>xs, ys)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="18">
<p><img src="plotting_files/figure-html/cell-19-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Looking carefully we see there is a difference. (How?)</p>
<p>There are four very common reflections:</p>
<ul>
<li>reflection through the <span class="math inline">\(y\)</span>-axis takes <span class="math inline">\((x,y)\)</span> to <span class="math inline">\((-x, y)\)</span>.</li>
<li>reflection through the <span class="math inline">\(x\)</span>-axis takes <span class="math inline">\((x,y)\)</span> to <span class="math inline">\((x, -y)\)</span>.</li>
<li>reflection through the origin takes <span class="math inline">\((x,y)\)</span> to <span class="math inline">\((-x, -y)\)</span>.</li>
<li>reflection through the line <span class="math inline">\(y=x\)</span> takes <span class="math inline">\((x,y)\)</span> to <span class="math inline">\((y,x)\)</span>.</li>
</ul>
<p>For the <span class="math inline">\(\sin(x)\)</span> graph, we see that reflecting through the <span class="math inline">\(x\)</span> axis produces the same graph as reflecting through the <span class="math inline">\(y\)</span> axis:</p>
<div class="cell" data-execution_count="19">
<div class="sourceCode cell-code" id="cb20"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(xs, <span class="op">-</span>ys)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="19">
<p><img src="plotting_files/figure-html/cell-20-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>However, reflecting through the origin leaves this graph unchanged:</p>
<div class="cell" data-execution_count="20">
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="op">-</span>xs, <span class="op">-</span>ys)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="20">
<p><img src="plotting_files/figure-html/cell-21-output-1.svg" class="img-fluid"></p>
</div>
</div>
<blockquote class="blockquote">
<p>An <em>even function</em> is one where reflection through the <span class="math inline">\(y\)</span> axis leaves the graph unchanged. That is, <span class="math inline">\(f(-x) = f(x)\)</span>. An <em>odd function</em> is one where a reflection through the origin leaves the graph unchanged, or symbolically <span class="math inline">\(f(-x) = -f(x)\)</span>.</p>
</blockquote>
<p>If we try reflecting the graph of <span class="math inline">\(\sin(x)\)</span> through the line <span class="math inline">\(y=x\)</span>, we have:</p>
<div class="cell" data-execution_count="21">
<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><span class="fu">plot</span>(ys, xs)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="21">
<p><img src="plotting_files/figure-html/cell-22-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>This is the graph of the equation <span class="math inline">\(x = \sin(y)\)</span>, but is not the graph of a function as the same <span class="math inline">\(x\)</span> can map to more than one <span class="math inline">\(y\)</span> value. (The new graph does not pass the “vertical line” test.)</p>
<p>However, for the sine function we can get a function from this reflection if we choose a narrower viewing window:</p>
<div class="cell" data-hold="true" data-execution_count="22">
<div class="sourceCode cell-code" id="cb23"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a>ys <span class="op">=</span> <span class="fu">sin</span>.(xs)</span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(ys, xs)</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="plotting_files/figure-html/cell-23-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The graph is that of the “inverse function” for <span class="math inline">\(\sin(x), x \text{ in } [-\pi/2, \pi/2]\)</span>.</p>
</section>
<section id="the-plotxs-f-syntax" class="level4">
<h4 class="anchored" data-anchor-id="the-plotxs-f-syntax">The <code>plot(xs, f)</code> syntax</h4>
<p>When plotting a univariate function there are three basic patterns that can be employed. We have examples above of:</p>
<ul>
<li><code>plot(f, xmin, xmax)</code> uses an adaptive algorithm to identify values for <span class="math inline">\(x\)</span> in the interval <code>[xmin, xmas]</code>,</li>
<li><code>plot(xs, f.(xs))</code> to manually choose the values of <span class="math inline">\(x\)</span> to plot points for, and</li>
</ul>
<p>Finally there is a merging of these following either of these patterns:</p>
<ul>
<li><code>plot(f, xs)</code> <em>or</em> <code>plot(xs, f)</code></li>
</ul>
<p>Both require a manual choice of the values of the <span class="math inline">\(x\)</span>-values to plot, but the broadcasting is carried out in the <code>plot</code> command. This style is convenient, for example, to down sample the <span class="math inline">\(x\)</span> range to see the plotting mechanics, such as:</p>
<div class="cell" data-execution_count="23">
<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">plot</span>(<span class="fl">0</span><span class="op">:</span><span class="cn">pi</span><span class="op">/</span><span class="fl">4</span><span class="op">:</span><span class="fl">2</span>pi, sin)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="23">
<p><img src="plotting_files/figure-html/cell-24-output-1.svg" class="img-fluid"></p>
</div>
</div>
</section>
<section id="nan-values" class="level4">
<h4 class="anchored" data-anchor-id="nan-values">NaN values</h4>
<p>At times it is not desirable to draw lines between each succesive point. For example, if there is a discontinuity in the function or if there were a vertical asymptote, such as what happens at <span class="math inline">\(0\)</span> with <span class="math inline">\(f(x) = 1/x\)</span>.</p>
<p>The most straightforward plot is dominated by the vertical asymptote at <span class="math inline">\(x=0\)</span>:</p>
<div class="cell" data-execution_count="24">
<div class="sourceCode cell-code" id="cb25"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="fu">q</span>(x) <span class="op">=</span> <span class="fl">1</span><span class="op">/</span>x</span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(q, <span class="op">-</span><span class="fl">1</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="24">
<p><img src="plotting_files/figure-html/cell-25-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>We can attempt to improve this graph by adjusting the viewport. The <em>viewport</em> of a graph is the <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span> range of the viewing window. By default, the <span class="math inline">\(y\)</span>-part of the viewport is determined by the range of the function over the specified interval, <span class="math inline">\([a,b]\)</span>. As just seen, this approach can produce poor graphs. The <code>ylims=(ymin, ymax)</code> argument can modify what part of the <span class="math inline">\(y\)</span> axis is shown. (Similarly <code>xlims=(xmin, xmax)</code> will modify the viewport in the <span class="math inline">\(x\)</span> direction.)</p>
<p>As we see, even with this adjustment, the spurious line connecting the points with <span class="math inline">\(x\)</span> values closest to <span class="math inline">\(0\)</span> is still drawn:</p>
<div class="cell" data-execution_count="25">
<div class="sourceCode cell-code" id="cb26"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(q, <span class="op">-</span><span class="fl">1</span>, <span class="fl">1</span>, ylims<span class="op">=</span>(<span class="op">-</span><span class="fl">10</span>,<span class="fl">10</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="25">
<p><img src="plotting_files/figure-html/cell-26-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The dot-to-dot algorithm, at some level, assumes the underlying function is continuous; here <span class="math inline">\(q(x)=1/x\)</span> is not.</p>
<p>There is a convention for most plotting programs that <strong>if</strong> the <span class="math inline">\(y\)</span> value for a point is <code>NaN</code> that no lines will connect to that point, <code>(x,NaN)</code>. <code>NaN</code> conveniently appears in many cases where a plot may have an issue, though not with <span class="math inline">\(1/x\)</span> as <code>1/0</code> is <code>Inf</code> and not <code>NaN</code>. (Unlike, say, <code>0/0</code> which is NaN.)</p>
<p>Here is one way to plot <span class="math inline">\(q(x) = 1/x\)</span> over <span class="math inline">\([-1,1]\)</span> taking advantage of this convention:</p>
<div class="cell" data-hold="true" data-execution_count="26">
<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>xs <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">1</span>, <span class="fl">1</span>, length<span class="op">=</span><span class="fl">251</span>)</span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a>ys <span class="op">=</span> <span class="fu">q</span>.(xs)</span>
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true" tabindex="-1"></a>ys[xs <span class="op">.==</span> <span class="fl">0.0</span>] <span class="op">.=</span> <span class="cn">NaN</span></span>
<span id="cb27-4"><a href="#cb27-4" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(xs, ys)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="26">
<p><img src="plotting_files/figure-html/cell-27-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>By using an odd number of points, we should have that <span class="math inline">\(0.0\)</span> is amongst the <code>xs</code>. The next to last line replaces the <span class="math inline">\(y\)</span> value that would be infinite with <code>NaN</code>.</p>
<p>As a recommended alternative, we might modify the function so that if it is too large, the values are replaced by <code>NaN</code>. Here is one such function consuming a function and returning a modified function put to use to make this graph:</p>
<div class="cell" data-execution_count="27">
<div class="sourceCode cell-code" id="cb28"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a><span class="fu">rangeclamp</span>(f, hi<span class="op">=</span><span class="fl">20</span>, lo<span class="op">=-</span>hi; replacement<span class="op">=</span><span class="cn">NaN</span>) <span class="op">=</span> x <span class="op">-&gt;</span> lo <span class="op">&lt;</span> <span class="fu">f</span>(x) <span class="op">&lt;</span> hi ? <span class="fu">f</span>(x) <span class="op">:</span> replacement</span>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">rangeclamp</span>(x <span class="op">-&gt;</span> <span class="fl">1</span><span class="op">/</span>x), <span class="op">-</span><span class="fl">1</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">
<p><img src="plotting_files/figure-html/cell-28-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>(The <code>clamp</code> function is a base <code>Julia</code> function which clamps a number between <code>lo</code> and <code>hi</code>, returning <code>lo</code> or <code>hi</code> if <code>x</code> is outside that range.)</p>
</section>
</section>
<section id="layers" class="level2" data-number="8.3">
<h2 data-number="8.3" class="anchored" data-anchor-id="layers"><span class="header-section-number">8.3</span> Layers</h2>
<p>Graphing more than one function over the same viewing window is often desirable. Though this is easily done in <code>Plots</code> by specifying a vector of functions as the first argument to <code>plot</code> instead of a single function object, we instead focus on building the graph layer by layer.</p>
<p>For example, to see that a polynomial and the cosine function are “close” near <span class="math inline">\(0\)</span>, we can plot <em>both</em> <span class="math inline">\(\cos(x)\)</span> and the function <span class="math inline">\(f(x) = 1 - x^2/2\)</span> over <span class="math inline">\([-\pi/2,\pi/2]\)</span>:</p>
<div class="cell" data-hold="true" data-execution_count="28">
<div class="sourceCode cell-code" id="cb29"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x) <span class="op">=</span> <span class="fl">1</span> <span class="op">-</span> x<span class="op">^</span><span class="fl">2</span><span class="op">/</span><span class="fl">2</span></span>
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(cos, <span class="op">-</span><span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, label<span class="op">=</span><span class="st">"cos"</span>)</span>
<span id="cb29-3"><a href="#cb29-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(f, <span class="op">-</span><span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, label<span class="op">=</span><span class="st">"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="28">
<p><img src="plotting_files/figure-html/cell-29-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Another useful function to add to a plot is one to highlight the <span class="math inline">\(x\)</span> axis. This makes identifying zeros of the function easier. The anonymous function <code>x -&gt; 0</code> will do this. But, perhaps less cryptically, so will the base function <code>zero</code>. For example</p>
<div class="cell" data-hold="true" data-execution_count="29">
<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">f</span>(x) <span class="op">=</span> x<span class="op">^</span><span class="fl">5</span> <span class="op">-</span> x <span class="op">+</span> <span class="fl">1</span></span>
<span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(f, <span class="op">-</span><span class="fl">1.5</span>, <span class="fl">1.4</span>, label<span class="op">=</span><span class="st">"f"</span>)</span>
<span id="cb30-3"><a href="#cb30-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(zero, label<span class="op">=</span><span class="st">"zero"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="29">
<p><img src="plotting_files/figure-html/cell-30-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>(The job of <code>zero</code> is to return “<span class="math inline">\(0\)</span>” in the appropriate type. There is also a similar <code>one</code> function in base <code>Julia</code>.)</p>
<p>The <code>plot!</code> call adds a layer. We could still specify the limits for the plot, though as this can be computed from the figure, to plot <code>zero</code> we let <code>Plots</code> do it.</p>
<p>For another example, suppose we wish to plot the function <span class="math inline">\(f(x)=x\cdot(x-1)\)</span> over the interval <span class="math inline">\([-1,2]\)</span> and emphasize with points the fact that <span class="math inline">\(0\)</span> and <span class="math inline">\(1\)</span> are zeros. We can do this with three layers: the first to graph the function, the second to emphasize the <span class="math inline">\(x\)</span> axis, the third to graph the points.</p>
<div class="cell" data-hold="true" data-execution_count="30">
<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">f</span>(x) <span class="op">=</span> <span class="fu">x*</span>(x<span class="op">-</span><span class="fl">1</span>)</span>
<span id="cb31-2"><a href="#cb31-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(f, <span class="op">-</span><span class="fl">1</span>, <span class="fl">2</span>, legend<span class="op">=</span><span class="cn">false</span>) <span class="co"># turn off legend</span></span>
<span id="cb31-3"><a href="#cb31-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(zero)</span>
<span id="cb31-4"><a href="#cb31-4" aria-hidden="true" tabindex="-1"></a><span class="fu">scatter!</span>([<span class="fl">0</span>,<span class="fl">1</span>], [<span class="fl">0</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="30">
<p><img src="plotting_files/figure-html/cell-31-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The <span class="math inline">\(3\)</span> main functions used in these notes for adding layers are:</p>
<ul>
<li><code>plot!(f, a, b)</code> to add the graph of the function <code>f</code>; also <code>plot!(xs, ys)</code></li>
<li><code>scatter!(xs, ys)</code> to add points <span class="math inline">\((x_1, y_1), (x_2, y_2), \dots\)</span>.</li>
<li><code>annotate!((x,y, label))</code> to add a label at <span class="math inline">\((x,y)\)</span></li>
</ul>
<div class="callout-warning callout callout-style-default callout-captioned">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-caption-container flex-fill">
Warning
</div>
</div>
<div class="callout-body-container callout-body">
<p>Julia has a convention to use functions named with a <code>!</code> suffix to indicate that they mutate some object. In this case, the object is the current graph, though it is implicit. Both <code>plot!</code>, <code>scatter!</code>, and <code>annotate!</code> (others too) do this by adding a layer.</p>
</div>
</div>
</section>
<section id="additional-arguments" class="level2" data-number="8.4">
<h2 data-number="8.4" class="anchored" data-anchor-id="additional-arguments"><span class="header-section-number">8.4</span> Additional arguments</h2>
<p>The <code>Plots</code> package provides many arguments for adjusting a graphic, here we mention just a few of the <a href="https://docs.juliaplots.org/latest/attributes/">attributes</a>:</p>
<ul>
<li><code>plot(..., title="main title", xlab="x axis label", ylab="y axis label")</code>: add title and label information to a graphic</li>
<li><code>plot(..., color="green")</code>: this argument can be used to adjust the color of the drawn figure (color can be a string,<code>"green"</code>, or a symbol, <code>:green</code>, among other specifications)</li>
<li><code>plot(..., linewidth=5)</code>: this argument can be used to adjust the width of drawn lines</li>
<li><code>plot(..., xlims=(a,b), ylims=(c,d)</code>: either or both <code>xlims</code> and <code>ylims</code> can be used to control the viewing window</li>
<li><code>plot(..., linestyle=:dash)</code>: will change the line style of the plotted lines to dashed lines. Also <code>:dot</code>, …</li>
<li><code>plot(..., aspect_ratio=:equal)</code>: will keep <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span> axis on same scale so that squares look square.</li>
<li><code>plot(..., legend=false)</code>: by default, different layers will be indicated with a legend, this will turn off this feature</li>
<li><code>plot(..., label="a label")</code> the <code>label</code> attribute will show up when a legend is present. Using an empty string, <code>""</code>, will suppress add the layer to the legend.</li>
</ul>
<p>For plotting points with <code>scatter</code>, or <code>scatter!</code> the markers can be adjusted via</p>
<ul>
<li><code>scatter(..., markersize=5)</code>: increase marker size</li>
<li><code>scatter(..., marker=:square)</code>: change the marker (uses a symbol, not a string to specify)</li>
</ul>
<p>Of course, zero, one, or more of these can be used on any given call to <code>plot</code>, <code>plot!</code>, <code>scatter</code> or <code>scatter!</code>.</p>
</section>
<section id="graphs-of-parametric-equations" class="level2" data-number="8.5">
<h2 data-number="8.5" class="anchored" data-anchor-id="graphs-of-parametric-equations"><span class="header-section-number">8.5</span> Graphs of parametric equations</h2>
<p>If we have two functions <span class="math inline">\(f(x)\)</span> and <span class="math inline">\(g(x)\)</span> there are a few ways to investigate their joint behavior. As just mentioned, we can graph both <span class="math inline">\(f\)</span> and <span class="math inline">\(g\)</span> over the same interval using layers. Such a graph allows an easy comparison of the shape of the two functions and can be useful in solving <span class="math inline">\(f(x) = g(x)\)</span>. For the latter, the graph of <span class="math inline">\(h(x) = f(x) - g(x)\)</span> is also of value: solutions to <span class="math inline">\(f(x)=g(x)\)</span> appear as crossing points on the graphs of <code>f</code> and <code>g</code>, whereas they appear as zeros (crossings of the <span class="math inline">\(x\)</span>-axis) when <code>h</code> is plotted.</p>
<p>A different graph can be made to compare the two functions side-by-side. This is a parametric plot. Rather than plotting points <span class="math inline">\((x,f(x))\)</span> and <span class="math inline">\((x,g(x))\)</span> with two separate graphs, the graph consists of points <span class="math inline">\((f(x), g(x))\)</span>. We illustrate with some examples below:</p>
<section id="example" class="level5">
<h5 class="anchored" data-anchor-id="example">Example</h5>
<p>The most “famous” parametric graph is one that is likely already familiar, as it follows the parametrization of points on the unit circle by the angle made between the <span class="math inline">\(x\)</span> axis and the ray from the origin through the point. (If not familiar, this will soon be discussed in these notes.)</p>
<div class="cell" data-execution_count="31">
<div class="sourceCode cell-code" id="cb32"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a><span class="fu">𝒇</span>(x) <span class="op">=</span> <span class="fu">cos</span>(x); <span class="fu">𝒈</span>(x) <span class="op">=</span> <span class="fu">sin</span>(x)</span>
<span id="cb32-2"><a href="#cb32-2" aria-hidden="true" tabindex="-1"></a>𝒕s <span class="op">=</span> <span class="fu">range</span>(<span class="fl">0</span>, <span class="fl">2</span>pi, length<span class="op">=</span><span class="fl">100</span>)</span>
<span id="cb32-3"><a href="#cb32-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">𝒇</span>.(𝒕s), <span class="fu">𝒈</span>.(𝒕s), aspect_ratio<span class="op">=:</span>equal) <span class="co"># make equal axes</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">
<p><img src="plotting_files/figure-html/cell-32-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Any point <span class="math inline">\((a,b)\)</span> on this graph is represented by <span class="math inline">\((\cos(t), \sin(t))\)</span> for some value of <span class="math inline">\(t\)</span>, and in fact multiple values of <span class="math inline">\(t\)</span>, since <span class="math inline">\(t + 2k\pi\)</span> will produce the same <span class="math inline">\((a,b)\)</span> value as <span class="math inline">\(t\)</span> will.</p>
<p>Making the parametric plot is similar to creating a plot using lower level commands. There a sequence of values is generated to approximate the <span class="math inline">\(x\)</span> values in the graph (<code>xs</code>), a set of commands to create the corresponding function values (e.g., <code>f.(xs)</code>), and some instruction on how to represent the values, in this case with lines connecting the points (the default for <code>plot</code> for two sets of numbers).</p>
<p>In this next plot, the angle values are chosen to be the familiar ones, so the mechanics of the graph can be emphasized. Only the upper half is plotted:</p>
<div class="cell" data-hold="true" data-execution_count="32">
<div class="cell-output cell-output-display" data-execution_count="32">
<div class="data-frame"><p>9 rows × 3 columns</p><table class="data-frame table table-sm table-striped"><thead><tr><th></th><th>θ</th><th>x</th><th>y</th></tr><tr><th></th><th title="Sym">Sym</th><th title="Sym">Sym</th><th title="Sym">Sym</th></tr></thead><tbody><tr><th>1</th><td>0</td><td>1</td><td>0</td></tr><tr><th>2</th><td>pi/6</td><td>sqrt(3)/2</td><td>1/2</td></tr><tr><th>3</th><td>pi/4</td><td>sqrt(2)/2</td><td>sqrt(2)/2</td></tr><tr><th>4</th><td>pi/3</td><td>1/2</td><td>sqrt(3)/2</td></tr><tr><th>5</th><td>pi/2</td><td>0</td><td>1</td></tr><tr><th>6</th><td>2*pi/3</td><td>-1/2</td><td>sqrt(3)/2</td></tr><tr><th>7</th><td>3*pi/4</td><td>-sqrt(2)/2</td><td>sqrt(2)/2</td></tr><tr><th>8</th><td>5*pi/6</td><td>-sqrt(3)/2</td><td>1/2</td></tr><tr><th>9</th><td>pi</td><td>-1</td><td>0</td></tr></tbody></table></div>
</div>
</div>
<div class="cell" data-hold="true" data-execution_count="33">
<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>θs <span class="op">=</span>[<span class="fl">0</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">6</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">4</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">3</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, <span class="fl">2</span>pi<span class="op">/</span><span class="fl">3</span>, <span class="fl">3</span>pi<span class="op">/</span><span class="fl">4</span>, <span class="fl">5</span>pi<span class="op">/</span><span class="fl">6</span>, <span class="cn">pi</span>]</span>
<span id="cb33-2"><a href="#cb33-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">𝒇</span>.(θs), <span class="fu">𝒈</span>.(θs), legend<span class="op">=</span><span class="cn">false</span>, aspect_ratio<span class="op">=:</span>equal)</span>
<span id="cb33-3"><a href="#cb33-3" aria-hidden="true" tabindex="-1"></a><span class="fu">scatter!</span>(<span class="fu">𝒇</span>.(θs), <span class="fu">𝒈</span>.(θs))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="33">
<p><img src="plotting_files/figure-html/cell-34-output-1.svg" class="img-fluid"></p>
</div>
</div>
<hr>
<p>As with the plot of a univariate function, there is a convenience interface for these plots - just pass the two functions in:</p>
<div class="cell" data-execution_count="34">
<div class="sourceCode cell-code" id="cb34"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(𝒇, 𝒈, <span class="fl">0</span>, <span class="fl">2</span>pi, aspect_ratio<span class="op">=:</span>equal)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="34">
<p><img src="plotting_files/figure-html/cell-35-output-1.svg" class="img-fluid"></p>
</div>
</div>
</section>
<section id="example-1" class="level5">
<h5 class="anchored" data-anchor-id="example-1">Example</h5>
<p>Looking at growth. Comparing <span class="math inline">\(x^2\)</span> with <span class="math inline">\(x^3\)</span> can run into issues, as the scale gets big:</p>
<div class="cell" data-execution_count="35">
<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"></span>(x) <span class="op">=</span> x<span class="op">^</span><span class="fl">2</span></span>
<span id="cb35-2"><a href="#cb35-2" aria-hidden="true" tabindex="-1"></a><span class="fu"></span>(x) <span class="op">=</span> x<span class="op">^</span><span class="fl">3</span></span>
<span id="cb35-3"><a href="#cb35-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(x², <span class="fl">0</span>, <span class="fl">25</span>)</span>
<span id="cb35-4"><a href="#cb35-4" aria-hidden="true" tabindex="-1"></a><span class="fu">plot!</span>(x³, <span class="fl">0</span>, <span class="fl">25</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="35">
<p><img src="plotting_files/figure-html/cell-36-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>In the above, <code></code> is already <span class="math inline">\(25\)</span> times larger on the scale of <span class="math inline">\([0,25]\)</span> and this only gets worse if the viewing window were to get larger. However, the parametric graph is quite different:</p>
<div class="cell" data-execution_count="36">
<div class="sourceCode cell-code" id="cb36"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(x², x³, <span class="fl">0</span>, <span class="fl">25</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="36">
<p><img src="plotting_files/figure-html/cell-37-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>In this graph, as <span class="math inline">\(x^3/x^2 = x\)</span>, as <span class="math inline">\(x\)</span> gets large, the ratio stays reasonable.</p>
</section>
<section id="example-2" class="level5">
<h5 class="anchored" data-anchor-id="example-2">Example</h5>
<p>Parametric plots are useful to compare the ratio of values near a point. In the above example, we see how this is helpful for large <code>x</code>. This example shows it is convenient for a fixed <code>x</code>, in this case <code>x=0</code>.</p>
<p>Plot <span class="math inline">\(f(x) = x^3\)</span> and <span class="math inline">\(g(x) = x - \sin(x)\)</span> around <span class="math inline">\(x=0\)</span>:</p>
<div class="cell" data-hold="true" data-execution_count="37">
<div class="sourceCode cell-code" id="cb37"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb37-1"><a href="#cb37-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x) <span class="op">=</span> x<span class="op">^</span><span class="fl">3</span></span>
<span id="cb37-2"><a href="#cb37-2" aria-hidden="true" tabindex="-1"></a><span class="fu">g</span>(x) <span class="op">=</span> x <span class="op">-</span> <span class="fu">sin</span>(x)</span>
<span id="cb37-3"><a href="#cb37-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(f, g, <span class="op">-</span><span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, <span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="37">
<p><img src="plotting_files/figure-html/cell-38-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>This graph is <em>nearly</em> a straight line. At the point <span class="math inline">\((0,0)=(g(0), g(0))\)</span>, we see that both functions are behaving in a similar manner, though the slope is not <span class="math inline">\(1\)</span>, so they do not increase at exactly the same rate.</p>
</section>
<section id="example-etch-a-sketch" class="level5">
<h5 class="anchored" data-anchor-id="example-etch-a-sketch">Example: Etch A Sketch</h5>
<p><a href="http://en.wikipedia.org/wiki/Etch_A_Sketch">Etch A sketch</a> is a drawing toy where two knobs control the motion of a pointer, one knob controlling the <span class="math inline">\(x\)</span> motion, the other the <span class="math inline">\(y\)</span> motion. The trace of the movement of the pointer is recorded until the display is cleared by shaking. Shake to clear is now a motion incorporated by some smart-phone apps.</p>
<p>Playing with the toy makes a few things become clear:</p>
<ul>
<li>Twisting just the left knob (the horizontal or <span class="math inline">\(x\)</span> motion) will move the pointer left or right, leaving a horizontal line. Parametrically, this would follow the equations <span class="math inline">\(f(t) = \xi(t)\)</span> for some <span class="math inline">\(\xi\)</span> and <span class="math inline">\(g(t) = c\)</span>.</li>
<li>Twisting just the right knob (the vertical or <span class="math inline">\(y\)</span> motion) will move the pointer up or down, leaving a vertical line. Parametrically, this would follow the equations <span class="math inline">\(f(t) = c\)</span> and <span class="math inline">\(g(t) = \psi(t)\)</span> for some <span class="math inline">\(\psi\)</span>.</li>
<li>Drawing a line with a slope different from <span class="math inline">\(0\)</span> or <span class="math inline">\(\infty\)</span> requires moving both knobs at the same time. A <span class="math inline">\(45\)</span><span class="math inline">\(^\circ\)</span> line with slope <span class="math inline">\(m=1\)</span> can be made by twisting both at the same rate, say through <span class="math inline">\(f(t) = ct\)</span>, <span class="math inline">\(g(t)=ct\)</span>. It doesnt matter how big <span class="math inline">\(c\)</span> is, just that it is the same for both <span class="math inline">\(f\)</span> and <span class="math inline">\(g\)</span>. Creating a different slope is done by twisting at different rates, say <span class="math inline">\(f(t)=ct\)</span> and <span class="math inline">\(g(t)=dt\)</span>. The slope of the resulting line will be <span class="math inline">\(d/c\)</span>.</li>
<li>Drawing a curve is done by twisting the two knobs with varying rates.</li>
</ul>
<p>These all apply to parametric plots, as the Etch A Sketch trace is no more than a plot of <span class="math inline">\((f(t), g(t))\)</span> over some range of values for <span class="math inline">\(t\)</span>, where <span class="math inline">\(f\)</span> describes the movement in time of the left knob and <span class="math inline">\(g\)</span> the movement in time of the right.</p>
<p>Now, we revist the last problem in the context of this. We saw in the last problem that the parametric graph was nearly a line - so close the eye cant really tell otherwise. That means that the growth in both <span class="math inline">\(f(t) = t^3\)</span> and <span class="math inline">\(g(t)=t - \sin(t)\)</span> for <span class="math inline">\(t\)</span> around <span class="math inline">\(0\)</span> are in a nearly fixed ratio, as otherwise the graph would have more curve in it.</p>
</section>
<section id="example-spirograph" class="level5">
<h5 class="anchored" data-anchor-id="example-spirograph">Example: Spirograph</h5>
<p>Parametric plots can describe a richer set of curves than can plots of functions. Plots of functions must pass the “vertical-line test”, as there can be at most one <span class="math inline">\(y\)</span> value for a given <span class="math inline">\(x\)</span> value. This is not so for parametric plots, as the circle example above shows. Plotting sines and cosines this way is the basis for the once popular <a href="http://en.wikipedia.org/wiki/Spirograph#Mathematical_basis">Spirograph</a> toy. The curves drawn there are parametric plots where the functions come from rolling a smaller disc either around the outside or inside of a larger disc.</p>
<p>Here is an example using a parameterization provided on the Wikipedia page where <span class="math inline">\(R\)</span> is the radius of the larger disc, <span class="math inline">\(r\)</span> the radius of the smaller disc and <span class="math inline">\(\rho &lt; r\)</span> indicating the position of the pencil within the smaller disc.</p>
<div class="cell" data-hold="true" data-execution_count="38">
<div class="sourceCode cell-code" id="cb38"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb38-1"><a href="#cb38-1" aria-hidden="true" tabindex="-1"></a>R, r, rho <span class="op">=</span> <span class="fl">1</span>, <span class="fl">1</span><span class="op">/</span><span class="fl">4</span>, <span class="fl">1</span><span class="op">/</span><span class="fl">4</span></span>
<span id="cb38-2"><a href="#cb38-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(t) <span class="op">=</span> (R<span class="op">-</span>r) <span class="op">*</span> <span class="fu">cos</span>(t) <span class="op">+</span> rho <span class="op">*</span> <span class="fu">cos</span>((R<span class="op">-</span>r)<span class="op">/</span>r <span class="op">*</span> t)</span>
<span id="cb38-3"><a href="#cb38-3" aria-hidden="true" tabindex="-1"></a><span class="fu">g</span>(t) <span class="op">=</span> (R<span class="op">-</span>r) <span class="op">*</span> <span class="fu">sin</span>(t) <span class="op">-</span> rho <span class="op">*</span> <span class="fu">sin</span>((R<span class="op">-</span>r)<span class="op">/</span>r <span class="op">*</span> t)</span>
<span id="cb38-4"><a href="#cb38-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-5"><a href="#cb38-5" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(f, g, <span class="fl">0</span>, <span class="fu">max</span>((R<span class="op">-</span>r)<span class="op">/</span>r, r<span class="op">/</span>(R<span class="op">-</span>r))<span class="op">*</span><span class="fl">2</span>pi)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="38">
<p><img src="plotting_files/figure-html/cell-39-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>In the above, one can fix <span class="math inline">\(R=1\)</span>. Then different values for <code>r</code> and <code>rho</code> will produce different graphs. These graphs will be periodic if <span class="math inline">\((R-r)/r\)</span> is a rational. (Nothing about these equations requires <span class="math inline">\(\rho &lt; r\)</span>.)</p>
</section>
</section>
<section id="questions" class="level2" data-number="8.6">
<h2 data-number="8.6" class="anchored" data-anchor-id="questions"><span class="header-section-number">8.6</span> Questions</h2>
<section id="question" class="level6">
<h6 class="anchored" data-anchor-id="question">Question</h6>
<p>Plot the function <span class="math inline">\(f(x) = x^3 - x\)</span>. When is the function positive?</p>
<div class="cell" data-hold="true" data-execution_count="39">
<div class="cell-output cell-output-display" data-execution_count="39">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="9072286468236693779" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_9072286468236693779">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_9072286468236693779_1">
<input class="form-check-input" type="radio" name="radio_9072286468236693779" id="radio_9072286468236693779_1" value="1">
<span class="label-body px-1">
<code>(-1, 0)</code> and <code>(1, Inf)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_9072286468236693779_2">
<input class="form-check-input" type="radio" name="radio_9072286468236693779" id="radio_9072286468236693779_2" value="2">
<span class="label-body px-1">
<code>(-Inf, -0.577)</code> and <code>(0.577, Inf)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_9072286468236693779_3">
<input class="form-check-input" type="radio" name="radio_9072286468236693779" id="radio_9072286468236693779_3" value="3">
<span class="label-body px-1">
<code>(-Inf, -1)</code> and <code>(0,1)</code>
</span>
</label>
</div>
</div>
</div>
<div id="9072286468236693779_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_9072286468236693779"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('9072286468236693779_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_9072286468236693779")
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_9072286468236693779")
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>Plot the function <span class="math inline">\(f(x) = 3x^4 + 8x^3 - 18x^2\)</span>. Where (what <span class="math inline">\(x\)</span> value) is the smallest value? (That is, for which input <span class="math inline">\(x\)</span> is the output <span class="math inline">\(f(x)\)</span> as small as possible.</p>
<div class="cell" data-hold="true" data-execution_count="40">
<div class="cell-output cell-output-display" data-execution_count="40">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="62567470117662231" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_62567470117662231">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="62567470117662231" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="62567470117662231_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("62567470117662231").addEventListener("change", function() {
var correct = (Math.abs(this.value - -3) <= 0.25);
var msgBox = document.getElementById('62567470117662231_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_62567470117662231")
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_62567470117662231")
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>Plot the function <span class="math inline">\(f(x) = 3x^4 + 8x^3 - 18x^2\)</span>. When is the function increasing?</p>
<div class="cell" data-hold="true" data-execution_count="41">
<div class="cell-output cell-output-display" data-execution_count="41">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="11172431834144415184" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_11172431834144415184">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_11172431834144415184_1">
<input class="form-check-input" type="radio" name="radio_11172431834144415184" id="radio_11172431834144415184_1" value="1">
<span class="label-body px-1">
<code>(-3, 0)</code> and <code>(1, Inf)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_11172431834144415184_2">
<input class="form-check-input" type="radio" name="radio_11172431834144415184" id="radio_11172431834144415184_2" value="2">
<span class="label-body px-1">
<code>(-Inf, -3)</code> and <code>(0, 1)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_11172431834144415184_3">
<input class="form-check-input" type="radio" name="radio_11172431834144415184" id="radio_11172431834144415184_3" value="3">
<span class="label-body px-1">
<code>(-Inf, -4.1)</code> and <code>(1.455, Inf)</code>
</span>
</label>
</div>
</div>
</div>
<div id="11172431834144415184_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_11172431834144415184"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('11172431834144415184_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_11172431834144415184")
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_11172431834144415184")
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>Graphing both <code>f</code> and the line <span class="math inline">\(y=0\)</span> helps focus on the <em>zeros</em> of <code>f</code>. When <code>f(x)=log(x)-2</code>, plot <code>f</code> and the line <span class="math inline">\(y=0\)</span>. Identify the lone zero.</p>
<div class="cell" data-hold="true" data-execution_count="42">
<div class="cell-output cell-output-display" data-execution_count="42">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="8268432280259085227" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_8268432280259085227">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="8268432280259085227" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="8268432280259085227_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("8268432280259085227").addEventListener("change", function() {
var correct = (Math.abs(this.value - 7.38905609893065) <= 0.5);
var msgBox = document.getElementById('8268432280259085227_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_8268432280259085227")
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_8268432280259085227")
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>Plot the function <span class="math inline">\(f(x) = x^3 - x\)</span> over <span class="math inline">\([-2,2]\)</span>. How many zeros are there?</p>
<div class="cell" data-hold="true" data-execution_count="43">
<div class="cell-output cell-output-display" data-execution_count="43">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="5566470711795800839" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_5566470711795800839">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="5566470711795800839" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="5566470711795800839_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("5566470711795800839").addEventListener("change", function() {
var correct = (Math.abs(this.value - 3) <= 1.0e-16);
var msgBox = document.getElementById('5566470711795800839_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_5566470711795800839")
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_5566470711795800839")
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 function <span class="math inline">\(f(x) = (x^3 - 2x) / (2x^2 -10)\)</span> is a rational function with issues when <span class="math inline">\(2x^2 = 10\)</span>, or <span class="math inline">\(x = -\sqrt{5}\)</span> or <span class="math inline">\(\sqrt{5}\)</span>.</p>
<p>Plot this function from <span class="math inline">\(-5\)</span> to <span class="math inline">\(5\)</span>. How many times does it cross the <span class="math inline">\(x\)</span> axis?</p>
<div class="cell" data-hold="true" data-execution_count="44">
<div class="cell-output cell-output-display" data-execution_count="44">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="7463908715912138032" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_7463908715912138032">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="7463908715912138032" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="7463908715912138032_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("7463908715912138032").addEventListener("change", function() {
var correct = (Math.abs(this.value - 3) <= 0.2);
var msgBox = document.getElementById('7463908715912138032_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_7463908715912138032")
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_7463908715912138032")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
</section>
<section id="question-6" class="level6">
<h6 class="anchored" data-anchor-id="question-6">Question</h6>
<p>A trash collection plan charges a flat rate of 35 dollars a month for the first 10 bags of trash and is 4 dollars a bag thereafter. Which function will model this:</p>
<div class="cell" data-hold="true" data-execution_count="45">
<div class="cell-output cell-output-display" data-execution_count="45">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="11666351460870420764" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_11666351460870420764">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_11666351460870420764_1">
<input class="form-check-input" type="radio" name="radio_11666351460870420764" id="radio_11666351460870420764_1" value="1">
<span class="label-body px-1">
<code>f(x) = x &lt;= 4 ? 35.0 : 35.0 + 10.0 * (x-4)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_11666351460870420764_2">
<input class="form-check-input" type="radio" name="radio_11666351460870420764" id="radio_11666351460870420764_2" value="2">
<span class="label-body px-1">
<code>f(x) = x &lt;= 10 ? 35.0 : 35.0 + 4.0 * (x-10)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_11666351460870420764_3">
<input class="form-check-input" type="radio" name="radio_11666351460870420764" id="radio_11666351460870420764_3" value="3">
<span class="label-body px-1">
<code>f(x) = x &lt;= 35.0 ? 10.0 : 10.0 + 35.0 * (x-4)</code>
</span>
</label>
</div>
</div>
</div>
<div id="11666351460870420764_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_11666351460870420764"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('11666351460870420764_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_11666351460870420764")
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_11666351460870420764")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Make a plot of the model. Graphically estimate how many bags of trash will cost 55 dollars.</p>
<div class="cell" data-hold="true" data-execution_count="46">
<div class="cell-output cell-output-display" data-execution_count="46">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="1375866895540576282" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_1375866895540576282">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="1375866895540576282" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="1375866895540576282_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("1375866895540576282").addEventListener("change", function() {
var correct = (Math.abs(this.value - 15) <= 0.5);
var msgBox = document.getElementById('1375866895540576282_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_1375866895540576282")
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_1375866895540576282")
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>Plot the functions <span class="math inline">\(f(x) = \cos(x)\)</span> and <span class="math inline">\(g(x) = x\)</span>. Estimate the <span class="math inline">\(x\)</span> value of where the two graphs intersect.</p>
<div class="cell" data-hold="true" data-execution_count="47">
<div class="cell-output cell-output-display" data-execution_count="47">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="10614988919064474934" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_10614988919064474934">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="10614988919064474934" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="10614988919064474934_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("10614988919064474934").addEventListener("change", function() {
var correct = (Math.abs(this.value - 0.7390851332151607) <= 0.25);
var msgBox = document.getElementById('10614988919064474934_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_10614988919064474934")
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_10614988919064474934")
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>The fact that only a finite number of points are used in a graph can introduce artifacts. An example can appear when plotting <a href="http://en.wikipedia.org/wiki/Aliasing#Sampling_sinusoidal_functions">sinusoidal</a> functions. An example is the graph of <code>f(x) = sin(500*pi*x)</code> over <code>[0,1]</code>.</p>
<p>Make its graph using 250 evenly spaced points, as follows:</p>
<div class="sourceCode cell-code" id="cb39"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb39-1"><a href="#cb39-1" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> <span class="fu">range</span>(<span class="fl">0</span>, <span class="fl">1</span>, length<span class="op">=</span><span class="fl">250</span>)</span>
<span id="cb39-2"><a href="#cb39-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x) <span class="op">=</span> <span class="fu">sin</span>(<span class="fl">500</span><span class="op">*</span><span class="cn">pi</span><span class="op">*</span>x)</span>
<span id="cb39-3"><a href="#cb39-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(xs, <span class="fu">f</span>.(xs))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>What is seen?</p>
<div class="cell" data-hold="true" data-execution_count="49">
<div class="cell-output cell-output-display" data-execution_count="48">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="17158485534582785607" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_17158485534582785607">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_17158485534582785607_1">
<input class="form-check-input" type="radio" name="radio_17158485534582785607" id="radio_17158485534582785607_1" value="1">
<span class="label-body px-1">
Oddly, it looks exactly like the graph of \(f(x) = \sin(2\pi x)\).
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_17158485534582785607_2">
<input class="form-check-input" type="radio" name="radio_17158485534582785607" id="radio_17158485534582785607_2" value="2">
<span class="label-body px-1">
It oscillates wildly, as the period is \(T=2\pi/(500 \pi)\) so there are 250 oscillations.
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_17158485534582785607_3">
<input class="form-check-input" type="radio" name="radio_17158485534582785607" id="radio_17158485534582785607_3" value="3">
<span class="label-body px-1">
It should oscillate evenly, but instead doesn't oscillate very much near 0 and 1
</span>
</label>
</div>
</div>
</div>
<div id="17158485534582785607_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_17158485534582785607"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('17158485534582785607_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_17158485534582785607")
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_17158485534582785607")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>The algorithm to plot a function works to avoid aliasing issues. Does the graph generated by <code>plot(f, 0, 1)</code> look the same, as the one above?</p>
<div class="cell" data-hold="true" data-execution_count="50">
<div class="cell-output cell-output-display" data-execution_count="49">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="4473843244109144942" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_4473843244109144942">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_4473843244109144942_1">
<input class="form-check-input" type="radio" name="radio_4473843244109144942" id="radio_4473843244109144942_1" value="1">
<span class="label-body px-1">
No, but is still looks pretty bad, as fitting 250 periods into a too small number of pixels is a problem.
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4473843244109144942_2">
<input class="form-check-input" type="radio" name="radio_4473843244109144942" id="radio_4473843244109144942_2" value="2">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4473843244109144942_3">
<input class="form-check-input" type="radio" name="radio_4473843244109144942" id="radio_4473843244109144942_3" value="3">
<span class="label-body px-1">
No, the graph shows clearly all 250 periods.
</span>
</label>
</div>
</div>
</div>
<div id="4473843244109144942_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_4473843244109144942"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('4473843244109144942_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_4473843244109144942")
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_4473843244109144942")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-9" class="level6">
<h6 class="anchored" data-anchor-id="question-9">Question</h6>
<p>Make this parametric plot for the specific values of the parameters <code>k</code> and <code>l</code>. What shape best describes it?</p>
<div class="sourceCode cell-code" id="cb40"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb40-1"><a href="#cb40-1" aria-hidden="true" tabindex="-1"></a>R, r, rho <span class="op">=</span> <span class="fl">1</span>, <span class="fl">3</span><span class="op">/</span><span class="fl">4</span>, <span class="fl">1</span><span class="op">/</span><span class="fl">4</span></span>
<span id="cb40-2"><a href="#cb40-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(t) <span class="op">=</span> (R<span class="op">-</span>r) <span class="op">*</span> <span class="fu">cos</span>(t) <span class="op">+</span> rho <span class="op">*</span> <span class="fu">cos</span>((R<span class="op">-</span>r)<span class="op">/</span>r <span class="op">*</span> t)</span>
<span id="cb40-3"><a href="#cb40-3" aria-hidden="true" tabindex="-1"></a><span class="fu">g</span>(t) <span class="op">=</span> (R<span class="op">-</span>r) <span class="op">*</span> <span class="fu">sin</span>(t) <span class="op">-</span> rho <span class="op">*</span> <span class="fu">sin</span>((R<span class="op">-</span>r)<span class="op">/</span>r <span class="op">*</span> t)</span>
<span id="cb40-4"><a href="#cb40-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-5"><a href="#cb40-5" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(f, g, <span class="fl">0</span>, <span class="fu">max</span>((R<span class="op">-</span>r)<span class="op">/</span>r, r<span class="op">/</span>(R<span class="op">-</span>r))<span class="op">*</span><span class="fl">2</span>pi, aspect_ratio<span class="op">=:</span>equal)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell" data-hold="true" data-execution_count="52">
<div class="cell-output cell-output-display" data-execution_count="50">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="1736480731978382837" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_1736480731978382837">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_1736480731978382837_1">
<input class="form-check-input" type="radio" name="radio_1736480731978382837" id="radio_1736480731978382837_1" value="1">
<span class="label-body px-1">
Four sharp points, like a star
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1736480731978382837_2">
<input class="form-check-input" type="radio" name="radio_1736480731978382837" id="radio_1736480731978382837_2" value="2">
<span class="label-body px-1">
Four petals, like a flower
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1736480731978382837_3">
<input class="form-check-input" type="radio" name="radio_1736480731978382837" id="radio_1736480731978382837_3" value="3">
<span class="label-body px-1">
An ellipse
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1736480731978382837_4">
<input class="form-check-input" type="radio" name="radio_1736480731978382837" id="radio_1736480731978382837_4" value="4">
<span class="label-body px-1">
A straight line
</span>
</label>
</div>
</div>
</div>
<div id="1736480731978382837_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_1736480731978382837"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('1736480731978382837_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_1736480731978382837")
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_1736480731978382837")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-10" class="level6">
<h6 class="anchored" data-anchor-id="question-10">Question</h6>
<p>For these next questions, we use this function:</p>
<div class="cell" data-execution_count="53">
<div class="sourceCode cell-code" id="cb41"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb41-1"><a href="#cb41-1" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span> <span class="fu">spirograph</span>(R, r, rho)</span>
<span id="cb41-2"><a href="#cb41-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">f</span>(t) <span class="op">=</span> (R<span class="op">-</span>r) <span class="op">*</span> <span class="fu">cos</span>(t) <span class="op">+</span> rho <span class="op">*</span> <span class="fu">cos</span>((R<span class="op">-</span>r)<span class="op">/</span>r <span class="op">*</span> t)</span>
<span id="cb41-3"><a href="#cb41-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">g</span>(t) <span class="op">=</span> (R<span class="op">-</span>r) <span class="op">*</span> <span class="fu">sin</span>(t) <span class="op">-</span> rho <span class="op">*</span> <span class="fu">sin</span>((R<span class="op">-</span>r)<span class="op">/</span>r <span class="op">*</span> t)</span>
<span id="cb41-4"><a href="#cb41-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb41-5"><a href="#cb41-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">plot</span>(f, g, <span class="fl">0</span>, <span class="fu">max</span>((R<span class="op">-</span>r)<span class="op">/</span>r, r<span class="op">/</span>(R<span class="op">-</span>r))<span class="op">*</span><span class="fl">2</span>pi, aspect_ratio<span class="op">=:</span>equal)</span>
<span id="cb41-6"><a href="#cb41-6" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="51">
<pre><code>spirograph (generic function with 1 method)</code></pre>
</div>
</div>
<p>Make this plot for the following specific values of the parameters <code>R</code>, <code>r</code>, and <code>rho</code>. What shape best describes it?</p>
<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>R, r, rho <span class="op">=</span> <span class="fl">1</span>, <span class="fl">3</span><span class="op">/</span><span class="fl">4</span>, <span class="fl">1</span><span class="op">/</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" data-hold="true" data-execution_count="55">
<div class="cell-output cell-output-display" data-execution_count="52">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="14496352095564740731" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_14496352095564740731">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_14496352095564740731_1">
<input class="form-check-input" type="radio" name="radio_14496352095564740731" id="radio_14496352095564740731_1" value="1">
<span class="label-body px-1">
Four sharp points, like a star
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14496352095564740731_2">
<input class="form-check-input" type="radio" name="radio_14496352095564740731" id="radio_14496352095564740731_2" value="2">
<span class="label-body px-1">
Four petals, like a flower
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14496352095564740731_3">
<input class="form-check-input" type="radio" name="radio_14496352095564740731" id="radio_14496352095564740731_3" value="3">
<span class="label-body px-1">
An ellipse
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14496352095564740731_4">
<input class="form-check-input" type="radio" name="radio_14496352095564740731" id="radio_14496352095564740731_4" value="4">
<span class="label-body px-1">
A straight line
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14496352095564740731_5">
<input class="form-check-input" type="radio" name="radio_14496352095564740731" id="radio_14496352095564740731_5" value="5">
<span class="label-body px-1">
None of the above
</span>
</label>
</div>
</div>
</div>
<div id="14496352095564740731_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_14496352095564740731"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('14496352095564740731_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_14496352095564740731")
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_14496352095564740731")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Make this plot for the following specific values of the parameters <code>R</code>, <code>r</code>, and <code>rho</code>. What shape best describes it?</p>
<div class="sourceCode cell-code" id="cb44"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb44-1"><a href="#cb44-1" aria-hidden="true" tabindex="-1"></a>R, r, rho <span class="op">=</span> <span class="fl">1</span>, <span class="fl">1</span><span class="op">/</span><span class="fl">2</span>, <span class="fl">1</span><span class="op">/</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" data-hold="true" data-execution_count="57">
<div class="cell-output cell-output-display" data-execution_count="53">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="3052234064994092459" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_3052234064994092459">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_3052234064994092459_1">
<input class="form-check-input" type="radio" name="radio_3052234064994092459" id="radio_3052234064994092459_1" value="1">
<span class="label-body px-1">
Four sharp points, like a star
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_3052234064994092459_2">
<input class="form-check-input" type="radio" name="radio_3052234064994092459" id="radio_3052234064994092459_2" value="2">
<span class="label-body px-1">
Four petals, like a flower
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_3052234064994092459_3">
<input class="form-check-input" type="radio" name="radio_3052234064994092459" id="radio_3052234064994092459_3" value="3">
<span class="label-body px-1">
An ellipse
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_3052234064994092459_4">
<input class="form-check-input" type="radio" name="radio_3052234064994092459" id="radio_3052234064994092459_4" value="4">
<span class="label-body px-1">
A straight line
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_3052234064994092459_5">
<input class="form-check-input" type="radio" name="radio_3052234064994092459" id="radio_3052234064994092459_5" value="5">
<span class="label-body px-1">
None of the above
</span>
</label>
</div>
</div>
</div>
<div id="3052234064994092459_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_3052234064994092459"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('3052234064994092459_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_3052234064994092459")
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_3052234064994092459")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Make this plot for the specific values of the parameters <code>R</code>, <code>r</code>, and <code>rho</code>. What shape best describes it?</p>
<div class="sourceCode cell-code" id="cb45"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb45-1"><a href="#cb45-1" aria-hidden="true" tabindex="-1"></a>R, r, rho <span class="op">=</span> <span class="fl">1</span>, <span class="fl">1</span><span class="op">/</span><span class="fl">4</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" data-hold="true" data-execution_count="59">
<div class="cell-output cell-output-display" data-execution_count="54">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12218772737755876173" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_12218772737755876173">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_12218772737755876173_1">
<input class="form-check-input" type="radio" name="radio_12218772737755876173" id="radio_12218772737755876173_1" value="1">
<span class="label-body px-1">
Four sharp points, like a star
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12218772737755876173_2">
<input class="form-check-input" type="radio" name="radio_12218772737755876173" id="radio_12218772737755876173_2" value="2">
<span class="label-body px-1">
Four petals, like a flower
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12218772737755876173_3">
<input class="form-check-input" type="radio" name="radio_12218772737755876173" id="radio_12218772737755876173_3" value="3">
<span class="label-body px-1">
A circle
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12218772737755876173_4">
<input class="form-check-input" type="radio" name="radio_12218772737755876173" id="radio_12218772737755876173_4" value="4">
<span class="label-body px-1">
A straight line
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12218772737755876173_5">
<input class="form-check-input" type="radio" name="radio_12218772737755876173" id="radio_12218772737755876173_5" value="5">
<span class="label-body px-1">
None of the above
</span>
</label>
</div>
</div>
</div>
<div id="12218772737755876173_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_12218772737755876173"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('12218772737755876173_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_12218772737755876173")
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_12218772737755876173")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Make this plot for the specific values of the parameters <code>R</code>, <code>r</code>, and <code>rho</code>. What shape best describes it?</p>
<div class="sourceCode cell-code" id="cb46"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb46-1"><a href="#cb46-1" aria-hidden="true" tabindex="-1"></a>R, r, rho <span class="op">=</span> <span class="fl">1</span>, <span class="fl">1</span><span class="op">/</span><span class="fl">8</span>, <span class="fl">1</span><span class="op">/</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" data-hold="true" data-execution_count="61">
<div class="cell-output cell-output-display" data-execution_count="55">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="9099351115090702708" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_9099351115090702708">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_9099351115090702708_1">
<input class="form-check-input" type="radio" name="radio_9099351115090702708" id="radio_9099351115090702708_1" value="1">
<span class="label-body px-1">
Four sharp points, like a star
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_9099351115090702708_2">
<input class="form-check-input" type="radio" name="radio_9099351115090702708" id="radio_9099351115090702708_2" value="2">
<span class="label-body px-1">
Four petals, like a flower
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_9099351115090702708_3">
<input class="form-check-input" type="radio" name="radio_9099351115090702708" id="radio_9099351115090702708_3" value="3">
<span class="label-body px-1">
A circle
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_9099351115090702708_4">
<input class="form-check-input" type="radio" name="radio_9099351115090702708" id="radio_9099351115090702708_4" value="4">
<span class="label-body px-1">
A straight line
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_9099351115090702708_5">
<input class="form-check-input" type="radio" name="radio_9099351115090702708" id="radio_9099351115090702708_5" value="5">
<span class="label-body px-1">
None of the above
</span>
</label>
</div>
</div>
</div>
<div id="9099351115090702708_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_9099351115090702708"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 5;
var msgBox = document.getElementById('9099351115090702708_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_9099351115090702708")
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_9099351115090702708")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<hr>
</section>
</section>
<section id="technical-note" class="level2" data-number="8.7">
<h2 data-number="8.7" class="anchored" data-anchor-id="technical-note"><span class="header-section-number">8.7</span> Technical note</h2>
<p>The slow “time to first plot” in <code>Julia</code> is a well-known hiccup that is related to how <code>Julia</code> can be so fast. Loading Plots and the making the first plot are both somewhat time consuming, though the second and subsequent plots are speedy. Why?</p>
<p><code>Julia</code> is an interactive language that attains its speed by compiling functions on the fly using the <a href="llvm.org">llvm</a> compiler. When <code>Julia</code> encounters a new combination of a function method and argument types it will compile and cache a function for subsequent speedy execution. The first plot is slow, as there are many internal functions that get compiled. This has sped up of late, as excessive recompilations have been trimmed down, but still has a way to go. This is different from “precompilation” which also helps trim down time for initial executions. There are also some more technically challenging means to create <code>Julia</code> images for faster start up that can be pursued if needed.</p>
</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/functions.html" class="pagination-link">
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">7</span>&nbsp; <span class="chapter-title">Functions</span></span>
</a>
</div>
<div class="nav-page nav-page-next">
<a href="../precalc/transformations.html" class="pagination-link">
<span class="nav-page-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Function manipulations</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>