2486 lines
129 KiB
HTML
2486 lines
129 KiB
HTML
<!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 - 6 Ranges and Sets</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/functions.html" rel="next">
|
||
<link href="../precalc/vectors.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">6</span> <span class="chapter-title">Ranges and Sets</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> <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> <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> <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> <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> <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 active"><span class="chapter-number">6</span> <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> <span class="chapter-title">Functions</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">8</span> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <span class="chapter-title">Newton’s 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> <span class="chapter-title">Derivative-free alternatives to Newton’s 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> <span class="chapter-title">L’Hospital’s 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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <span class="chapter-title">Euler’s 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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <span class="chapter-title">Green’s 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> <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> <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> <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> <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> <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> <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> <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> <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="#arithmetic-sequences" id="toc-arithmetic-sequences" class="nav-link active" data-scroll-target="#arithmetic-sequences"> <span class="header-section-number">6.1</span> Arithmetic sequences</a>
|
||
<ul class="collapse">
|
||
<li><a href="#the-colon-operator" id="toc-the-colon-operator" class="nav-link" data-scroll-target="#the-colon-operator"> <span class="header-section-number">6.1.1</span> The colon operator</a></li>
|
||
<li><a href="#the-range-function" id="toc-the-range-function" class="nav-link" data-scroll-target="#the-range-function"> <span class="header-section-number">6.1.2</span> The range function</a></li>
|
||
</ul></li>
|
||
<li><a href="#modifying-sequences" id="toc-modifying-sequences" class="nav-link" data-scroll-target="#modifying-sequences"> <span class="header-section-number">6.2</span> Modifying sequences</a>
|
||
<ul class="collapse">
|
||
<li><a href="#filtering" id="toc-filtering" class="nav-link" data-scroll-target="#filtering"> <span class="header-section-number">6.2.1</span> Filtering</a></li>
|
||
<li><a href="#comprehensions" id="toc-comprehensions" class="nav-link" data-scroll-target="#comprehensions"> <span class="header-section-number">6.2.2</span> Comprehensions</a></li>
|
||
<li><a href="#generators" id="toc-generators" class="nav-link" data-scroll-target="#generators"> <span class="header-section-number">6.2.3</span> Generators</a></li>
|
||
<li><a href="#filtering-generated-expressions" id="toc-filtering-generated-expressions" class="nav-link" data-scroll-target="#filtering-generated-expressions"> <span class="header-section-number">6.2.4</span> Filtering generated expressions</a></li>
|
||
</ul></li>
|
||
<li><a href="#random-numbers" id="toc-random-numbers" class="nav-link" data-scroll-target="#random-numbers"> <span class="header-section-number">6.3</span> Random numbers</a></li>
|
||
<li><a href="#questions" id="toc-questions" class="nav-link" data-scroll-target="#questions"> <span class="header-section-number">6.4</span> Questions</a></li>
|
||
</ul>
|
||
<div class="toc-actions"><div><i class="bi bi-github"></i></div><div class="action-links"><p><a href="https://github.com/jverzani/CalculusWithJuliaNotes.jl/edit/main/quarto/precalc/ranges.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">6</span> <span class="chapter-title">Ranges and Sets</span></h1>
|
||
</div>
|
||
|
||
|
||
|
||
<div class="quarto-title-meta">
|
||
|
||
|
||
|
||
</div>
|
||
|
||
|
||
</header>
|
||
|
||
<section id="arithmetic-sequences" class="level2" data-number="6.1">
|
||
<h2 data-number="6.1" class="anchored" data-anchor-id="arithmetic-sequences"><span class="header-section-number">6.1</span> Arithmetic sequences</h2>
|
||
<p>Sequences of numbers are prevalent in math. A simple one is just counting by ones:</p>
|
||
<p><span class="math display">\[
|
||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, \dots
|
||
\]</span></p>
|
||
<p>Or counting by sevens:</p>
|
||
<p><span class="math display">\[
|
||
7, 14, 21, 28, 35, 42, 49, \dots
|
||
\]</span></p>
|
||
<p>More challenging for humans is <a href="http://www.psychpage.com/learning/library/assess/mse.htm">counting backwards</a> by 7:</p>
|
||
<p><span class="math display">\[
|
||
100, 93, 86, 79, \dots
|
||
\]</span></p>
|
||
<p>These are examples of <a href="http://en.wikipedia.org/wiki/Arithmetic_progression">arithmetic sequences</a>. The form of the first <span class="math inline">\(n+1\)</span> terms in such a sequence is:</p>
|
||
<p><span class="math display">\[
|
||
a_0, a_0 + h, a_0 + 2h, a_0 + 3h, \dots, a_0 + nh
|
||
\]</span></p>
|
||
<p>The formula for the <span class="math inline">\(a_n\)</span>th term can be written in terms of <span class="math inline">\(a_0\)</span>, or any other <span class="math inline">\(0 \leq m \leq n\)</span> with <span class="math inline">\(a_n = a_m + (n-m)\cdot h\)</span>.</p>
|
||
<p>A typical question might be: The first term of an arithmetic sequence is equal to <span class="math inline">\(200\)</span> and the common difference is equal to <span class="math inline">\(-10\)</span>. Find the value of <span class="math inline">\(a_{20}\)</span>. We could find this using <span class="math inline">\(a_n = a_0 + n\cdot h\)</span>:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="3">
|
||
<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>a0, h, n <span class="op">=</span> <span class="fl">200</span>, <span class="op">-</span><span class="fl">10</span>, <span class="fl">20</span></span>
|
||
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>a0 <span class="op">+</span> n <span class="op">*</span> h</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="4">
|
||
<pre><code>0</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>More complicated questions involve an unknown first value, as with: an arithmetic sequence has a common difference equal to <span class="math inline">\(10\)</span> and its <span class="math inline">\(6\)</span>th term is equal to <span class="math inline">\(52\)</span>. Find its <span class="math inline">\(15\)</span>th term, <span class="math inline">\(a_{15}\)</span>. Here we have to answer: <span class="math inline">\(a_0 + 15 \cdot 10\)</span>. Either we could find <span class="math inline">\(a_0\)</span> (using <span class="math inline">\(52 = a_0 + 6\cdot(10)\)</span>) or use the above formula</p>
|
||
<div class="cell" data-hold="true" data-execution_count="4">
|
||
<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>a6, h, m, n <span class="op">=</span> <span class="fl">52</span>, <span class="fl">10</span>, <span class="fl">6</span>, <span class="fl">15</span></span>
|
||
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a>a15 <span class="op">=</span> a6 <span class="op">+</span> (n<span class="op">-</span>m)<span class="op">*</span>h</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="5">
|
||
<pre><code>142</code></pre>
|
||
</div>
|
||
</div>
|
||
<section id="the-colon-operator" class="level3" data-number="6.1.1">
|
||
<h3 data-number="6.1.1" class="anchored" data-anchor-id="the-colon-operator"><span class="header-section-number">6.1.1</span> The colon operator</h3>
|
||
<p>Rather than express sequences by the <span class="math inline">\(a_0\)</span>, <span class="math inline">\(h\)</span>, and <span class="math inline">\(n\)</span>, <code>Julia</code> uses the starting point (<code>a</code>), the difference (<code>h</code>) and a <em>suggested</em> stopping value (<code>b</code>). That is, we need three values to specify these ranges of numbers: a <code>start</code>, a <code>step</code>, and an <code>endof</code>. <code>Julia</code> gives a convenient syntax for this: <code>a:h:b</code>. When the difference is just <span class="math inline">\(1\)</span>, all numbers between the start and end are specified by <code>a:b</code>, as in</p>
|
||
<div class="cell" data-execution_count="5">
|
||
<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="fl">1</span><span class="op">:</span><span class="fl">10</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="6">
|
||
<pre><code>1:10</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>But wait, nothing different printed? This is because <code>1:10</code> is efficiently stored. Basically, a recipe to generate the next number from the previous number is created and <code>1:10</code> just stores the start and end point and that recipe is used to generate the set of all values. To expand the values, you have to ask for them to be <code>collect</code>ed (though this typically isn’t needed in practice):</p>
|
||
<div class="cell" data-execution_count="6">
|
||
<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">collect</span>(<span class="fl">1</span><span class="op">:</span><span class="fl">10</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="7">
|
||
<pre><code>10-element Vector{Int64}:
|
||
1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
8
|
||
9
|
||
10</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>When a non-default step size is needed, it goes in the middle, as in <code>a:h:b</code>. For example, counting by sevens from <span class="math inline">\(1\)</span> to <span class="math inline">\(50\)</span> is achieved by:</p>
|
||
<div class="cell" data-execution_count="7">
|
||
<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">collect</span>(<span class="fl">1</span><span class="op">:</span><span class="fl">7</span><span class="op">:</span><span class="fl">50</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="8">
|
||
<pre><code>8-element Vector{Int64}:
|
||
1
|
||
8
|
||
15
|
||
22
|
||
29
|
||
36
|
||
43
|
||
50</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Or counting down from 100:</p>
|
||
<div class="cell" data-execution_count="8">
|
||
<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">collect</span>(<span class="fl">100</span><span class="op">:-</span><span class="fl">7</span><span class="op">:</span><span class="fl">1</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="9">
|
||
<pre><code>15-element Vector{Int64}:
|
||
100
|
||
93
|
||
86
|
||
79
|
||
72
|
||
65
|
||
58
|
||
51
|
||
44
|
||
37
|
||
30
|
||
23
|
||
16
|
||
9
|
||
2</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>In this last example, we said end with <span class="math inline">\(1\)</span>, but it ended with <span class="math inline">\(2\)</span>. The ending value in the range is a suggestion to go up to, but not exceed. Negative values for <code>h</code> are used to make decreasing sequences.</p>
|
||
</section>
|
||
<section id="the-range-function" class="level3" data-number="6.1.2">
|
||
<h3 data-number="6.1.2" class="anchored" data-anchor-id="the-range-function"><span class="header-section-number">6.1.2</span> The range function</h3>
|
||
<p>For generating points to make graphs, a natural set of points to specify is <span class="math inline">\(n\)</span> evenly spaced points between <span class="math inline">\(a\)</span> and <span class="math inline">\(b\)</span>. We can mimic creating this set with the range operation by solving for the correct step size. We have <span class="math inline">\(a_0=a\)</span> and <span class="math inline">\(a_0 + (n-1) \cdot h = b\)</span>. (Why <span class="math inline">\(n-1\)</span> and not <span class="math inline">\(n\)</span>?) Solving yields <span class="math inline">\(h = (b-a)/(n-1)\)</span>. To be concrete we might ask for <span class="math inline">\(9\)</span> points between <span class="math inline">\(-1\)</span> and <span class="math inline">\(1\)</span>:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="9">
|
||
<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>a, b, n <span class="op">=</span> <span class="op">-</span><span class="fl">1</span>, <span class="fl">1</span>, <span class="fl">9</span></span>
|
||
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a>h <span class="op">=</span> (b<span class="op">-</span>a)<span class="op">/</span>(n<span class="op">-</span><span class="fl">1</span>)</span>
|
||
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a><span class="fu">collect</span>(a<span class="op">:</span>h<span class="op">:</span>b)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="10">
|
||
<pre><code>9-element Vector{Float64}:
|
||
-1.0
|
||
-0.75
|
||
-0.5
|
||
-0.25
|
||
0.0
|
||
0.25
|
||
0.5
|
||
0.75
|
||
1.0</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Pretty neat. If we were doing this many times - such as once per plot - we’d want to encapsulate this into a function, for example:</p>
|
||
<div class="cell" data-execution_count="10">
|
||
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span> <span class="fu">evenly_spaced</span>(a, b, n)</span>
|
||
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a> h <span class="op">=</span> (b<span class="op">-</span>a)<span class="op">/</span>(n<span class="op">-</span><span class="fl">1</span>)</span>
|
||
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">collect</span>(a<span class="op">:</span>h<span class="op">:</span>b)</span>
|
||
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="11">
|
||
<pre><code>evenly_spaced (generic function with 1 method)</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Great, let’s try it out:</p>
|
||
<div class="cell" data-execution_count="11">
|
||
<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">evenly_spaced</span>(<span class="fl">0</span>, <span class="fl">2</span>pi, <span class="fl">5</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="12">
|
||
<pre><code>5-element Vector{Float64}:
|
||
0.0
|
||
1.5707963267948966
|
||
3.141592653589793
|
||
4.71238898038469
|
||
6.283185307179586</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Now, our implementation was straightforward, but only because it avoids somethings. Look at something simple:</p>
|
||
<div class="cell" data-execution_count="12">
|
||
<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">evenly_spaced</span>(<span class="fl">1</span><span class="op">/</span><span class="fl">5</span>, <span class="fl">3</span><span class="op">/</span><span class="fl">5</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="13">
|
||
<pre><code>3-element Vector{Float64}:
|
||
0.2
|
||
0.4
|
||
0.6</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>It seems to work as expected. But looking just at the algorithm it isn’t quite so clear:</p>
|
||
<div class="cell" data-execution_count="13">
|
||
<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="fl">1</span><span class="op">/</span><span class="fl">5</span> <span class="op">+</span> <span class="fl">2</span><span class="op">*</span><span class="fl">1</span><span class="op">/</span><span class="fl">5</span> <span class="co"># last value</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>0.6000000000000001</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Floating point roundoff leads to the last value <em>exceeding</em> <code>0.6</code>, so should it be included? Well, here it is pretty clear it <em>should</em> be, but better to have something programmed that hits both <code>a</code> and <code>b</code> and adjusts <code>h</code> accordingly.</p>
|
||
<p>Enter the base function <code>range</code> which solves this seemingly simple - but not really - task. It can use <code>a</code>, <code>b</code>, and <code>n</code>. Like the range operation, this function returns a generator which can be collected to realize the values.</p>
|
||
<p>The number of points is specified with keyword arguments, as in:</p>
|
||
<div class="cell" data-execution_count="14">
|
||
<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="fl">1</span>, <span class="fl">1</span>, length<span class="op">=</span><span class="fl">9</span>) <span class="co"># or simply range(-1, 1, 9) as of v"1.7"</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="15">
|
||
<pre><code>-1.0:0.25:1.0</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>and</p>
|
||
<div class="cell" data-execution_count="15">
|
||
<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">collect</span>(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="16">
|
||
<pre><code>9-element Vector{Float64}:
|
||
-1.0
|
||
-0.75
|
||
-0.5
|
||
-0.25
|
||
0.0
|
||
0.25
|
||
0.5
|
||
0.75
|
||
1.0</code></pre>
|
||
</div>
|
||
</div>
|
||
<div class="callout-note callout callout-style-default callout-captioned">
|
||
<div class="callout-header d-flex align-content-center">
|
||
<div class="callout-icon-container">
|
||
<i class="callout-icon"></i>
|
||
</div>
|
||
<div class="callout-caption-container flex-fill">
|
||
Note
|
||
</div>
|
||
</div>
|
||
<div class="callout-body-container callout-body">
|
||
<p>There is also the <code>LinRange(a, b, n)</code> function which can be more performant than <code>range</code>, as it doesn’t try to correct for floating point errors.</p>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</section>
|
||
<section id="modifying-sequences" class="level2" data-number="6.2">
|
||
<h2 data-number="6.2" class="anchored" data-anchor-id="modifying-sequences"><span class="header-section-number">6.2</span> Modifying sequences</h2>
|
||
<p>Now we concentrate on some more general styles to modify a sequence to produce a new sequence.</p>
|
||
<section id="filtering" class="level3" data-number="6.2.1">
|
||
<h3 data-number="6.2.1" class="anchored" data-anchor-id="filtering"><span class="header-section-number">6.2.1</span> Filtering</h3>
|
||
<p>For example, another way to get the values between <span class="math inline">\(0\)</span> and <span class="math inline">\(100\)</span> that are multiples of <span class="math inline">\(7\)</span> is to start with all <span class="math inline">\(101\)</span> values and throw out those that don’t match. To check if a number is divisible by <span class="math inline">\(7\)</span>, we could use the <code>rem</code> function. It gives the remainder upon division. Multiples of <code>7</code> match <code>rem(m, 7) == 0</code>. Checking for divisibility by seven is unusual enough there is nothing built in for that, but checking for division by <span class="math inline">\(2\)</span> is common, and for that, there is a built-in function <code>iseven</code>.</p>
|
||
<p>The act of throwing out elements of a collection based on some condition is called <em>filtering</em>. The <code>filter</code> function does this in <code>Julia</code>; the basic syntax being <code>filter(predicate_function, collection)</code>. The “<code>predicate_function</code>” is one that returns either <code>true</code> or <code>false</code>, such as <code>iseven</code>. The output of <code>filter</code> consists of the new collection of values - those where the predicate returns <code>true</code>.</p>
|
||
<p>To see it used, lets start with the numbers between <code>0</code> and <code>25</code> (inclusive) and filter out those that are even:</p>
|
||
<div class="cell" data-execution_count="16">
|
||
<div class="sourceCode cell-code" id="cb27"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a><span class="fu">filter</span>(iseven, <span class="fl">0</span><span class="op">:</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="17">
|
||
<pre><code>13-element Vector{Int64}:
|
||
0
|
||
2
|
||
4
|
||
6
|
||
8
|
||
10
|
||
12
|
||
14
|
||
16
|
||
18
|
||
20
|
||
22
|
||
24</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>To get the numbers between <span class="math inline">\(1\)</span> and <span class="math inline">\(100\)</span> that are divisible by <span class="math inline">\(7\)</span> requires us to write a function akin to <code>iseven</code>, which isn’t hard (e.g., <code>is_seven(x) = x%7 == 0</code> or if being fancy <code>Base.Fix2(iszero∘rem, 7)</code>), but isn’t something we continue with just yet.</p>
|
||
<p>For another example, here is an inefficient way to list the prime numbers between <span class="math inline">\(100\)</span> and <span class="math inline">\(200\)</span>. This uses the <code>isprime</code> function from the <code>Primes</code> package</p>
|
||
<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="im">using</span> <span class="bu">Primes</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell" data-execution_count="18">
|
||
<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">filter</span>(isprime, <span class="fl">100</span><span class="op">:</span><span class="fl">200</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="19">
|
||
<pre><code>21-element Vector{Int64}:
|
||
101
|
||
103
|
||
107
|
||
109
|
||
113
|
||
127
|
||
131
|
||
137
|
||
139
|
||
149
|
||
151
|
||
157
|
||
163
|
||
167
|
||
173
|
||
179
|
||
181
|
||
191
|
||
193
|
||
197
|
||
199</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Illustrating <code>filter</code> at this point is mainly a motivation to illustrate that we can start with a regular set of numbers and then modify or filter them. The function takes on more value once we discuss how to write predicate functions.</p>
|
||
</section>
|
||
<section id="comprehensions" class="level3" data-number="6.2.2">
|
||
<h3 data-number="6.2.2" class="anchored" data-anchor-id="comprehensions"><span class="header-section-number">6.2.2</span> Comprehensions</h3>
|
||
<p>Let’s return to the case of the set of even numbers between <span class="math inline">\(0\)</span> and <span class="math inline">\(100\)</span>. We have many ways to describe this set:</p>
|
||
<ul>
|
||
<li>The collection of numbers <span class="math inline">\(0, 2, 4, 6 \dots, 100\)</span>, or the arithmetic sequence with step size <span class="math inline">\(2\)</span>, which is returned by <code>0:2:100</code>.</li>
|
||
<li>The numbers between <span class="math inline">\(0\)</span> and <span class="math inline">\(100\)</span> that are even, that is <code>filter(iseven, 0:100)</code>.</li>
|
||
<li>The set of numbers <span class="math inline">\(\{2k: k=0, \dots, 50\}\)</span>.</li>
|
||
</ul>
|
||
<p>While <code>Julia</code> has a special type for dealing with sets, we will use a vector for such a set. (Unlike a set, vectors can have repeated values, but as vectors are more widely used, we demonstrate them.) Vectors are described more fully in a previous section, but as a reminder, vectors are constructed using square brackets: <code>[]</code> (a special syntax for <a href="http://docs.julialang.org/en/latest/manual/arrays/#concatenation">concatenation</a>). Square brackets are used in different contexts within <code>Julia</code>, in this case we use them to create a <em>collection</em>. If we separate single values in our collection by commas (or semicolons), we will create a vector:</p>
|
||
<div class="cell" data-execution_count="19">
|
||
<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>x <span class="op">=</span> [<span class="fl">0</span>, <span class="fl">2</span>, <span class="fl">4</span>, <span class="fl">6</span>, <span class="fl">8</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="20">
|
||
<pre><code>6-element Vector{Int64}:
|
||
0
|
||
2
|
||
4
|
||
6
|
||
8
|
||
10</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>That is of course only part of the set of even numbers we want. Creating more might be tedious were we to type them all out, as above. In such cases, it is best to <em>generate</em> the values.</p>
|
||
<p>For this simple case, a range can be used, but more generally a <a href="http://julia.readthedocs.org/en/latest/manual/arrays/#comprehensions">comprehension</a> provides this ability using a construct that closely mirrors a set definition, such as <span class="math inline">\(\{2k: k=0, \dots, 50\}\)</span>. The simplest use of a comprehension takes this form (as we described in the section on vectors):</p>
|
||
<p><code>[expr for variable in collection]</code></p>
|
||
<p>The expression typically involves the variable specified after the keyword <code>for</code>. The collection can be a range, a vector, or many other items that are <em>iterable</em>. Here is how the mathematical set <span class="math inline">\(\{2k: k=0, \dots, 50\}\)</span> may be generated by a comprehension:</p>
|
||
<div class="cell" data-execution_count="20">
|
||
<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="fl">2</span>k for k <span class="kw">in</span> <span class="fl">0</span><span class="op">:</span><span class="fl">50</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="21">
|
||
<pre><code>51-element Vector{Int64}:
|
||
0
|
||
2
|
||
4
|
||
6
|
||
8
|
||
10
|
||
12
|
||
14
|
||
16
|
||
18
|
||
20
|
||
22
|
||
24
|
||
⋮
|
||
78
|
||
80
|
||
82
|
||
84
|
||
86
|
||
88
|
||
90
|
||
92
|
||
94
|
||
96
|
||
98
|
||
100</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>The expression is <code>2k</code>, the variable <code>k</code>, and the collection is the range of values, <code>0:50</code>. The syntax is basically identical to how the math expression is typically read aloud.</p>
|
||
<p>For some other examples, here is how we can create the first <span class="math inline">\(10\)</span> numbers divisible by <span class="math inline">\(7\)</span>:</p>
|
||
<div class="cell" data-execution_count="21">
|
||
<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="fl">7</span>k for k <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">10</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="22">
|
||
<pre><code>10-element Vector{Int64}:
|
||
7
|
||
14
|
||
21
|
||
28
|
||
35
|
||
42
|
||
49
|
||
56
|
||
63
|
||
70</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Here is how we can square the numbers between <span class="math inline">\(1\)</span> and <span class="math inline">\(10\)</span>:</p>
|
||
<div class="cell" data-execution_count="22">
|
||
<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>[x<span class="op">^</span><span class="fl">2</span> for x <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">10</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="23">
|
||
<pre><code>10-element Vector{Int64}:
|
||
1
|
||
4
|
||
9
|
||
16
|
||
25
|
||
36
|
||
49
|
||
64
|
||
81
|
||
100</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>To generate other progressions, such as powers of <span class="math inline">\(2\)</span>, we could do:</p>
|
||
<div class="cell" data-execution_count="23">
|
||
<div class="sourceCode cell-code" id="cb40"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb40-1"><a href="#cb40-1" aria-hidden="true" tabindex="-1"></a>[<span class="fl">2</span><span class="op">^</span>i for i <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">10</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="24">
|
||
<pre><code>10-element Vector{Int64}:
|
||
2
|
||
4
|
||
8
|
||
16
|
||
32
|
||
64
|
||
128
|
||
256
|
||
512
|
||
1024</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Here are decreasing powers of <span class="math inline">\(2\)</span>:</p>
|
||
<div class="cell" data-execution_count="24">
|
||
<div class="sourceCode cell-code" id="cb42"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb42-1"><a href="#cb42-1" aria-hidden="true" tabindex="-1"></a>[<span class="fl">1</span><span class="op">/</span><span class="fl">2</span><span class="op">^</span>i for i <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">10</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="25">
|
||
<pre><code>10-element Vector{Float64}:
|
||
0.5
|
||
0.25
|
||
0.125
|
||
0.0625
|
||
0.03125
|
||
0.015625
|
||
0.0078125
|
||
0.00390625
|
||
0.001953125
|
||
0.0009765625</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Sometimes, the comprehension does not produce the type of output that may be expected. This is related to <code>Julia</code>’s more limited abilities to infer types at the command line. If the output type is important, the extra prefix of <code>T[]</code> can be used, where <code>T</code> is the desired type. We will see that this will be needed at times with symbolic math.</p>
|
||
</section>
|
||
<section id="generators" class="level3" data-number="6.2.3">
|
||
<h3 data-number="6.2.3" class="anchored" data-anchor-id="generators"><span class="header-section-number">6.2.3</span> Generators</h3>
|
||
<p>A typical pattern would be to generate a collection of numbers and then apply a function to them. For example, here is one way to sum the powers of <span class="math inline">\(2\)</span>:</p>
|
||
<div class="cell" data-execution_count="25">
|
||
<div class="sourceCode cell-code" id="cb44"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb44-1"><a href="#cb44-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sum</span>([<span class="fl">2</span><span class="op">^</span>i for i <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">10</span>])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="26">
|
||
<pre><code>2046</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Conceptually this is easy to understand, but computationally it is a bit inefficient. The generator syntax allows this type of task to be done more efficiently. To use this syntax, we just need to drop the <code>[]</code>:</p>
|
||
<div class="cell" data-execution_count="26">
|
||
<div class="sourceCode cell-code" id="cb46"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb46-1"><a href="#cb46-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sum</span>(<span class="fl">2</span><span class="op">^</span>i <span class="cf">for</span> i <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">10</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="27">
|
||
<pre><code>2046</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>(The difference being no intermediate object is created to store the collection of all values specified by the generator.)</p>
|
||
</section>
|
||
<section id="filtering-generated-expressions" class="level3" data-number="6.2.4">
|
||
<h3 data-number="6.2.4" class="anchored" data-anchor-id="filtering-generated-expressions"><span class="header-section-number">6.2.4</span> Filtering generated expressions</h3>
|
||
<p>Both comprehensions and generators allow for filtering through the keyword <code>if</code>. The following shows <em>one</em> way to add the prime numbers in <span class="math inline">\([1,100]\)</span>:</p>
|
||
<div class="cell" data-execution_count="27">
|
||
<div class="sourceCode cell-code" id="cb48"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb48-1"><a href="#cb48-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sum</span>(p <span class="cf">for</span> p <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">100</span> <span class="cf">if</span> <span class="fu">isprime</span>(p))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="28">
|
||
<pre><code>1060</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>The value on the other side of <code>if</code> should be an expression that evaluates to either <code>true</code> or <code>false</code> for a given <code>p</code> (like a predicate function, but here specified as an expression). The value returned by <code>isprime(p)</code> is such.</p>
|
||
<p>In this example, we use the fact that <code>rem(k, 7)</code> returns the remainder found from dividing <code>k</code> by <code>7</code>, and so is <code>0</code> when <code>k</code> is a multiple of <code>7</code>:</p>
|
||
<div class="cell" data-execution_count="28">
|
||
<div class="sourceCode cell-code" id="cb50"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb50-1"><a href="#cb50-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sum</span>(k <span class="cf">for</span> k <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">100</span> <span class="cf">if</span> <span class="fu">rem</span>(k,<span class="fl">7</span>) <span class="op">==</span> <span class="fl">0</span>) <span class="co">## add multiples of 7</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="29">
|
||
<pre><code>735</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>The same <code>if</code> can be used in a comprehension. For example, this is an alternative to <code>filter</code> for identifying the numbers divisble by <code>7</code> in a range of numbers:</p>
|
||
<div class="cell" data-execution_count="29">
|
||
<div class="sourceCode cell-code" id="cb52"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb52-1"><a href="#cb52-1" aria-hidden="true" tabindex="-1"></a>[k for k <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">100</span> if <span class="fu">rem</span>(k,<span class="fl">7</span>) <span class="op">==</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">
|
||
<pre><code>14-element Vector{Int64}:
|
||
7
|
||
14
|
||
21
|
||
28
|
||
35
|
||
42
|
||
49
|
||
56
|
||
63
|
||
70
|
||
77
|
||
84
|
||
91
|
||
98</code></pre>
|
||
</div>
|
||
</div>
|
||
<section id="example-making-change" class="level4">
|
||
<h4 class="anchored" data-anchor-id="example-making-change">Example: Making change</h4>
|
||
<p>This example of Stefan Karpinski comes from a <a href="http://julialang.org/blog/2016/10/julia-0.5-highlights">blog</a> post highlighting changes to the <code>Julia</code> language with version <code>v"0.5.0"</code>, which added features to comprehensions that made this example possible.</p>
|
||
<p>First, a simple question: using pennies, nickels, dimes, and quarters how many different ways can we generate one dollar? Clearly <span class="math inline">\(100\)</span> pennies, or <span class="math inline">\(20\)</span> nickels, or <span class="math inline">\(10\)</span> dimes, or <span class="math inline">\(4\)</span> quarters will do this, so the answer is at least four, but how much more than four?</p>
|
||
<p>Well, we can use a comprehension to enumerate the possibilities. This example illustrates how comprehensions and generators can involve one or more variable for the iteration.</p>
|
||
<p>First, we either have <span class="math inline">\(0,1,2,3\)</span>, or <span class="math inline">\(4\)</span> quarters, or <span class="math inline">\(0\)</span>, <span class="math inline">\(25\)</span> cents, <span class="math inline">\(50\)</span> cents, <span class="math inline">\(75\)</span> cents, or a dollar’s worth. If we have, say, <span class="math inline">\(1\)</span> quarter, then we need to make up <span class="math inline">\(75\)</span> cents with the rest. If we had <span class="math inline">\(3\)</span> dimes, then we need to make up <span class="math inline">\(45\)</span> cents out of nickels and pennies, if we then had <span class="math inline">\(6\)</span> nickels, we know we must need <span class="math inline">\(15\)</span> pennies.</p>
|
||
<p>The following expression shows how counting this can be done through enumeration. Here <code>q</code> is the amount contributed by quarters, <code>d</code> the amount from dimes, <code>n</code> the amount from nickels, and <code>p</code> the amount from pennies. <code>q</code> ranges over <span class="math inline">\(0, 25, 50, 75, 100\)</span> or <code>0:25:100</code>, etc. If we know that the sum of quarters, dimes, nickels contributes a certain amount, then the number of pennies must round things up to <span class="math inline">\(100\)</span>.</p>
|
||
<div class="cell" data-execution_count="30">
|
||
<div class="sourceCode cell-code" id="cb54"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb54-1"><a href="#cb54-1" aria-hidden="true" tabindex="-1"></a>ways <span class="op">=</span> [(q, d, n, p) for q <span class="op">=</span> <span class="fl">0</span><span class="op">:</span><span class="fl">25</span><span class="op">:</span><span class="fl">100</span> for d <span class="op">=</span> <span class="fl">0</span><span class="op">:</span><span class="fl">10</span><span class="op">:</span>(<span class="fl">100</span> <span class="op">-</span> q) for n <span class="op">=</span> <span class="fl">0</span><span class="op">:</span><span class="fl">5</span><span class="op">:</span>(<span class="fl">100</span> <span class="op">-</span> q <span class="op">-</span> d) for p <span class="op">=</span> (<span class="fl">100</span> <span class="op">-</span> q <span class="op">-</span> d <span class="op">-</span> n)]</span>
|
||
<span id="cb54-2"><a href="#cb54-2" aria-hidden="true" tabindex="-1"></a><span class="fu">length</span>(ways)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="31">
|
||
<pre><code>242</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>We see <span class="math inline">\(242\)</span> cases, each distinct. The first <span class="math inline">\(3\)</span> are:</p>
|
||
<div class="cell" data-execution_count="31">
|
||
<div class="sourceCode cell-code" id="cb56"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb56-1"><a href="#cb56-1" aria-hidden="true" tabindex="-1"></a>ways[<span class="fl">1</span><span class="op">:</span><span class="fl">3</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="32">
|
||
<pre><code>3-element Vector{NTuple{4, Int64}}:
|
||
(0, 0, 0, 100)
|
||
(0, 0, 5, 95)
|
||
(0, 0, 10, 90)</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>The generating expression reads naturally. It introduces the use of multiple <code>for</code> statements, each subsequent one depending on the value of the previous (working left to right). Now suppose, we want to ensure that the amount in pennies is less than the amount in nickels, etc. We could use <code>filter</code> somehow to do this for our last answer, but using <code>if</code> allows for filtering while the events are generating. Here our condition is simply expressed: <code>q > d > n > p</code>:</p>
|
||
<div class="cell" data-execution_count="32">
|
||
<div class="sourceCode cell-code" id="cb58"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb58-1"><a href="#cb58-1" aria-hidden="true" tabindex="-1"></a>[(q, d, n, p) for q <span class="op">=</span> <span class="fl">0</span><span class="op">:</span><span class="fl">25</span><span class="op">:</span><span class="fl">100</span></span>
|
||
<span id="cb58-2"><a href="#cb58-2" aria-hidden="true" tabindex="-1"></a> for d <span class="op">=</span> <span class="fl">0</span><span class="op">:</span><span class="fl">10</span><span class="op">:</span>(<span class="fl">100</span> <span class="op">-</span> q)</span>
|
||
<span id="cb58-3"><a href="#cb58-3" aria-hidden="true" tabindex="-1"></a> for n <span class="op">=</span> <span class="fl">0</span><span class="op">:</span><span class="fl">5</span><span class="op">:</span>(<span class="fl">100</span> <span class="op">-</span> q <span class="op">-</span> d)</span>
|
||
<span id="cb58-4"><a href="#cb58-4" aria-hidden="true" tabindex="-1"></a> for p <span class="op">=</span> (<span class="fl">100</span> <span class="op">-</span> q <span class="op">-</span> d <span class="op">-</span> n)</span>
|
||
<span id="cb58-5"><a href="#cb58-5" aria-hidden="true" tabindex="-1"></a> if q <span class="op">></span> d <span class="op">></span> n <span class="op">></span> p]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="33">
|
||
<pre><code>4-element Vector{NTuple{4, Int64}}:
|
||
(50, 30, 15, 5)
|
||
(50, 30, 20, 0)
|
||
(50, 40, 10, 0)
|
||
(75, 20, 5, 0)</code></pre>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</section>
|
||
</section>
|
||
<section id="random-numbers" class="level2" data-number="6.3">
|
||
<h2 data-number="6.3" class="anchored" data-anchor-id="random-numbers"><span class="header-section-number">6.3</span> Random numbers</h2>
|
||
<p>We have been discussing structured sets of numbers. On the opposite end of the spectrum are random numbers. <code>Julia</code> makes them easy to generate, especially random numbers chosen uniformly from <span class="math inline">\([0,1)\)</span>.</p>
|
||
<ul>
|
||
<li>The <code>rand()</code> function returns a randomly chosen number in <span class="math inline">\([0,1)\)</span>.</li>
|
||
<li>The <code>rand(n)</code> function returns a vector of <code>n</code> randomly chosen numbers in <span class="math inline">\([0,1)\)</span>.</li>
|
||
</ul>
|
||
<p>To illustrate, this will command return a single number</p>
|
||
<div class="cell" data-execution_count="33">
|
||
<div class="sourceCode cell-code" id="cb60"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb60-1"><a href="#cb60-1" aria-hidden="true" tabindex="-1"></a><span class="fu">rand</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="34">
|
||
<pre><code>0.7091665095082278</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>If the command is run again, it is almost certain that a different value will be returned:</p>
|
||
<div class="cell" data-execution_count="34">
|
||
<div class="sourceCode cell-code" id="cb62"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb62-1"><a href="#cb62-1" aria-hidden="true" tabindex="-1"></a><span class="fu">rand</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">
|
||
<pre><code>0.49047268527669474</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>This call will return a vector of <span class="math inline">\(10\)</span> such random numbers:</p>
|
||
<div class="cell" data-execution_count="35">
|
||
<div class="sourceCode cell-code" id="cb64"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb64-1"><a href="#cb64-1" aria-hidden="true" tabindex="-1"></a><span class="fu">rand</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="36">
|
||
<pre><code>10-element Vector{Float64}:
|
||
0.9297209023460982
|
||
0.4435368429176365
|
||
0.5398096862580283
|
||
0.007172948822441794
|
||
0.95740601571626
|
||
0.36712852348390046
|
||
0.8258955993805087
|
||
0.23389908444145213
|
||
0.6865547101208402
|
||
0.8362747495470747</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>The <code>rand</code> function is easy to use. The only common source of confusion is the subtle distinction between <code>rand()</code> and <code>rand(1)</code>, as the latter is a vector of <span class="math inline">\(1\)</span> random number and the former just <span class="math inline">\(1\)</span> random number.</p>
|
||
</section>
|
||
<section id="questions" class="level2" data-number="6.4">
|
||
<h2 data-number="6.4" class="anchored" data-anchor-id="questions"><span class="header-section-number">6.4</span> Questions</h2>
|
||
<section id="question" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question">Question</h6>
|
||
<p>Which of these will produce the odd numbers between <span class="math inline">\(1\)</span> and <span class="math inline">\(99\)</span>?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="36">
|
||
<div class="cell-output cell-output-display" data-execution_count="37">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="1860220524955073279" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_1860220524955073279">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_1860220524955073279_1">
|
||
<input class="form-check-input" type="radio" name="radio_1860220524955073279" id="radio_1860220524955073279_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
<code>1:3:99</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_1860220524955073279_2">
|
||
<input class="form-check-input" type="radio" name="radio_1860220524955073279" id="radio_1860220524955073279_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
<code>1:2:99</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_1860220524955073279_3">
|
||
<input class="form-check-input" type="radio" name="radio_1860220524955073279" id="radio_1860220524955073279_3" value="3">
|
||
|
||
<span class="label-body px-1">
|
||
<code>1:99</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="1860220524955073279_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_1860220524955073279"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 2;
|
||
var msgBox = document.getElementById('1860220524955073279_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_1860220524955073279")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_1860220524955073279")
|
||
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>Which of these will create the sequence <span class="math inline">\(2, 9, 16, 23, \dots, 72\)</span>?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="37">
|
||
<div class="cell-output cell-output-display" data-execution_count="38">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="10612279827106106501" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_10612279827106106501">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_10612279827106106501_1">
|
||
<input class="form-check-input" type="radio" name="radio_10612279827106106501" id="radio_10612279827106106501_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
<code>2:72</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_10612279827106106501_2">
|
||
<input class="form-check-input" type="radio" name="radio_10612279827106106501" id="radio_10612279827106106501_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
<code>72:-7:2</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_10612279827106106501_3">
|
||
<input class="form-check-input" type="radio" name="radio_10612279827106106501" id="radio_10612279827106106501_3" value="3">
|
||
|
||
<span class="label-body px-1">
|
||
<code>2:9:72</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_10612279827106106501_4">
|
||
<input class="form-check-input" type="radio" name="radio_10612279827106106501" id="radio_10612279827106106501_4" value="4">
|
||
|
||
<span class="label-body px-1">
|
||
<code>2:7:72</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="10612279827106106501_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_10612279827106106501"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 4;
|
||
var msgBox = document.getElementById('10612279827106106501_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_10612279827106106501")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_10612279827106106501")
|
||
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>How many numbers are in the sequence produced by <code>0:19:1000</code>?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="38">
|
||
<div class="cell-output cell-output-display" data-execution_count="39">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="9184758134906783536" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_9184758134906783536">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="9184758134906783536" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="9184758134906783536_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("9184758134906783536").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 53) <= 0);
|
||
var msgBox = document.getElementById('9184758134906783536_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_9184758134906783536")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_9184758134906783536")
|
||
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>The range operation (<code>a:h:b</code>) can also be used to countdown. Which of these will do so, counting down from <code>10</code> to <code>1</code>? (You can call <code>collect</code> to visualize the generated numbers.)</p>
|
||
<div class="cell" data-hold="true" data-execution_count="39">
|
||
<div class="cell-output cell-output-display" data-execution_count="40">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12124426329116594202" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_12124426329116594202">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_12124426329116594202_1">
|
||
<input class="form-check-input" type="radio" name="radio_12124426329116594202" id="radio_12124426329116594202_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
<code>1:-1:10</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_12124426329116594202_2">
|
||
<input class="form-check-input" type="radio" name="radio_12124426329116594202" id="radio_12124426329116594202_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
<code>10:-1:1</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_12124426329116594202_3">
|
||
<input class="form-check-input" type="radio" name="radio_12124426329116594202" id="radio_12124426329116594202_3" value="3">
|
||
|
||
<span class="label-body px-1">
|
||
<code>10:1</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_12124426329116594202_4">
|
||
<input class="form-check-input" type="radio" name="radio_12124426329116594202" id="radio_12124426329116594202_4" value="4">
|
||
|
||
<span class="label-body px-1">
|
||
<code>1:10</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="12124426329116594202_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_12124426329116594202"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 2;
|
||
var msgBox = document.getElementById('12124426329116594202_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_12124426329116594202")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_12124426329116594202")
|
||
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>What is the last number generated by <code>1:4:7</code>?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="40">
|
||
<div class="cell-output cell-output-display" data-execution_count="41">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="4762807266890829046" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_4762807266890829046">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="4762807266890829046" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="4762807266890829046_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("4762807266890829046").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 5) <= 0);
|
||
var msgBox = document.getElementById('4762807266890829046_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_4762807266890829046")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_4762807266890829046")
|
||
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>While the range operation can generate vectors by collecting, do the objects themselves act like vectors?</p>
|
||
<p>Does scalar multiplication work as expected? In particular, is the result of <code>2*(1:5)</code> <em>basically</em> the same as <code>2 * [1,2,3,4,5]</code>?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="41">
|
||
<div class="cell-output cell-output-display" data-execution_count="42">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="6891489865724869347" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_6891489865724869347">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_6891489865724869347_1">
|
||
<input class="form-check-input" type="radio" name="radio_6891489865724869347" id="radio_6891489865724869347_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
Yes
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_6891489865724869347_2">
|
||
<input class="form-check-input" type="radio" name="radio_6891489865724869347" id="radio_6891489865724869347_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
No
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="6891489865724869347_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_6891489865724869347"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 1;
|
||
var msgBox = document.getElementById('6891489865724869347_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_6891489865724869347")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_6891489865724869347")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
})});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
<p>Does vector addition work? as expected? In particular, is the result of <code>(1:4) + (2:5)</code> <em>basically</em> the same as <code>[1,2,3,4]</code> + <code>[2,3,4,5]</code>?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="42">
|
||
<div class="cell-output cell-output-display" data-execution_count="43">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="3346208123249017407" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_3346208123249017407">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_3346208123249017407_1">
|
||
<input class="form-check-input" type="radio" name="radio_3346208123249017407" id="radio_3346208123249017407_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
Yes
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_3346208123249017407_2">
|
||
<input class="form-check-input" type="radio" name="radio_3346208123249017407" id="radio_3346208123249017407_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
No
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="3346208123249017407_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_3346208123249017407"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 1;
|
||
var msgBox = document.getElementById('3346208123249017407_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_3346208123249017407")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_3346208123249017407")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
})});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
<p>What if parenthese are left off? Explain the output of <code>1:4 + 2:5</code>?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="43">
|
||
<div class="cell-output cell-output-display" data-execution_count="44">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="301395141200030916" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_301395141200030916">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_301395141200030916_1">
|
||
<input class="form-check-input" type="radio" name="radio_301395141200030916" id="radio_301395141200030916_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
Addition happens prior to the use of <code>:</code> so this is like <code>1:(4+2):5</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_301395141200030916_2">
|
||
<input class="form-check-input" type="radio" name="radio_301395141200030916" id="radio_301395141200030916_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
It is just random
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_301395141200030916_3">
|
||
<input class="form-check-input" type="radio" name="radio_301395141200030916" id="radio_301395141200030916_3" value="3">
|
||
|
||
<span class="label-body px-1">
|
||
It gives the correct answer, a generator for the vector <code>[3,5,7,9]</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="301395141200030916_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_301395141200030916"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 1;
|
||
var msgBox = document.getElementById('301395141200030916_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_301395141200030916")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_301395141200030916")
|
||
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>How is <code>a:b-1</code> interpreted:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="44">
|
||
<div class="cell-output cell-output-display" data-execution_count="45">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="9227010241153630268" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_9227010241153630268">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_9227010241153630268_1">
|
||
<input class="form-check-input" type="radio" name="radio_9227010241153630268" id="radio_9227010241153630268_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
as <code>a:(b-1)</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_9227010241153630268_2">
|
||
<input class="form-check-input" type="radio" name="radio_9227010241153630268" id="radio_9227010241153630268_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
as <code>(a:b) - 1</code>, which is <code>(a-1):(b-1)</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="9227010241153630268_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_9227010241153630268"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 1;
|
||
var msgBox = document.getElementById('9227010241153630268_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_9227010241153630268")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_9227010241153630268")
|
||
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>Create the sequence <span class="math inline">\(10, 100, 1000, \dots, 1,000,000\)</span> using a list comprehension. Which of these works?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="45">
|
||
<div class="cell-output cell-output-display" data-execution_count="46">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="8474034070184718660" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_8474034070184718660">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_8474034070184718660_1">
|
||
<input class="form-check-input" type="radio" name="radio_8474034070184718660" id="radio_8474034070184718660_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
<code>[10^i for i in [10, 100, 1000]]</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_8474034070184718660_2">
|
||
<input class="form-check-input" type="radio" name="radio_8474034070184718660" id="radio_8474034070184718660_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
<code>[i^10 for i in [1:6]]</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_8474034070184718660_3">
|
||
<input class="form-check-input" type="radio" name="radio_8474034070184718660" id="radio_8474034070184718660_3" value="3">
|
||
|
||
<span class="label-body px-1">
|
||
<code>[10^i for i in 1:6]</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="8474034070184718660_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_8474034070184718660"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 3;
|
||
var msgBox = document.getElementById('8474034070184718660_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_8474034070184718660")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_8474034070184718660")
|
||
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>Create the sequence <span class="math inline">\(0.1, 0.01, 0.001, \dots, 0.0000001\)</span> using a list comprehension. Which of these will work:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="46">
|
||
<div class="cell-output cell-output-display" data-execution_count="47">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12080370024679963905" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_12080370024679963905">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_12080370024679963905_1">
|
||
<input class="form-check-input" type="radio" name="radio_12080370024679963905" id="radio_12080370024679963905_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
<code>[(1/10)^i for i in 1:7]</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_12080370024679963905_2">
|
||
<input class="form-check-input" type="radio" name="radio_12080370024679963905" id="radio_12080370024679963905_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
<code>[10^-i for i in 1:7]</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_12080370024679963905_3">
|
||
<input class="form-check-input" type="radio" name="radio_12080370024679963905" id="radio_12080370024679963905_3" value="3">
|
||
|
||
<span class="label-body px-1">
|
||
<code>[i^(1/10) for i in 1:7]</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="12080370024679963905_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_12080370024679963905"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 1;
|
||
var msgBox = document.getElementById('12080370024679963905_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_12080370024679963905")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_12080370024679963905")
|
||
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>Evaluate the expression <span class="math inline">\(x^3 - 2x + 3\)</span> for each of the values <span class="math inline">\(-5, -4, \dots, 4, 5\)</span> using a comprehension. Which of these will work?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="47">
|
||
<div class="cell-output cell-output-display" data-execution_count="48">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="16489426055535222241" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_16489426055535222241">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_16489426055535222241_1">
|
||
<input class="form-check-input" type="radio" name="radio_16489426055535222241" id="radio_16489426055535222241_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
<code>[x^3 - 2x + 3 for x in -(5:5)]</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_16489426055535222241_2">
|
||
<input class="form-check-input" type="radio" name="radio_16489426055535222241" id="radio_16489426055535222241_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
<code>[x^3 - 2x + 3 for i in -5:5]</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_16489426055535222241_3">
|
||
<input class="form-check-input" type="radio" name="radio_16489426055535222241" id="radio_16489426055535222241_3" value="3">
|
||
|
||
<span class="label-body px-1">
|
||
<code>[x^3 - 2x + 3 for x in -5:5]</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="16489426055535222241_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_16489426055535222241"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 3;
|
||
var msgBox = document.getElementById('16489426055535222241_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_16489426055535222241")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_16489426055535222241")
|
||
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>How many prime numbers are there between <span class="math inline">\(1100\)</span> and <span class="math inline">\(1200\)</span>? (Use <code>filter</code> and <code>isprime</code>)</p>
|
||
<div class="cell" data-hold="true" data-execution_count="48">
|
||
<div class="cell-output cell-output-display" data-execution_count="49">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="5798925587329152050" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_5798925587329152050">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="5798925587329152050" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="5798925587329152050_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("5798925587329152050").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 12) <= 0);
|
||
var msgBox = document.getElementById('5798925587329152050_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_5798925587329152050")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_5798925587329152050")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="question-11" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question-11">Question</h6>
|
||
<p>Which has more prime numbers the range <code>1000:2000</code> or the range <code>11000:12000</code>?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="49">
|
||
<div class="cell-output cell-output-display" data-execution_count="50">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="17496638185759880896" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_17496638185759880896">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_17496638185759880896_1">
|
||
<input class="form-check-input" type="radio" name="radio_17496638185759880896" id="radio_17496638185759880896_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
<code>1000:2000</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_17496638185759880896_2">
|
||
<input class="form-check-input" type="radio" name="radio_17496638185759880896" id="radio_17496638185759880896_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
<code>11000:12000</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="17496638185759880896_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_17496638185759880896"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 1;
|
||
var msgBox = document.getElementById('17496638185759880896_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_17496638185759880896")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_17496638185759880896")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
})});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="question-12" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question-12">Question</h6>
|
||
<p>We can easily add an arithmetic progression with the <code>sum</code> function. For example, <code>sum(1:100)</code> will add the numbers <span class="math inline">\(1, 2, ..., 100\)</span>.</p>
|
||
<p>What is the sum of the odd numbers between <span class="math inline">\(0\)</span> and <span class="math inline">\(100\)</span>?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="50">
|
||
<div class="cell-output cell-output-display" data-execution_count="51">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="3229438511826502873" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_3229438511826502873">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="3229438511826502873" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="3229438511826502873_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("3229438511826502873").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 2500) <= 0);
|
||
var msgBox = document.getElementById('3229438511826502873_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_3229438511826502873")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_3229438511826502873")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="question-13" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question-13">Question</h6>
|
||
<p>The sum of the arithmetic progression <span class="math inline">\(a, a+h, \dots, a+n\cdot h\)</span> has a simple formula. Using a few cases, can you tell if this is the correct one:</p>
|
||
<p><span class="math display">\[
|
||
(n+1)\cdot a + h \cdot n(n+1)/2
|
||
\]</span></p>
|
||
<div class="cell" data-hold="true" data-execution_count="51">
|
||
<div class="cell-output cell-output-display" data-execution_count="52">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="6481874351316140838" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_6481874351316140838">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_6481874351316140838_1">
|
||
<input class="form-check-input" type="radio" name="radio_6481874351316140838" id="radio_6481874351316140838_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
Yes, this is true
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_6481874351316140838_2">
|
||
<input class="form-check-input" type="radio" name="radio_6481874351316140838" id="radio_6481874351316140838_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
No, this is false
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="6481874351316140838_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_6481874351316140838"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 1;
|
||
var msgBox = document.getElementById('6481874351316140838_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_6481874351316140838")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_6481874351316140838")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
})});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="question-14" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question-14">Question</h6>
|
||
<p>A <em>geometric progression</em> is of the form <span class="math inline">\(a^0, a^1, a^2, \dots, a^n\)</span>. These are easily generated by comprehensions of the form <code>[a^i for i in 0:n]</code>. Find the sum of the geometric progression <span class="math inline">\(1, 2^1, 2^2, \dots, 2^{10}\)</span>.</p>
|
||
<div class="cell" data-hold="true" data-execution_count="52">
|
||
<div class="cell-output cell-output-display" data-execution_count="53">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="907814364242957004" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_907814364242957004">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="907814364242957004" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="907814364242957004_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("907814364242957004").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 2047) <= 0);
|
||
var msgBox = document.getElementById('907814364242957004_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_907814364242957004")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_907814364242957004")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
<p>Is your answer of the form <span class="math inline">\((1 - a^{n+1}) / (1-a)\)</span>?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="53">
|
||
<div class="cell-output cell-output-display" data-execution_count="54">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="9294712059613976704" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_9294712059613976704">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_9294712059613976704_1">
|
||
<input class="form-check-input" type="radio" name="radio_9294712059613976704" id="radio_9294712059613976704_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
Yes
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_9294712059613976704_2">
|
||
<input class="form-check-input" type="radio" name="radio_9294712059613976704" id="radio_9294712059613976704_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
No
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="9294712059613976704_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_9294712059613976704"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 1;
|
||
var msgBox = document.getElementById('9294712059613976704_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_9294712059613976704")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_9294712059613976704")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
})});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="question-15" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question-15">Question</h6>
|
||
<p>The <a href="http://en.wikipedia.org/wiki/Arithmetic_progression">product</a> of the terms in an arithmetic progression has a known formula. The product can be found by an expression of the form <code>prod(a:h:b)</code>. Find the product of the terms in the sequence <span class="math inline">\(1,3,5,\dots,19\)</span>.</p>
|
||
<div class="cell" data-hold="true" data-execution_count="54">
|
||
<div class="cell-output cell-output-display" data-execution_count="55">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="3390855502283116070" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_3390855502283116070">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="3390855502283116070" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="3390855502283116070_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("3390855502283116070").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 654729075) <= 0);
|
||
var msgBox = document.getElementById('3390855502283116070_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_3390855502283116070")
|
||
if (explanation != null) {
|
||
explanation.style.display = "none";
|
||
}
|
||
} else {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
||
var explanation = document.getElementById("explanation_3390855502283116070")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
</section>
|
||
</section>
|
||
|
||
</main> <!-- /main -->
|
||
<script id="quarto-html-after-body" type="application/javascript">
|
||
window.document.addEventListener("DOMContentLoaded", function (event) {
|
||
const toggleBodyColorMode = (bsSheetEl) => {
|
||
const mode = bsSheetEl.getAttribute("data-mode");
|
||
const bodyEl = window.document.querySelector("body");
|
||
if (mode === "dark") {
|
||
bodyEl.classList.add("quarto-dark");
|
||
bodyEl.classList.remove("quarto-light");
|
||
} else {
|
||
bodyEl.classList.add("quarto-light");
|
||
bodyEl.classList.remove("quarto-dark");
|
||
}
|
||
}
|
||
const toggleBodyColorPrimary = () => {
|
||
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
|
||
if (bsSheetEl) {
|
||
toggleBodyColorMode(bsSheetEl);
|
||
}
|
||
}
|
||
toggleBodyColorPrimary();
|
||
const icon = "";
|
||
const anchorJS = new window.AnchorJS();
|
||
anchorJS.options = {
|
||
placement: 'right',
|
||
icon: icon
|
||
};
|
||
anchorJS.add('.anchored');
|
||
const clipboard = new window.ClipboardJS('.code-copy-button', {
|
||
target: function(trigger) {
|
||
return trigger.previousElementSibling;
|
||
}
|
||
});
|
||
clipboard.on('success', function(e) {
|
||
// button target
|
||
const button = e.trigger;
|
||
// don't keep focus
|
||
button.blur();
|
||
// flash "checked"
|
||
button.classList.add('code-copy-button-checked');
|
||
var currentTitle = button.getAttribute("title");
|
||
button.setAttribute("title", "Copied!");
|
||
setTimeout(function() {
|
||
button.setAttribute("title", currentTitle);
|
||
button.classList.remove('code-copy-button-checked');
|
||
}, 1000);
|
||
// clear code selection
|
||
e.clearSelection();
|
||
});
|
||
function tippyHover(el, contentFn) {
|
||
const config = {
|
||
allowHTML: true,
|
||
content: contentFn,
|
||
maxWidth: 500,
|
||
delay: 100,
|
||
arrow: false,
|
||
appendTo: function(el) {
|
||
return el.parentElement;
|
||
},
|
||
interactive: true,
|
||
interactiveBorder: 10,
|
||
theme: 'quarto',
|
||
placement: 'bottom-start'
|
||
};
|
||
window.tippy(el, config);
|
||
}
|
||
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
|
||
for (var i=0; i<noterefs.length; i++) {
|
||
const ref = noterefs[i];
|
||
tippyHover(ref, function() {
|
||
let href = ref.getAttribute('href');
|
||
try { href = new URL(href).hash; } catch {}
|
||
const id = href.replace(/^#\/?/, "");
|
||
const note = window.document.getElementById(id);
|
||
return note.innerHTML;
|
||
});
|
||
}
|
||
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
|
||
for (var i=0; i<bibliorefs.length; i++) {
|
||
const ref = bibliorefs[i];
|
||
const cites = ref.parentNode.getAttribute('data-cites').split(' ');
|
||
tippyHover(ref, function() {
|
||
var popup = window.document.createElement('div');
|
||
cites.forEach(function(cite) {
|
||
var citeDiv = window.document.createElement('div');
|
||
citeDiv.classList.add('hanging-indent');
|
||
citeDiv.classList.add('csl-entry');
|
||
var biblioDiv = window.document.getElementById('ref-' + cite);
|
||
if (biblioDiv) {
|
||
citeDiv.innerHTML = biblioDiv.innerHTML;
|
||
}
|
||
popup.appendChild(citeDiv);
|
||
});
|
||
return popup.innerHTML;
|
||
});
|
||
}
|
||
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
|
||
var filterRegex = new RegExp('/' + window.location.host + '/');
|
||
var isInternal = (href) => {
|
||
return filterRegex.test(href) || localhostRegex.test(href);
|
||
}
|
||
// Inspect non-navigation links and adorn them if external
|
||
var links = window.document.querySelectorAll('a:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external)');
|
||
for (var i=0; i<links.length; i++) {
|
||
const link = links[i];
|
||
if (!isInternal(link.href)) {
|
||
// target, if specified
|
||
link.setAttribute("target", "_blank");
|
||
}
|
||
}
|
||
});
|
||
</script>
|
||
<nav class="page-navigation">
|
||
<div class="nav-page nav-page-previous">
|
||
<a href="../precalc/vectors.html" class="pagination-link">
|
||
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">5</span> <span class="chapter-title">Vectors</span></span>
|
||
</a>
|
||
</div>
|
||
<div class="nav-page nav-page-next">
|
||
<a href="../precalc/functions.html" class="pagination-link">
|
||
<span class="nav-page-text"><span class="chapter-number">7</span> <span class="chapter-title">Functions</span></span> <i class="bi bi-arrow-right-short"></i>
|
||
</a>
|
||
</div>
|
||
</nav>
|
||
</div> <!-- /content -->
|
||
<footer class="footer">
|
||
<div class="nav-footer">
|
||
<div class="nav-footer-center">Copyright 2022, John Verzani</div>
|
||
</div>
|
||
</footer>
|
||
|
||
|
||
|
||
</body></html> |