2986 lines
164 KiB
HTML
2986 lines
164 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 - 1 From calculator to computer</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/variables.html" rel="next">
|
||
<link href="../index.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">1</span> <span class="chapter-title">From calculator to computer</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 active"><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"><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="#operations" id="toc-operations" class="nav-link active" data-scroll-target="#operations"> <span class="header-section-number">1.1</span> Operations</a>
|
||
<ul class="collapse">
|
||
<li><a href="#examples" id="toc-examples" class="nav-link" data-scroll-target="#examples"> <span class="header-section-number">1.1.1</span> Examples</a></li>
|
||
</ul></li>
|
||
<li><a href="#order-of-operations" id="toc-order-of-operations" class="nav-link" data-scroll-target="#order-of-operations"> <span class="header-section-number">1.2</span> Order of operations</a>
|
||
<ul class="collapse">
|
||
<li><a href="#examples-1" id="toc-examples-1" class="nav-link" data-scroll-target="#examples-1"> <span class="header-section-number">1.2.1</span> Examples</a></li>
|
||
<li><a href="#two-ways-to-write-division---and-they-are-not-the-same" id="toc-two-ways-to-write-division---and-they-are-not-the-same" class="nav-link" data-scroll-target="#two-ways-to-write-division---and-they-are-not-the-same"> <span class="header-section-number">1.2.2</span> Two ways to write division - and they are not the same</a></li>
|
||
<li><a href="#infix-postfix-and-prefix-notation" id="toc-infix-postfix-and-prefix-notation" class="nav-link" data-scroll-target="#infix-postfix-and-prefix-notation"> <span class="header-section-number">1.2.3</span> Infix, postfix, and prefix notation</a></li>
|
||
</ul></li>
|
||
<li><a href="#constants" id="toc-constants" class="nav-link" data-scroll-target="#constants"> <span class="header-section-number">1.3</span> Constants</a>
|
||
<ul class="collapse">
|
||
<li><a href="#numeric-literals" id="toc-numeric-literals" class="nav-link" data-scroll-target="#numeric-literals"> <span class="header-section-number">1.3.1</span> Numeric literals</a></li>
|
||
</ul></li>
|
||
<li><a href="#functions" id="toc-functions" class="nav-link" data-scroll-target="#functions"> <span class="header-section-number">1.4</span> Functions</a>
|
||
<ul class="collapse">
|
||
<li><a href="#multiple-arguments" id="toc-multiple-arguments" class="nav-link" data-scroll-target="#multiple-arguments"> <span class="header-section-number">1.4.1</span> Multiple arguments</a></li>
|
||
<li><a href="#examples-2" id="toc-examples-2" class="nav-link" data-scroll-target="#examples-2"> <span class="header-section-number">1.4.2</span> Examples</a></li>
|
||
</ul></li>
|
||
<li><a href="#errors" id="toc-errors" class="nav-link" data-scroll-target="#errors"> <span class="header-section-number">1.5</span> Errors</a></li>
|
||
<li><a href="#questions" id="toc-questions" class="nav-link" data-scroll-target="#questions"> <span class="header-section-number">1.6</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/calculator.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">1</span> <span class="chapter-title">From calculator to computer</span></h1>
|
||
</div>
|
||
|
||
|
||
|
||
<div class="quarto-title-meta">
|
||
|
||
|
||
|
||
</div>
|
||
|
||
|
||
</header>
|
||
|
||
<p>Let us consider a basic calculator with buttons to add, subtract, multiply, divide, and take square roots. Using such a simple thing is certainly familiar for any reader of these notes. Indeed, a familiarity with a <em>graphing</em> calculator is expected. <code>Julia</code> makes these familiar tasks just as easy, offering numerous conveniences along the way. In this section we describe how.</p>
|
||
<p>The following image is the calculator that Google presents upon searching for “calculator.”</p>
|
||
<div class="quarto-figure quarto-figure-center">
|
||
<figure class="figure">
|
||
<p><img src="../precalc/figures/calculator.png" class="img-fluid figure-img"></p>
|
||
<p></p><figcaption class="figure-caption">Screenshot of a calculator provided by the Google search engine.</figcaption><p></p>
|
||
</figure>
|
||
</div>
|
||
<p>This calculator should have a familiar appearance with a keypad of numbers, a set of buttons for arithmetic operations, a set of buttons for some common mathematical functions, a degree/radian switch, and buttons for interacting with the calculator: <code>Ans</code>, <code>AC</code> (also <code>CE</code>), and <code>=</code>.</p>
|
||
<p>The goal here is to see the counterparts within <code>Julia</code> to these features.</p>
|
||
<hr>
|
||
<p>For an illustration of a <em>really</em> basic calculator, have some fun watching this video:</p>
|
||
<div class="cell" data-execution_count="4">
|
||
<div class="cell-output cell-output-display" data-execution_count="5">
|
||
<center>
|
||
<iframe width="560" height="315" src="https://www.youtube.com/embed/sxLdGjV-_yg" frameborder="0" allowfullscreen="">
|
||
</iframe>
|
||
</center>
|
||
</div>
|
||
</div>
|
||
<section id="operations" class="level2" data-number="1.1">
|
||
<h2 data-number="1.1" class="anchored" data-anchor-id="operations"><span class="header-section-number">1.1</span> Operations</h2>
|
||
<p>Performing a simple computation on the calculator typically involves hitting buttons in a sequence, such as “<code>1</code>”, “<code>+</code>”, “<code>2</code>”, “<code>=</code>” to compute <code>3</code> from adding <code>1 + 2</code>. In <code>Julia</code>, the process is not so different. Instead of pressing buttons, the various values are typed in. So, we would have:</p>
|
||
<div class="cell" data-execution_count="5">
|
||
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fl">1</span> <span class="op">+</span> <span class="fl">2</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="6">
|
||
<pre><code>3</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Sending an expression to <code>Julia</code>’s interpreter - the equivalent of pressing the “<code>=</code>” key on a calculator - is done at the command line by pressing the <code>Enter</code> or <code>Return</code> key, and in <code>Pluto</code>, also using the “play” icon, or the keyboard shortcut <code>Shift-Enter</code>. If the current expression is complete, then <code>Julia</code> evaluates it and shows any output. If the expression is not complete, <code>Julia</code>’s response depends on how it is being called. Within <code>Pluto</code>, a message about “<code>premature end of input</code>” is given. If the expression raises an error, this will be noted.</p>
|
||
<p>The basic arithmetic operations on a calculator are “+”, “-”, “×”, “÷”, and “<span class="math inline">\(xʸ\)</span>”. These have parallels in <code>Julia</code> through the <em>binary</em> operators: <code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>, and <code>^</code>:</p>
|
||
<div class="cell" data-execution_count="6">
|
||
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fl">1</span> <span class="op">+</span> <span class="fl">2</span>, <span class="fl">2</span> <span class="op">-</span> <span class="fl">3</span>, <span class="fl">3</span> <span class="op">*</span> <span class="fl">4</span>, <span class="fl">4</span> <span class="op">/</span> <span class="fl">5</span>, <span class="fl">5</span> <span class="op">^</span> <span class="fl">6</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="7">
|
||
<pre><code>(3, -1, 12, 0.8, 15625)</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>On some calculators, there is a distinction between minus signs - the binary minus sign and the unary minus sign to create values such as <span class="math inline">\(-1\)</span>.</p>
|
||
<p>In <code>Julia</code>, the same symbol, “<code>-</code>”, is used for each:</p>
|
||
<div class="cell" data-execution_count="7">
|
||
<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="op">-</span><span class="fl">1</span> <span class="op">-</span> <span class="fl">2</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="8">
|
||
<pre><code>-3</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>An expression like <span class="math inline">\(6 - -3\)</span>, subtracting minus three from six, must be handled with some care. With the Google calculator, the expression must be entered with accompanying parentheses: <span class="math inline">\(6 -(-3)\)</span>. In <code>Julia</code>, parentheses may be used, but are not needed. However, if omitted, a space is required between the two minus signs:</p>
|
||
<div class="cell" data-execution_count="8">
|
||
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="fl">6</span> <span class="op">-</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="9">
|
||
<pre><code>9</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>(If no space is included, the value “<code>--</code>” is parsed like a different, undefined, operation.)</p>
|
||
<div class="cell" data-execution_count="9">
|
||
<div class="cell-output cell-output-display" data-execution_count="10">
|
||
<div class="markdown"><div class="admonition warning"><p class="admonition-title">Warning</p><p><code>Julia</code> only uses one symbol for minus, but web pages may not! Copying and pasting an expression with a minus sign can lead to hard to understand errors such as: <code>invalid character "−"</code>. There are several Unicode symbols that look similar to the ASCII minus sign, but are different. These notes use a different character for the minus sign for the typeset math (e.g., \(1 - \pi\)) than for the code within cells (e.g. <code>1 - 2</code>). Thus, copying and pasting the typeset math may not work as expected.</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<section id="examples" class="level3" data-number="1.1.1">
|
||
<h3 data-number="1.1.1" class="anchored" data-anchor-id="examples"><span class="header-section-number">1.1.1</span> Examples</h3>
|
||
<section id="example" class="level5">
|
||
<h5 class="anchored" data-anchor-id="example">Example</h5>
|
||
<p>For everyday temperatures, the conversion from Celsius to Fahrenheit (<span class="math inline">\(9/5 C + 32\)</span>) is well approximated by simply doubling and adding <span class="math inline">\(30\)</span>. Compare these values for an average room temperature, <span class="math inline">\(C=20\)</span>, and for a relatively chilly day, <span class="math inline">\(C=5\)</span>:</p>
|
||
<p>For <span class="math inline">\(C=20\)</span>:</p>
|
||
<div class="cell" data-execution_count="10">
|
||
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="fl">9</span> <span class="op">/</span> <span class="fl">5</span> <span class="op">*</span> <span class="fl">20</span> <span class="op">+</span> <span class="fl">32</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>68.0</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>The easy to compute approximate value is:</p>
|
||
<div class="cell" data-execution_count="11">
|
||
<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="fl">2</span> <span class="op">*</span> <span class="fl">20</span> <span class="op">+</span> <span class="fl">30</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>70</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>The difference is:</p>
|
||
<div class="cell" data-execution_count="12">
|
||
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>(<span class="fl">9</span><span class="op">/</span><span class="fl">5</span><span class="op">*</span><span class="fl">20</span> <span class="op">+</span> <span class="fl">32</span>) <span class="op">-</span> (<span class="fl">2</span> <span class="op">*</span> <span class="fl">20</span> <span class="op">+</span> <span class="fl">30</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>-2.0</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>For <span class="math inline">\(C=5\)</span>, we have the actual value of:</p>
|
||
<div class="cell" data-execution_count="13">
|
||
<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="fl">9</span> <span class="op">/</span> <span class="fl">5</span> <span class="op">*</span> <span class="fl">5</span> <span class="op">+</span> <span class="fl">32</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>41.0</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>and the easy to compute value is simply <span class="math inline">\(40 = 10 + 30\)</span>. The difference is</p>
|
||
<div class="cell" data-execution_count="14">
|
||
<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="fl">9</span> <span class="op">/</span> <span class="fl">5</span> <span class="op">*</span> <span class="fl">5</span> <span class="op">+</span> <span class="fl">32</span>) <span class="op">-</span> <span class="fl">40</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</code></pre>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="example-1" class="level5">
|
||
<h5 class="anchored" data-anchor-id="example-1">Example</h5>
|
||
<p>Add the numbers <span class="math inline">\(1 + 2 + 3 + 4 + 5\)</span>.</p>
|
||
<div class="cell" data-execution_count="15">
|
||
<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="fl">1</span> <span class="op">+</span> <span class="fl">2</span> <span class="op">+</span> <span class="fl">3</span> <span class="op">+</span> <span class="fl">4</span> <span class="op">+</span> <span class="fl">5</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="16">
|
||
<pre><code>15</code></pre>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="example-2" class="level5">
|
||
<h5 class="anchored" data-anchor-id="example-2">Example</h5>
|
||
<p>How small is <span class="math inline">\(1/2/3/4/5/6\)</span>? It is about <span class="math inline">\(14/10,000\)</span>, as this will show:</p>
|
||
<div class="cell" data-execution_count="16">
|
||
<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">2</span><span class="op">/</span><span class="fl">3</span><span class="op">/</span><span class="fl">4</span><span class="op">/</span><span class="fl">5</span><span class="op">/</span><span class="fl">6</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="17">
|
||
<pre><code>0.001388888888888889</code></pre>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="example-3" class="level5">
|
||
<h5 class="anchored" data-anchor-id="example-3">Example</h5>
|
||
<p>Which is bigger <span class="math inline">\(4^3\)</span> or <span class="math inline">\(3^4\)</span>? We can check by computing their difference:</p>
|
||
<div class="cell" data-execution_count="17">
|
||
<div class="sourceCode cell-code" id="cb23"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a><span class="fl">4</span><span class="op">^</span><span class="fl">3</span> <span class="op">-</span> <span class="fl">3</span><span class="op">^</span><span class="fl">4</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="18">
|
||
<pre><code>-17</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>So <span class="math inline">\(3^4\)</span> is bigger.</p>
|
||
</section>
|
||
<section id="example-4" class="level5">
|
||
<h5 class="anchored" data-anchor-id="example-4">Example</h5>
|
||
<p>A right triangle has sides <span class="math inline">\(a=11\)</span> and <span class="math inline">\(b=12\)</span>. Find the length of the hypotenuse squared. As <span class="math inline">\(c^2 = a^2 + b^2\)</span> we have:</p>
|
||
<div class="cell" data-execution_count="18">
|
||
<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="fl">11</span><span class="op">^</span><span class="fl">2</span> <span class="op">+</span> <span class="fl">12</span><span class="op">^</span><span class="fl">2</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="19">
|
||
<pre><code>265</code></pre>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</section>
|
||
</section>
|
||
<section id="order-of-operations" class="level2" data-number="1.2">
|
||
<h2 data-number="1.2" class="anchored" data-anchor-id="order-of-operations"><span class="header-section-number">1.2</span> Order of operations</h2>
|
||
<p>The calculator must use some rules to define how it will evaluate its instructions when two or more operations are involved. We know mathematically, that when <span class="math inline">\(1 + 2 \cdot 3\)</span> is to be evaluated the multiplication is done first then the addition.</p>
|
||
<p>With the Google Calculator, typing <code>1 + 2 x 3 =</code> will give the value <span class="math inline">\(7\)</span>, but <em>if</em> we evaluate the <code>+</code> sign first, via <code>1</code> <code>+</code> <code>2</code> <code>=</code> <code>x</code> <code>3</code> <code>=</code> the answer will be 9, as that will force the addition of <code>1+2</code> before multiplying. The more traditional way of performing that calculation is to use <em>parentheses</em> to force an evaluation. That is, <code>(1 + 2) * 3 =</code> will produce <code>9</code> (though one must type it in, and not use a mouse to enter). Except for the most primitive of calculators, there are dedicated buttons for parentheses to group expressions.</p>
|
||
<p>In <code>Julia</code>, the entire expression is typed in before being evaluated, so the usual conventions of mathematics related to the order of operations may be used. These are colloquially summarized by the acronym <a href="http://en.wikipedia.org/wiki/Order_of_operations">PEMDAS</a>.</p>
|
||
<blockquote class="blockquote">
|
||
<p><strong>PEMDAS</strong>. This acronym stands for Parentheses, Exponents, Multiplication, Division, Addition, Subtraction. The order indicates which operation has higher precedence, or should happen first. This isn’t exactly the case, as “M” and “D” have the same precedence, as do “A” and “S”. In the case of two operations with equal precedence, <em>associativity</em> is used to decide which to do. For the operations <code>+</code>, <code>-</code>, <code>*</code>, <code>/</code> the associativity is left to right, as in the left one is done first, then the right. However, <code>^</code> has right associativity, so <code>4^3^2</code> is <code>4^(3^2)</code> and not <code>(4^3)^2</code>. (Be warned that some calculators - and spread sheets, such as Excel - will treat this expression with left associativity.)</p>
|
||
</blockquote>
|
||
<p>With rules of precedence, an expression like the following has a clear interpretation to <code>Julia</code> without the need for parentheses:</p>
|
||
<div class="cell" data-execution_count="19">
|
||
<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="fl">1</span> <span class="op">+</span> <span class="fl">2</span> <span class="op">-</span> <span class="fl">3</span> <span class="op">*</span> <span class="fl">4</span> <span class="op">/</span> <span class="fl">5</span> <span class="op">^</span> <span class="fl">6</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="20">
|
||
<pre><code>2.999232</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Working through PEMDAS we see that <code>^</code> is first, then <code>*</code> and then <code>/</code> (this due to associativity and <code>*</code> being the leftmost expression of the two) and finally <code>+</code> and then <code>-</code>, again by associativity rules. So we should have the same value with:</p>
|
||
<div class="cell" data-execution_count="20">
|
||
<div class="sourceCode cell-code" id="cb29"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a>(<span class="fl">1</span> <span class="op">+</span> <span class="fl">2</span>) <span class="op">-</span> ((<span class="fl">3</span> <span class="op">*</span> <span class="fl">4</span>) <span class="op">/</span> (<span class="fl">5</span> <span class="op">^</span> <span class="fl">6</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="21">
|
||
<pre><code>2.999232</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>If different parentheses are used, the answer will likely be different. For example, the following forces the operations to be <code>-</code>, then <code>*</code>, then <code>+</code>. The result of that is then divided by <code>5^6</code>:</p>
|
||
<div class="cell" data-execution_count="21">
|
||
<div class="sourceCode cell-code" id="cb31"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a>(<span class="fl">1</span> <span class="op">+</span> ((<span class="fl">2</span> <span class="op">-</span> <span class="fl">3</span>) <span class="op">*</span> <span class="fl">4</span>)) <span class="op">/</span> (<span class="fl">5</span> <span class="op">^</span> <span class="fl">6</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="22">
|
||
<pre><code>-0.000192</code></pre>
|
||
</div>
|
||
</div>
|
||
<section id="examples-1" class="level3" data-number="1.2.1">
|
||
<h3 data-number="1.2.1" class="anchored" data-anchor-id="examples-1"><span class="header-section-number">1.2.1</span> Examples</h3>
|
||
<section id="example-5" class="level5">
|
||
<h5 class="anchored" data-anchor-id="example-5">Example</h5>
|
||
<p>The percentage error in <span class="math inline">\(x\)</span> if <span class="math inline">\(y\)</span> is the correct value is <span class="math inline">\((x-y)/y \cdot 100\)</span>. Compute this if <span class="math inline">\(x=100\)</span> and <span class="math inline">\(y=98.6\)</span>.</p>
|
||
<div class="cell" data-execution_count="22">
|
||
<div class="sourceCode cell-code" id="cb33"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a>(<span class="fl">100</span> <span class="op">-</span> <span class="fl">98.6</span>) <span class="op">/</span> <span class="fl">98.6</span> <span class="op">*</span> <span class="fl">100</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>1.4198782961460505</code></pre>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="example-6" class="level5">
|
||
<h5 class="anchored" data-anchor-id="example-6">Example</h5>
|
||
<p>The marginal cost of producing one unit can be computed by finding the cost for <span class="math inline">\(n+1\)</span> units and subtracting the cost for <span class="math inline">\(n\)</span> units. If the cost of <span class="math inline">\(n\)</span> units is <span class="math inline">\(n^2 + 10\)</span>, find the marginal cost when <span class="math inline">\(n=100\)</span>.</p>
|
||
<div class="cell" data-execution_count="23">
|
||
<div class="sourceCode cell-code" id="cb35"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a>(<span class="fl">101</span><span class="op">^</span><span class="fl">2</span> <span class="op">+</span> <span class="fl">10</span>) <span class="op">-</span> (<span class="fl">100</span><span class="op">^</span><span class="fl">2</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>201</code></pre>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="example-7" class="level5">
|
||
<h5 class="anchored" data-anchor-id="example-7">Example</h5>
|
||
<p>The average cost per unit is the total cost divided by the number of units. Again, if the cost of <span class="math inline">\(n\)</span> units is <span class="math inline">\(n^2 + 10\)</span>, find the average cost for <span class="math inline">\(n=100\)</span> units.</p>
|
||
<div class="cell" data-execution_count="24">
|
||
<div class="sourceCode cell-code" id="cb37"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb37-1"><a href="#cb37-1" aria-hidden="true" tabindex="-1"></a>(<span class="fl">100</span><span class="op">^</span><span class="fl">2</span> <span class="op">+</span> <span class="fl">10</span>) <span class="op">/</span> <span class="fl">100</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>100.1</code></pre>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="example-8" class="level5">
|
||
<h5 class="anchored" data-anchor-id="example-8">Example</h5>
|
||
<p>The slope of the line through two points is <span class="math inline">\(m=(y_1 - y_0) / (x_1 - x_0)\)</span>. For the two points <span class="math inline">\((1,2)\)</span> and <span class="math inline">\((3,4)\)</span> find the slope of the line through them.</p>
|
||
<div class="cell" data-execution_count="25">
|
||
<div class="sourceCode cell-code" id="cb39"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb39-1"><a href="#cb39-1" aria-hidden="true" tabindex="-1"></a>(<span class="fl">4</span> <span class="op">-</span> <span class="fl">2</span>) <span class="op">/</span> (<span class="fl">3</span> <span class="op">-</span> <span class="fl">1</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="26">
|
||
<pre><code>1.0</code></pre>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</section>
|
||
<section id="two-ways-to-write-division---and-they-are-not-the-same" class="level3" data-number="1.2.2">
|
||
<h3 data-number="1.2.2" class="anchored" data-anchor-id="two-ways-to-write-division---and-they-are-not-the-same"><span class="header-section-number">1.2.2</span> Two ways to write division - and they are not the same</h3>
|
||
<p>The expression <span class="math inline">\(a + b / c + d\)</span> is equivalent to <span class="math inline">\(a + (b/c) + d\)</span> due to the order of operations. It will generally have a different answer than <span class="math inline">\((a + b) / (c + d)\)</span>.</p>
|
||
<p>How would the following be expressed, were it written inline:</p>
|
||
<p><span class="math display">\[
|
||
\frac{1 + 2}{3 + 4}?
|
||
\]</span></p>
|
||
<p>It would have to be computed through <span class="math inline">\((1 + 2) / (3 + 4)\)</span>. This is because unlike <code>/</code>, the implied order of operation in the mathematical notation with the <em>horizontal division symbol</em> (the <a href="http://tinyurl.com/y9tj6udl">vinicula</a>) is to compute the top and the bottom and then divide. That is, the vinicula is a grouping notation like parentheses, only implicitly so. Thus the above expression really represents the more verbose:</p>
|
||
<p><span class="math display">\[
|
||
\frac{(1 + 2)}{(3 + 4)}.
|
||
\]</span></p>
|
||
<p>Which lends itself readily to the translation:</p>
|
||
<div class="cell" data-execution_count="26">
|
||
<div class="sourceCode cell-code" id="cb41"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb41-1"><a href="#cb41-1" aria-hidden="true" tabindex="-1"></a>(<span class="fl">1</span> <span class="op">+</span> <span class="fl">2</span>) <span class="op">/</span> (<span class="fl">3</span> <span class="op">+</span> <span class="fl">4</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="27">
|
||
<pre><code>0.42857142857142855</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>To emphasize, this is not the same as the value without the parentheses:</p>
|
||
<div class="cell" data-execution_count="27">
|
||
<div class="sourceCode cell-code" id="cb43"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb43-1"><a href="#cb43-1" aria-hidden="true" tabindex="-1"></a><span class="fl">1</span> <span class="op">+</span> <span class="fl">2</span> <span class="op">/</span> <span class="fl">3</span> <span class="op">+</span> <span class="fl">4</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="28">
|
||
<pre><code>5.666666666666666</code></pre>
|
||
</div>
|
||
</div>
|
||
<div class="callout-warning callout callout-style-default callout-captioned">
|
||
<div class="callout-header d-flex align-content-center">
|
||
<div class="callout-icon-container">
|
||
<i class="callout-icon"></i>
|
||
</div>
|
||
<div class="callout-caption-container flex-fill">
|
||
Warning
|
||
</div>
|
||
</div>
|
||
<div class="callout-body-container callout-body">
|
||
<p>The viniculum also indicates grouping when used with the square root (the top bar), and complex conjugation. That usage is often clear enough, but the usage of the viniculum in division often leads to confusion. The example above is one where the parentheses are often, erroneously, omitted. However, more confusion can arise when there is more than one vinicula. An expression such as <span class="math inline">\(a/b/c\)</span> written inline has no confusion, it is: <span class="math inline">\((a/b) / c\)</span> as left association is used; but when written with a pair of vinicula there is often the typographical convention of a slightly longer vinicula to indicate which is to be considered first. In the absence of that, then top to bottom association is often implied.</p>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="infix-postfix-and-prefix-notation" class="level3" data-number="1.2.3">
|
||
<h3 data-number="1.2.3" class="anchored" data-anchor-id="infix-postfix-and-prefix-notation"><span class="header-section-number">1.2.3</span> Infix, postfix, and prefix notation</h3>
|
||
<p>The factorial button on the Google Button creates an expression like <code>14!</code> that is then evaluated. The operator, <code>!</code>, appears after the value (<code>14</code>) that it is applied to. This is called <em>postfix notation</em>. When a unary minus sign is used, as in <code>-14</code>, the minus sign occurs before the value it operates on. This uses <em>prefix notation</em>. These concepts can be extended to binary operations, where a third possibility is provided: <em>infix notation</em>, where the operator is between the two values. The infix notation is common for our familiar mathematical operations. We write <code>14 + 2</code> and not <code>+ 14 2</code> or <code>14 2 +</code>. (Though if we had an old reverse-Polish notation calculator, we would enter <code>14 2 +</code>!) In <code>Julia</code>, there are several infix operators, such as <code>+</code>, <code>-</code>, … and others that we may be unfamiliar with. These mirror the familiar notation from most math texts.</p>
|
||
<div class="callout-note callout callout-style-default callout-captioned">
|
||
<div class="callout-header d-flex align-content-center">
|
||
<div class="callout-icon-container">
|
||
<i class="callout-icon"></i>
|
||
</div>
|
||
<div class="callout-caption-container flex-fill">
|
||
Note
|
||
</div>
|
||
</div>
|
||
<div class="callout-body-container callout-body">
|
||
<p>In <code>Julia</code> many infix operations can be done using a prefix manner. For example <code>14 + 2</code> can also be evaluated by <code>+(14,2)</code>. There are very few <em>postfix</em> operations, though in these notes we will overload one, the <code>'</code> operation, to indicate a derivative.</p>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</section>
|
||
<section id="constants" class="level2" data-number="1.3">
|
||
<h2 data-number="1.3" class="anchored" data-anchor-id="constants"><span class="header-section-number">1.3</span> Constants</h2>
|
||
<p>The Google calculator has two built in constants, <code>e</code> and <code>π</code>. Julia provides these as well, though not quite as easily. First, <code>π</code> is just <code>pi</code>:</p>
|
||
<div class="cell" data-execution_count="28">
|
||
<div class="sourceCode cell-code" id="cb45"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb45-1"><a href="#cb45-1" aria-hidden="true" tabindex="-1"></a><span class="cn">pi</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>π = 3.1415926535897...</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Whereas, <code>e</code> is is not simply the character <code>e</code>, but <em>rather</em> a <a href="../unicode.html">Unicode</a> character typed in as <code>\euler[tab]</code>.</p>
|
||
<div class="cell" data-execution_count="29">
|
||
<div class="sourceCode cell-code" id="cb47"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb47-1"><a href="#cb47-1" aria-hidden="true" tabindex="-1"></a><span class="cn">ℯ</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>ℯ = 2.7182818284590...</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>However, when the accompanying package, <code>CalculusWithJulia</code>, is loaded, the character <code>e</code> will refer to a floating point approximation to the Euler constant .</p>
|
||
</div>
|
||
</div>
|
||
<p>In the sequel, we will just use <code>e</code> for this constant (though more commonly the <code>exp</code> function), with the reminder that base <code>Julia</code> alone does not reserve this symbol.</p>
|
||
<p>Mathematically these are irrational values with decimal expansions that do not repeat. <code>Julia</code> represents these values internally with additional accuracy beyond that which is displayed. Math constants can be used as though they were numbers, such is done with this expression:</p>
|
||
<div class="cell" data-execution_count="30">
|
||
<div class="sourceCode cell-code" id="cb49"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb49-1"><a href="#cb49-1" aria-hidden="true" tabindex="-1"></a><span class="cn">ℯ</span><span class="op">^</span>(<span class="fl">1</span><span class="op">/</span>(<span class="fl">2</span><span class="op">*</span><span class="cn">pi</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="31">
|
||
<pre><code>1.17251960642002</code></pre>
|
||
</div>
|
||
</div>
|
||
<div class="callout-warning callout callout-style-default callout-captioned">
|
||
<div class="callout-header d-flex align-content-center">
|
||
<div class="callout-icon-container">
|
||
<i class="callout-icon"></i>
|
||
</div>
|
||
<div class="callout-caption-container flex-fill">
|
||
Warning
|
||
</div>
|
||
</div>
|
||
<div class="callout-body-container callout-body">
|
||
<p>In most cases. There are occasional (basically rare) spots where using <code>pi</code> by itself causes an eror where <code>1*pi</code> will not. The reason is <code>1*pi</code> will create a floating point value from the irrational object, <code>pi</code>.</p>
|
||
</div>
|
||
</div>
|
||
<section id="numeric-literals" class="level3" data-number="1.3.1">
|
||
<h3 data-number="1.3.1" class="anchored" data-anchor-id="numeric-literals"><span class="header-section-number">1.3.1</span> Numeric literals</h3>
|
||
<p>For some special cases, Julia implements <em>multiplication</em> without a multiplication symbol. This is when the value on the left is a number, as in <code>2pi</code>, which has an equivalent value to <code>2*pi</code>. <em>However</em> the two are not equivalent, in that multiplication with <em>numeric literals</em> does not have the same precedence as regular multiplication - it is higher. This has practical importance when used in division or powers. For instance, these two are <strong>not</strong> the same:</p>
|
||
<div class="cell" data-execution_count="31">
|
||
<div class="sourceCode cell-code" id="cb51"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb51-1"><a href="#cb51-1" aria-hidden="true" tabindex="-1"></a><span class="fl">1</span><span class="op">/</span><span class="fl">2</span>pi, <span class="fl">1</span><span class="op">/</span><span class="fl">2</span><span class="op">*</span><span class="cn">pi</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>(0.15915494309189535, 1.5707963267948966)</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Why? Because the first <code>2pi</code> is performed before division, as multiplication with numeric literals has higher precedence than regular multiplication, which is at the same level as division.</p>
|
||
<p>To confuse things even more, consider</p>
|
||
<div class="cell" data-execution_count="32">
|
||
<div class="sourceCode cell-code" id="cb53"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb53-1"><a href="#cb53-1" aria-hidden="true" tabindex="-1"></a><span class="fl">2</span>pi<span class="op">^</span><span class="fl">2</span>pi</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="33">
|
||
<pre><code>2658.978166443007</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Is this the same as <code>2 * (pi^2) * pi</code> or <code>(2pi)^(2pi)</code>?. The former would be the case is powers had higher precedence than literal multiplication, the latter would be the case were it the reverse. In fact, the correct answer is <code>2 * (pi^(2*pi))</code>:</p>
|
||
<div class="cell" data-execution_count="33">
|
||
<div class="sourceCode cell-code" id="cb55"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb55-1"><a href="#cb55-1" aria-hidden="true" tabindex="-1"></a><span class="fl">2</span>pi<span class="op">^</span><span class="fl">2</span>pi, <span class="fl">2</span> <span class="op">*</span> (<span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>) <span class="op">*</span> <span class="cn">pi</span>, (<span class="fl">2</span>pi)<span class="op">^</span>(<span class="fl">2</span>pi), <span class="fl">2</span> <span class="op">*</span> (<span class="cn">pi</span><span class="op">^</span>(<span class="fl">2</span>pi))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="34">
|
||
<pre><code>(2658.978166443007, 9.869604401089358, 103540.92043427199, 2658.978166443007)</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>This follows usual mathematical convention, but is a source of potential confusion. It can be best to be explicit about multiplication, save for the simplest of cases.</p>
|
||
</section>
|
||
</section>
|
||
<section id="functions" class="level2" data-number="1.4">
|
||
<h2 data-number="1.4" class="anchored" data-anchor-id="functions"><span class="header-section-number">1.4</span> Functions</h2>
|
||
<p>On the Google calculator, the square root button has a single purpose: for the current value find a square root if possible, and if not signal an error (such as what happens if the value is negative). For more general powers, the <span class="math inline">\(x^y\)</span> key can be used.</p>
|
||
<p>In <code>Julia</code>, functions are used to perform the actions that a specialized button may do on the calculator. <code>Julia</code> provides many standard mathematical functions - more than there could be buttons on a calculator - and allows the user to easily define their own functions. For example, <code>Julia</code> provides the same set of functions as on Google’s calculator, though with different names. For logarithms, <span class="math inline">\(\ln\)</span> becomes <code>log</code> and <span class="math inline">\(\log\)</span> is <code>log10</code> (computer programs almost exclusively reserve <code>log</code> for the natural log); for factorials, <span class="math inline">\(x!\)</span>, there is <code>factorial</code>; for powers <span class="math inline">\(\sqrt{}\)</span> becomes <code>sqrt</code>, <span class="math inline">\(EXP\)</span> becomes <code>exp</code>, and <span class="math inline">\(x^y\)</span> is computed with the infix operator <code>^</code>. For the trigonometric functions, the basic names are similar: <code>sin</code>, <code>cos</code>, <code>tan</code>. These expect radians. For angles in degrees, the convenience functions <code>sind</code>, <code>cosd</code>, and <code>tand</code> are provided. On the calculator, inverse functions like <span class="math inline">\(\sin^{-1}(x)\)</span> are done by combining <span class="math inline">\(Inv\)</span> with <span class="math inline">\(\sin\)</span>. With <code>Julia</code>, the function name is <code>asin</code>, an abbreviation for “arcsine.” (Which is a good thing, as the notation using a power of <span class="math inline">\(-1\)</span> is often a source of confusion and is not supported by <code>Julia</code> without work.) Similarly, there are <code>asind</code>, <code>acos</code>, <code>acosd</code>, <code>atan</code>, and <code>atand</code> functions available to the <code>Julia</code> user.</p>
|
||
<p>The following table summarizes the above:</p>
|
||
<div class="cell" data-execution_count="34">
|
||
<div class="cell-output cell-output-display" data-execution_count="35">
|
||
|
||
|
||
<div class="table-responsive">
|
||
<table class="table table-hover">
|
||
<tbody><tr><th>Calculator</th><th>Julia</th></tr>
|
||
|
||
<tr><td><div class="markdown"><p>\(+\), \(-\), \(\times\), \(\div\)</p>
|
||
</div></td><td><div class="markdown"><p><code>+</code>, <code>-</code>, <code>*</code>, <code>/</code></p>
|
||
</div></td></tr>
|
||
<tr><td><div class="markdown">\(x^y\)
|
||
</div></td><td><div class="markdown"><p><code>^</code></p>
|
||
</div></td></tr>
|
||
<tr><td><div class="markdown">\(\sqrt{}, \sqrt[3]{}\)
|
||
</div></td><td><div class="markdown"><p><code>sqrt</code>, <code>cbrt</code></p>
|
||
</div></td></tr>
|
||
<tr><td><div class="markdown">\(e^x\)
|
||
</div></td><td><div class="markdown"><p><code>exp</code></p>
|
||
</div></td></tr>
|
||
<tr><td><div class="markdown"><p>\(\ln\), \(\log\)</p>
|
||
</div></td><td><div class="markdown"><p><code>log</code>, <code>log10</code></p>
|
||
</div></td></tr>
|
||
<tr><td><div class="markdown">\(\sin, \cos, \tan, \sec, \csc, \cot\)
|
||
</div></td><td><div class="markdown"><p><code>sin</code>, <code>cos</code>, <code>tan</code>, <code>sec</code>, <code>csc</code>, <code>cot</code></p>
|
||
</div></td></tr>
|
||
<tr><td><div class="markdown"><p>In degrees, not radians</p>
|
||
</div></td><td><div class="markdown"><p><code>sind</code>, <code>cosd</code>, <code>tand</code>, <code>secd</code>, <code>cscd</code>, <code>cotd</code></p>
|
||
</div></td></tr>
|
||
<tr><td><div class="markdown">\(\sin^{-1}, \cos^{-1}, \tan^{-1}\)
|
||
</div></td><td><div class="markdown"><p><code>asin</code>, <code>acos</code>, <code>atan</code></p>
|
||
</div></td></tr>
|
||
<tr><td><div class="markdown">\(n!\)
|
||
</div></td><td><div class="markdown"><p><code>factorial</code></p>
|
||
</div></td></tr>
|
||
|
||
</tbody></table>
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
<p>Using a function is very straightforward. A function is called using parentheses, in a manner visually similar to how a function is called mathematically. So if we consider the <code>sqrt</code> function, we have:</p>
|
||
<div class="cell" data-execution_count="35">
|
||
<div class="sourceCode cell-code" id="cb57"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb57-1"><a href="#cb57-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sqrt</span>(<span class="fl">4</span>), <span class="fu">sqrt</span>(<span class="fl">5</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="36">
|
||
<pre><code>(2.0, 2.23606797749979)</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>The function is referred to by name (<code>sqrt</code>) and called with parentheses. Any arguments are passed into the function using commas to separate values, should there be more than one. When there are numerous values for a function, the arguments may need to be given in a specific order or may possibly be specified with <em>keywords</em>. (A semicolon can be used instead of a comma to separate keyword arguments.)</p>
|
||
<p>Some more examples:</p>
|
||
<div class="cell" data-execution_count="36">
|
||
<div class="sourceCode cell-code" id="cb59"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb59-1"><a href="#cb59-1" aria-hidden="true" tabindex="-1"></a><span class="fu">exp</span>(<span class="fl">2</span>), <span class="fu">log</span>(<span class="fl">10</span>), <span class="fu">sqrt</span>(<span class="fl">100</span>), <span class="fl">10</span><span class="op">^</span>(<span class="fl">1</span><span class="op">/</span><span class="fl">2</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="37">
|
||
<pre><code>(7.38905609893065, 2.302585092994046, 10.0, 3.1622776601683795)</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>Parentheses have many roles. We’ve just seen that parentheses may be used for grouping, and now we see they are used to indicate a function is being called. These are familiar from their parallel usage in traditional math notation. In <code>Julia</code>, a third usage is common, the making of a “tuple,” or a container of different objects, for example <code>(1, sqrt(2), pi)</code>. In these notes, the output of multiple commands separated by commas is a printed tuple.</p>
|
||
</div>
|
||
</div>
|
||
<section id="multiple-arguments" class="level3" data-number="1.4.1">
|
||
<h3 data-number="1.4.1" class="anchored" data-anchor-id="multiple-arguments"><span class="header-section-number">1.4.1</span> Multiple arguments</h3>
|
||
<p>For the logarithm, we mentioned that <code>log</code> is the natural log and <code>log10</code> implements the logarithm base 10. As well there is <code>log2</code>. However, in general there is no <code>logb</code> for any base <code>b</code>. Instead, the basic <code>log</code> function can take <em>two</em> arguments. When it does, the first is the base, and the second the value to take the logarithm of. This avoids forcing the user to remember that <span class="math inline">\(\log_b(x) = \log(x)/\log(b)\)</span>.</p>
|
||
<p>So we have all these different, but related, uses to find logarithms:</p>
|
||
<div class="cell" data-execution_count="37">
|
||
<div class="sourceCode cell-code" id="cb61"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb61-1"><a href="#cb61-1" aria-hidden="true" tabindex="-1"></a><span class="fu">log</span>(<span class="cn">e</span>), <span class="fu">log</span>(<span class="fl">2</span>, <span class="cn">e</span>), <span class="fu">log</span>(<span class="fl">10</span>, <span class="cn">e</span>), <span class="fu">log</span>(<span class="cn">e</span>, <span class="fl">2</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="38">
|
||
<pre><code>(1.0, 1.4426950408889634, 0.43429448190325176, 0.6931471805599453)</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>In <code>Julia</code>, the “generic” function <code>log</code> not only has different implementations for different types of arguments (real or complex), but also has a different implementation depending on the number of arguments.</p>
|
||
</section>
|
||
<section id="examples-2" class="level3" data-number="1.4.2">
|
||
<h3 data-number="1.4.2" class="anchored" data-anchor-id="examples-2"><span class="header-section-number">1.4.2</span> Examples</h3>
|
||
<section id="example-9" class="level5">
|
||
<h5 class="anchored" data-anchor-id="example-9">Example</h5>
|
||
<p>A right triangle has sides <span class="math inline">\(a=11\)</span> and <span class="math inline">\(b=12\)</span>. Find the length of the hypotenuse. As <span class="math inline">\(c^2 = a^2 + b^2\)</span> we have:</p>
|
||
<div class="cell" data-execution_count="38">
|
||
<div class="sourceCode cell-code" id="cb63"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb63-1"><a href="#cb63-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sqrt</span>(<span class="fl">11</span><span class="op">^</span><span class="fl">2</span> <span class="op">+</span> <span class="fl">12</span><span class="op">^</span><span class="fl">2</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="39">
|
||
<pre><code>16.278820596099706</code></pre>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="example-10" class="level5">
|
||
<h5 class="anchored" data-anchor-id="example-10">Example</h5>
|
||
<p>A formula from statistics to compute the variance of a binomial random variable for parameters <span class="math inline">\(p\)</span> and <span class="math inline">\(n\)</span> is <span class="math inline">\(\sqrt{n p (1-p)}\)</span>. Compute this value for <span class="math inline">\(p=1/4\)</span> and <span class="math inline">\(n=10\)</span>.</p>
|
||
<div class="cell" data-execution_count="39">
|
||
<div class="sourceCode cell-code" id="cb65"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb65-1"><a href="#cb65-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sqrt</span>(<span class="fl">10</span> <span class="op">*</span> <span class="fl">1</span><span class="op">/</span><span class="fl">4</span> <span class="op">*</span> (<span class="fl">1</span> <span class="op">-</span> <span class="fl">1</span><span class="op">/</span><span class="fl">4</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="40">
|
||
<pre><code>1.3693063937629153</code></pre>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="example-11" class="level5">
|
||
<h5 class="anchored" data-anchor-id="example-11">Example</h5>
|
||
<p>Find the distance between the points <span class="math inline">\((-3, -4)\)</span> and <span class="math inline">\((5,6)\)</span>. Using the distance formula <span class="math inline">\(\sqrt{(x_1-x_0)^2+(y_1-y_0)^2}\)</span>, we have:</p>
|
||
<div class="cell" data-execution_count="40">
|
||
<div class="sourceCode cell-code" id="cb67"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb67-1"><a href="#cb67-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sqrt</span>((<span class="fl">5</span> <span class="op">-</span> <span class="op">-</span><span class="fl">3</span>)<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> (<span class="fl">6</span> <span class="op">-</span> <span class="op">-</span><span class="fl">4</span>)<span class="op">^</span><span class="fl">2</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="41">
|
||
<pre><code>12.806248474865697</code></pre>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="example-12" class="level5">
|
||
<h5 class="anchored" data-anchor-id="example-12">Example</h5>
|
||
<p>The formula to compute the resistance of two resistors in parallel is given by: <span class="math inline">\(1/(1/r_1 + 1/r_2)\)</span>. Suppose the resistance is <span class="math inline">\(10\)</span> in one resistor and <span class="math inline">\(20\)</span> in the other. What is the resistance in parallel?</p>
|
||
<div class="cell" data-execution_count="41">
|
||
<div class="sourceCode cell-code" id="cb69"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb69-1"><a href="#cb69-1" aria-hidden="true" tabindex="-1"></a><span class="fl">1</span> <span class="op">/</span> (<span class="fl">1</span><span class="op">/</span><span class="fl">10</span> <span class="op">+</span> <span class="fl">1</span><span class="op">/</span><span class="fl">20</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="42">
|
||
<pre><code>6.666666666666666</code></pre>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</section>
|
||
</section>
|
||
<section id="errors" class="level2" data-number="1.5">
|
||
<h2 data-number="1.5" class="anchored" data-anchor-id="errors"><span class="header-section-number">1.5</span> Errors</h2>
|
||
<p>Not all computations on a calculator are valid. For example, the Google calculator will display <code>Error</code> as the output of <span class="math inline">\(0/0\)</span> or <span class="math inline">\(\sqrt{-1}\)</span>. These are also errors mathematically, though the second is not if the complex numbers are considered.</p>
|
||
<p>In <code>Julia</code>, there is a richer set of error types. The value <code>0/0</code> will in fact not be an error, but rather a value <code>NaN</code>. This is a special floating point value indicating “not a number” and is the result for various operations. The output of <span class="math inline">\(\sqrt{-1}\)</span> (computed via <code>sqrt(-1)</code>) will indicate a domain error:</p>
|
||
<div class="cell" data-execution_count="42">
|
||
<div class="sourceCode cell-code" id="cb71"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb71-1"><a href="#cb71-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sqrt</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-error">
|
||
<pre><code>LoadError: DomainError with -1.0:
|
||
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>For integer or real-valued inputs, the <code>sqrt</code> function expects non-negative values, so that the output will always be a real number.</p>
|
||
<p>There are other types of errors. Overflow is a common one on most calculators. The value of <span class="math inline">\(1000!\)</span> is actually <em>very</em> large (over 2500 digits large). On the Google calculator it returns <code>Infinity</code>, a slight stretch. For <code>factorial(1000)</code> <code>Julia</code> returns an <code>OverflowError</code>. This means that the answer is too large to be represented as a regular integer.</p>
|
||
<div class="cell" data-execution_count="43">
|
||
<div class="sourceCode cell-code" id="cb73"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb73-1"><a href="#cb73-1" aria-hidden="true" tabindex="-1"></a><span class="fu">factorial</span>(<span class="fl">1000</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-error">
|
||
<pre><code>LoadError: OverflowError: 1000 is too large to look up in the table; consider using `factorial(big(1000))` instead</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>How <code>Julia</code> handles overflow is a study in tradeoffs. For integer operations that demand high performance, <code>Julia</code> does not check for overflow. So, for example, if we are not careful strange answers can be had. Consider the difference here between powers of 2:</p>
|
||
<div class="cell" data-execution_count="44">
|
||
<div class="sourceCode cell-code" id="cb75"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb75-1"><a href="#cb75-1" aria-hidden="true" tabindex="-1"></a><span class="fl">2</span><span class="op">^</span><span class="fl">62</span>, <span class="fl">2</span><span class="op">^</span><span class="fl">63</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="45">
|
||
<pre><code>(4611686018427387904, -9223372036854775808)</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>On a machine with <span class="math inline">\(64\)</span>-bit integers, the first of these two values is correct, the second, clearly wrong, as the answer given is negative. This is due to overflow. The cost of checking is considered too high, so no error is thrown. The user is expected to have a sense that they need to be careful when their values are quite large. (Or the user can use floating point numbers, which though not always exact, can represent much bigger values and are exact for a reasonably wide range of integer values.)</p>
|
||
<div class="callout-warning callout callout-style-default callout-captioned">
|
||
<div class="callout-header d-flex align-content-center">
|
||
<div class="callout-icon-container">
|
||
<i class="callout-icon"></i>
|
||
</div>
|
||
<div class="callout-caption-container flex-fill">
|
||
Warning
|
||
</div>
|
||
</div>
|
||
<div class="callout-body-container callout-body">
|
||
<p>In a turnaround from a classic blues song, we can think of <code>Julia</code> as built for speed, not for comfort. All of these errors above could be worked around so that the end user doesn’t see them. However, this would require slowing things down, either through checking of operations or allowing different types of outputs for similar type of inputs. These are tradeoffs that are not made for performance reasons. For the most part, the tradeoffs don’t get in the way, but learning where to be careful takes some time. Error messages often suggest a proper alternative.</p>
|
||
</div>
|
||
</div>
|
||
<section id="example-13" class="level5">
|
||
<h5 class="anchored" data-anchor-id="example-13">Example</h5>
|
||
<p>Did Homer Simpson disprove <a href="http://www.npr.org/sections/krulwich/2014/05/08/310818693/did-homer-simpson-actually-solve-fermat-s-last-theorem-take-a-look">Fermat’s Theorem</a>?</p>
|
||
<p>Fermat’s theorem states there are no solutions over the integers to <span class="math inline">\(a^n + b^n = c^n\)</span> when <span class="math inline">\(n > 2\)</span>. In the photo accompanying the linked article, we see:</p>
|
||
<p><span class="math display">\[
|
||
3987^{12} + 4365^{12} - 4472^{12}.
|
||
\]</span></p>
|
||
<p>If you were to do this on most calculators, the answer would be <span class="math inline">\(0\)</span>. Were this true, it would show that there is at least one solution to <span class="math inline">\(a^{12} + b^{12} = c^{12}\)</span> over the integers - hence Fermat would be wrong. So is it <span class="math inline">\(0\)</span>?</p>
|
||
<p>Well, let’s try something with <code>Julia</code> to see. Being clever, we check if <span class="math inline">\((3987^{12} + 4365^{12})^{1/12} = 4472\)</span>:</p>
|
||
<div class="cell" data-execution_count="45">
|
||
<div class="sourceCode cell-code" id="cb77"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb77-1"><a href="#cb77-1" aria-hidden="true" tabindex="-1"></a>(<span class="fl">3987</span><span class="op">^</span><span class="fl">12</span> <span class="op">+</span> <span class="fl">4365</span><span class="op">^</span><span class="fl">12</span>)<span class="op">^</span>(<span class="fl">1</span><span class="op">/</span><span class="fl">12</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="46">
|
||
<pre><code>28.663217591132355</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Not even close. Case closed. But wait? This number to be found must be <em>at least</em> as big as <span class="math inline">\(3987\)</span> and we got <span class="math inline">\(28\)</span>. Doh! Something can’t be right. Well, maybe integer powers are being an issue. (The largest <span class="math inline">\(64\)</span>-bit integer is less than <span class="math inline">\(10^{19}\)</span> and we can see that <span class="math inline">\((4\cdot 10^3)^{12}\)</span> is bigger than <span class="math inline">\(10^{36})\)</span>. Trying again using floating point values for the base, we see:</p>
|
||
<div class="cell" data-execution_count="46">
|
||
<div class="sourceCode cell-code" id="cb79"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb79-1"><a href="#cb79-1" aria-hidden="true" tabindex="-1"></a>(<span class="fl">3987.0</span><span class="op">^</span><span class="fl">12</span> <span class="op">+</span> <span class="fl">4365.0</span><span class="op">^</span><span class="fl">12</span>)<span class="op">^</span>(<span class="fl">1</span><span class="op">/</span><span class="fl">12</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="47">
|
||
<pre><code>4472.000000007058</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Ahh, we see something really close to <span class="math inline">\(4472\)</span>, but not exactly. Why do most calculators get this last part wrong? It isn’t that they don’t use floating point, but rather the difference between the two numbers:</p>
|
||
<div class="cell" data-execution_count="47">
|
||
<div class="sourceCode cell-code" id="cb81"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb81-1"><a href="#cb81-1" aria-hidden="true" tabindex="-1"></a>(<span class="fl">3987.0</span><span class="op">^</span><span class="fl">12</span> <span class="op">+</span> <span class="fl">4365.0</span><span class="op">^</span><span class="fl">12</span>)<span class="op">^</span>(<span class="fl">1</span><span class="op">/</span><span class="fl">12</span>) <span class="op">-</span> <span class="fl">4472</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="48">
|
||
<pre><code>7.057678885757923e-9</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>is less than <span class="math inline">\(10^{-8}\)</span> so on a display with <span class="math inline">\(8\)</span> digits may be rounded to <span class="math inline">\(0\)</span>.</p>
|
||
<p>Moral: with <code>Julia</code> and with calculators, we still have to be mindful not to blindly accept an answer.</p>
|
||
</section>
|
||
</section>
|
||
<section id="questions" class="level2" data-number="1.6">
|
||
<h2 data-number="1.6" class="anchored" data-anchor-id="questions"><span class="header-section-number">1.6</span> Questions</h2>
|
||
<section id="question" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question">Question</h6>
|
||
<p>Compute <span class="math inline">\(22/7\)</span> with <code>Julia</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="12866236643356175018" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_12866236643356175018">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="12866236643356175018" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="12866236643356175018_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("12866236643356175018").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 3.142857142857143) <= 0.001);
|
||
var msgBox = document.getElementById('12866236643356175018_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_12866236643356175018")
|
||
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_12866236643356175018")
|
||
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>Compute <span class="math inline">\(\sqrt{220}\)</span> with <code>Julia</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="8379144175821156447" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_8379144175821156447">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="8379144175821156447" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="8379144175821156447_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("8379144175821156447").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 14.832396974191326) <= 0.001);
|
||
var msgBox = document.getElementById('8379144175821156447_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_8379144175821156447")
|
||
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_8379144175821156447")
|
||
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>Compute <span class="math inline">\(2^8\)</span> with <code>Julia</code>.</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="5059702507635126408" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_5059702507635126408">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="5059702507635126408" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="5059702507635126408_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("5059702507635126408").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 256) <= 0);
|
||
var msgBox = document.getElementById('5059702507635126408_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_5059702507635126408")
|
||
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_5059702507635126408")
|
||
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>Compute the value of</p>
|
||
<p><span class="math display">\[
|
||
\frac{9 - 5 \cdot (3-4)}{6 - 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="5445304709388426836" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_5445304709388426836">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="5445304709388426836" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="5445304709388426836_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("5445304709388426836").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 3.5) <= 0.001);
|
||
var msgBox = document.getElementById('5445304709388426836_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_5445304709388426836")
|
||
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_5445304709388426836")
|
||
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>Compute the following using <code>Julia</code>:</p>
|
||
<p><span class="math display">\[
|
||
\frac{(.25 - .2)^2}{(1/4)^2 + (1/3)^2}
|
||
\]</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="10647984461639712637" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_10647984461639712637">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="10647984461639712637" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="10647984461639712637_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("10647984461639712637").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 0.014399999999999993) <= 0.001);
|
||
var msgBox = document.getElementById('10647984461639712637_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_10647984461639712637")
|
||
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_10647984461639712637")
|
||
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>Compute the decimal representation of the following using <code>Julia</code>:</p>
|
||
<p><span class="math display">\[
|
||
1 + \frac{1}{2} + \frac{1}{2^2} + \frac{1}{2^3} + \frac{1}{2^4}
|
||
\]</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="17953479304579835701" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_17953479304579835701">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="17953479304579835701" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="17953479304579835701_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("17953479304579835701").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 1.9375) <= 0.001);
|
||
var msgBox = document.getElementById('17953479304579835701_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_17953479304579835701")
|
||
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_17953479304579835701")
|
||
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>Compute the following using <code>Julia</code>:</p>
|
||
<p><span class="math display">\[
|
||
\frac{3 - 2^2}{4 - 2\cdot3}
|
||
\]</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="4316185232887402069" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_4316185232887402069">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="4316185232887402069" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="4316185232887402069_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("4316185232887402069").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 0.5) <= 0.001);
|
||
var msgBox = document.getElementById('4316185232887402069_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_4316185232887402069")
|
||
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_4316185232887402069")
|
||
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>Compute the following using <code>Julia</code>:</p>
|
||
<p><span class="math display">\[
|
||
(1/2) \cdot 32 \cdot 3^2 + 100 \cdot 3 - 20
|
||
\]</span></p>
|
||
<div class="cell" data-hold="true" data-execution_count="55">
|
||
<div class="cell-output cell-output-display" data-execution_count="56">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="10596313411068425253" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_10596313411068425253">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="10596313411068425253" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="10596313411068425253_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("10596313411068425253").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 424.0) <= 0.001);
|
||
var msgBox = document.getElementById('10596313411068425253_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_10596313411068425253")
|
||
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_10596313411068425253")
|
||
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>Wich of the following is a valid <code>Julia</code> expression for</p>
|
||
<p><span class="math display">\[
|
||
\frac{3 - 2}{4 - 1}
|
||
\]</span></p>
|
||
<p>that uses the least number of parentheses?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="56">
|
||
<div class="cell-output cell-output-display" data-execution_count="57">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="10023627762633600405" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_10023627762633600405">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_10023627762633600405_1">
|
||
<input class="form-check-input" type="radio" name="radio_10023627762633600405" id="radio_10023627762633600405_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
<code>3 - 2 / (4 - 1)</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_10023627762633600405_2">
|
||
<input class="form-check-input" type="radio" name="radio_10023627762633600405" id="radio_10023627762633600405_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
<code>(3 - 2) / (4 - 1)</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_10023627762633600405_3">
|
||
<input class="form-check-input" type="radio" name="radio_10023627762633600405" id="radio_10023627762633600405_3" value="3">
|
||
|
||
<span class="label-body px-1">
|
||
<code>(3 - 2)/ 4 - 1</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="10023627762633600405_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_10023627762633600405"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 2;
|
||
var msgBox = document.getElementById('10023627762633600405_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_10023627762633600405")
|
||
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_10023627762633600405")
|
||
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>Wich of the following is a valid <code>Julia</code> expression for</p>
|
||
<p><span class="math display">\[
|
||
\frac{3\cdot2}{4}
|
||
\]</span></p>
|
||
<p>that uses the least number of parentheses?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="57">
|
||
<div class="cell-output cell-output-display" data-execution_count="58">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="18440110962319229672" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_18440110962319229672">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_18440110962319229672_1">
|
||
<input class="form-check-input" type="radio" name="radio_18440110962319229672" id="radio_18440110962319229672_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
<code>(3 * 2) / 4</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_18440110962319229672_2">
|
||
<input class="form-check-input" type="radio" name="radio_18440110962319229672" id="radio_18440110962319229672_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
<code>3 * 2 / 4</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="18440110962319229672_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_18440110962319229672"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 2;
|
||
var msgBox = document.getElementById('18440110962319229672_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_18440110962319229672")
|
||
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_18440110962319229672")
|
||
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>Which of the following is a valid <code>Julia</code> expression for</p>
|
||
<p><span class="math display">\[
|
||
2^{4 - 2}
|
||
\]</span></p>
|
||
<p>that uses the least number of parentheses?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="58">
|
||
<div class="cell-output cell-output-display" data-execution_count="59">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12355429249813448621" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_12355429249813448621">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_12355429249813448621_1">
|
||
<input class="form-check-input" type="radio" name="radio_12355429249813448621" id="radio_12355429249813448621_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
<code>(2 ^ 4) - 2</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_12355429249813448621_2">
|
||
<input class="form-check-input" type="radio" name="radio_12355429249813448621" id="radio_12355429249813448621_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
<code>2 ^ 4 - 2</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_12355429249813448621_3">
|
||
<input class="form-check-input" type="radio" name="radio_12355429249813448621" id="radio_12355429249813448621_3" value="3">
|
||
|
||
<span class="label-body px-1">
|
||
<code>2 ^ (4 - 2)</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="12355429249813448621_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_12355429249813448621"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 3;
|
||
var msgBox = document.getElementById('12355429249813448621_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_12355429249813448621")
|
||
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_12355429249813448621")
|
||
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>In the U.S. version of the Office, the opening credits include a calculator calculation. The key sequence shown is <code>9653 +</code> which produces <code>11532</code>. What value was added to?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="59">
|
||
<div class="cell-output cell-output-display" data-execution_count="60">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="17571760457252579329" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_17571760457252579329">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="17571760457252579329" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="17571760457252579329_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("17571760457252579329").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 1879) <= 0);
|
||
var msgBox = document.getElementById('17571760457252579329_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_17571760457252579329")
|
||
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_17571760457252579329")
|
||
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 saw that <code>1 / 2 / 3 / 4 / 5 / 6</code> is about <span class="math inline">\(14\)</span> divided by <span class="math inline">\(10,000\)</span>. But what would be a more familiar expression representing it:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="60">
|
||
<div class="cell-output cell-output-display" data-execution_count="61">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="7698305173923872613" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_7698305173923872613">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_7698305173923872613_1">
|
||
<input class="form-check-input" type="radio" name="radio_7698305173923872613" id="radio_7698305173923872613_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
<code>1 / (2 / 3 / 4 / 5 / 6)</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_7698305173923872613_2">
|
||
<input class="form-check-input" type="radio" name="radio_7698305173923872613" id="radio_7698305173923872613_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
<code>1 /(2 * 3 * 4 * 5 * 6)</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_7698305173923872613_3">
|
||
<input class="form-check-input" type="radio" name="radio_7698305173923872613" id="radio_7698305173923872613_3" value="3">
|
||
|
||
<span class="label-body px-1">
|
||
<code>1 / 2 * 3 / 4 * 5 / 6</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="7698305173923872613_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_7698305173923872613"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 2;
|
||
var msgBox = document.getElementById('7698305173923872613_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_7698305173923872613")
|
||
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_7698305173923872613")
|
||
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>One of these three expressions will produce a different answer, select that one:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="61">
|
||
<div class="cell-output cell-output-display" data-execution_count="62">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15429816645145978467" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_15429816645145978467">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_15429816645145978467_1">
|
||
<input class="form-check-input" type="radio" name="radio_15429816645145978467" id="radio_15429816645145978467_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
<code>2 - (3 - 4)</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_15429816645145978467_2">
|
||
<input class="form-check-input" type="radio" name="radio_15429816645145978467" id="radio_15429816645145978467_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
<code>2 - 3 - 4</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_15429816645145978467_3">
|
||
<input class="form-check-input" type="radio" name="radio_15429816645145978467" id="radio_15429816645145978467_3" value="3">
|
||
|
||
<span class="label-body px-1">
|
||
<code>(2 - 3) - 4</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="15429816645145978467_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_15429816645145978467"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 1;
|
||
var msgBox = document.getElementById('15429816645145978467_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_15429816645145978467")
|
||
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_15429816645145978467")
|
||
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>One of these three expressions will produce a different answer, select that one:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="62">
|
||
<div class="cell-output cell-output-display" data-execution_count="63">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="1379452153948947462" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_1379452153948947462">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_1379452153948947462_1">
|
||
<input class="form-check-input" type="radio" name="radio_1379452153948947462" id="radio_1379452153948947462_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
<code>2 - 3 * 4</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_1379452153948947462_2">
|
||
<input class="form-check-input" type="radio" name="radio_1379452153948947462" id="radio_1379452153948947462_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
<code>(2 - 3) * 4</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_1379452153948947462_3">
|
||
<input class="form-check-input" type="radio" name="radio_1379452153948947462" id="radio_1379452153948947462_3" value="3">
|
||
|
||
<span class="label-body px-1">
|
||
<code>2 - (3 * 4)</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="1379452153948947462_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_1379452153948947462"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 2;
|
||
var msgBox = document.getElementById('1379452153948947462_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_1379452153948947462")
|
||
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_1379452153948947462")
|
||
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>One of these three expressions will produce a different answer, select that one:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="63">
|
||
<div class="cell-output cell-output-display" data-execution_count="64">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="5956212521609482646" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_5956212521609482646">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_5956212521609482646_1">
|
||
<input class="form-check-input" type="radio" name="radio_5956212521609482646" id="radio_5956212521609482646_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
<code>-(1^2)</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_5956212521609482646_2">
|
||
<input class="form-check-input" type="radio" name="radio_5956212521609482646" id="radio_5956212521609482646_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
<code>(-1)^2</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_5956212521609482646_3">
|
||
<input class="form-check-input" type="radio" name="radio_5956212521609482646" id="radio_5956212521609482646_3" value="3">
|
||
|
||
<span class="label-body px-1">
|
||
<code>-1^2</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="5956212521609482646_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_5956212521609482646"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 2;
|
||
var msgBox = document.getElementById('5956212521609482646_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_5956212521609482646")
|
||
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_5956212521609482646")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
})});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="question-16" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question-16">Question</h6>
|
||
<p>What is the value of <span class="math inline">\(\sin(\pi/10)\)</span>?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="64">
|
||
<div class="cell-output cell-output-display" data-execution_count="65">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="14893863811303484595" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_14893863811303484595">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="14893863811303484595" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="14893863811303484595_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("14893863811303484595").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 0.3090169943749474) <= 0.001);
|
||
var msgBox = document.getElementById('14893863811303484595_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_14893863811303484595")
|
||
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_14893863811303484595")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="question-17" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question-17">Question</h6>
|
||
<p>What is the value of <span class="math inline">\(\sin(52^\circ)\)</span>?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="65">
|
||
<div class="cell-output cell-output-display" data-execution_count="66">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="4396089115720893649" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_4396089115720893649">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="4396089115720893649" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="4396089115720893649_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("4396089115720893649").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 0.788010753606722) <= 0.001);
|
||
var msgBox = document.getElementById('4396089115720893649_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_4396089115720893649")
|
||
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_4396089115720893649")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="question-18" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question-18">Question</h6>
|
||
<p>What is the value of</p>
|
||
<p><span class="math display">\[
|
||
\frac{\sin(\pi/3) - 1/2}{\pi/3 - \pi/6}
|
||
\]</span></p>
|
||
<div class="cell" data-hold="true" data-execution_count="66">
|
||
<div class="cell-output cell-output-display" data-execution_count="67">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="164216896582943501" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_164216896582943501">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="164216896582943501" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="164216896582943501_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("164216896582943501").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 0.6990570277140041) <= 0.001);
|
||
var msgBox = document.getElementById('164216896582943501_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_164216896582943501")
|
||
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_164216896582943501")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="question-19" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question-19">Question</h6>
|
||
<p>Is <span class="math inline">\(\sin^{-1}(\sin(3\pi/2))\)</span> equal to <span class="math inline">\(3\pi/2\)</span>? (The “arc” functions do no use power notation, but instead a prefix of <code>a</code>.)</p>
|
||
<div class="cell" data-hold="true" data-execution_count="67">
|
||
<div class="cell-output cell-output-display" data-execution_count="68">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="8497864351667106703" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_8497864351667106703">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_8497864351667106703_1">
|
||
<input class="form-check-input" type="radio" name="radio_8497864351667106703" id="radio_8497864351667106703_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
Yes
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_8497864351667106703_2">
|
||
<input class="form-check-input" type="radio" name="radio_8497864351667106703" id="radio_8497864351667106703_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
No
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="8497864351667106703_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_8497864351667106703"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 2;
|
||
var msgBox = document.getElementById('8497864351667106703_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_8497864351667106703")
|
||
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_8497864351667106703")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
})});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="question-20" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question-20">Question</h6>
|
||
<p>What is the value of <code>round(3.5000)</code></p>
|
||
<div class="cell" data-hold="true" data-execution_count="68">
|
||
<div class="cell-output cell-output-display" data-execution_count="69">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="2323513532852177524" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_2323513532852177524">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="2323513532852177524" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="2323513532852177524_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("2323513532852177524").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 4.0) <= 0.001);
|
||
var msgBox = document.getElementById('2323513532852177524_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_2323513532852177524")
|
||
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_2323513532852177524")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="question-21" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question-21">Question</h6>
|
||
<p>What is the value of <code>sqrt(32 - 12)</code></p>
|
||
<div class="cell" data-hold="true" data-execution_count="69">
|
||
<div class="cell-output cell-output-display" data-execution_count="70">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="14845492953366631681" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_14845492953366631681">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="14845492953366631681" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="14845492953366631681_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("14845492953366631681").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 4.47213595499958) <= 0.001);
|
||
var msgBox = document.getElementById('14845492953366631681_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_14845492953366631681")
|
||
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_14845492953366631681")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="question-22" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question-22">Question</h6>
|
||
<p>Which is greater <span class="math inline">\(e^\pi\)</span> or <span class="math inline">\(\pi^e\)</span>?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="70">
|
||
<div class="cell-output cell-output-display" data-execution_count="71">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="16804406941609178675" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_16804406941609178675">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_16804406941609178675_1">
|
||
<input class="form-check-input" type="radio" name="radio_16804406941609178675" id="radio_16804406941609178675_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
\(e^{\pi}\)
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_16804406941609178675_2">
|
||
<input class="form-check-input" type="radio" name="radio_16804406941609178675" id="radio_16804406941609178675_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
\(\pi^{e}\)
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="16804406941609178675_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_16804406941609178675"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 1;
|
||
var msgBox = document.getElementById('16804406941609178675_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_16804406941609178675")
|
||
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_16804406941609178675")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
})});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="question-23" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question-23">Question</h6>
|
||
<p>What is the value of <span class="math inline">\(\pi - (x - \sin(x)/\cos(x))\)</span> when <span class="math inline">\(x=3\)</span>?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="71">
|
||
<div class="cell-output cell-output-display" data-execution_count="72">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12550700429177536758" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_12550700429177536758">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="12550700429177536758" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="12550700429177536758_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("12550700429177536758").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - -0.0009538894844847157) <= 0.001);
|
||
var msgBox = document.getElementById('12550700429177536758_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_12550700429177536758")
|
||
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_12550700429177536758")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="question-24" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question-24">Question</h6>
|
||
<p>Factorials in <code>Julia</code> are computed with the function <code>factorial</code>, not the postfix operator <code>!</code>, as with math notation. What is <span class="math inline">\(10!\)</span>?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="72">
|
||
<div class="cell-output cell-output-display" data-execution_count="73">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="2083526272488018226" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_2083526272488018226">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="2083526272488018226" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="2083526272488018226_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("2083526272488018226").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 3628800) <= 0);
|
||
var msgBox = document.getElementById('2083526272488018226_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_2083526272488018226")
|
||
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_2083526272488018226")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="question-25" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question-25">Question</h6>
|
||
<p>Will <code>-2^2</code> produce <code>4</code> (which is a unary <code>-</code> evaluated <em>before</em> <code>^</code>) or <code>-4</code> (which is a unary <code>-</code> evaluated <em>after</em> <code>^</code>)?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="73">
|
||
<div class="cell-output cell-output-display" data-execution_count="74">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="1167687326368844214" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_1167687326368844214">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_1167687326368844214_1">
|
||
<input class="form-check-input" type="radio" name="radio_1167687326368844214" id="radio_1167687326368844214_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
<code>-4</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_1167687326368844214_2">
|
||
<input class="form-check-input" type="radio" name="radio_1167687326368844214" id="radio_1167687326368844214_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
<code>4</code>
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="1167687326368844214_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_1167687326368844214"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 1;
|
||
var msgBox = document.getElementById('1167687326368844214_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_1167687326368844214")
|
||
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_1167687326368844214")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
})});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="question-26" class="level6">
|
||
<h6 class="anchored" data-anchor-id="question-26">Question</h6>
|
||
<p>A twitter post from popular mechanics generated some attention.</p>
|
||
<p><img src="https://raw.githubusercontent.com/jverzani/CalculusWithJuliaNotes.jl/master/CwJ/precalc/figures/order_operations_pop_mech.png" class="img-fluid"></p>
|
||
<p>What is the answer?</p>
|
||
<div class="cell" data-hold="true" data-execution_count="74">
|
||
<div class="cell-output cell-output-display" data-execution_count="75">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="14333996359859469606" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_14333996359859469606">
|
||
<div style="padding-top: 5px">
|
||
<br>
|
||
<div class="input-group">
|
||
<input id="14333996359859469606" type="number" class="form-control" placeholder="Numeric answer">
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="14333996359859469606_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.getElementById("14333996359859469606").addEventListener("change", function() {
|
||
var correct = (Math.abs(this.value - 16.0) <= 0.001);
|
||
var msgBox = document.getElementById('14333996359859469606_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_14333996359859469606")
|
||
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_14333996359859469606")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
<p>Does this expression return the <em>correct</em> answer using proper order of operations?</p>
|
||
<div class="cell" data-execution_count="75">
|
||
<div class="sourceCode cell-code" id="cb83"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb83-1"><a href="#cb83-1" aria-hidden="true" tabindex="-1"></a><span class="fl">8</span><span class="fu">÷2</span>(<span class="fl">2</span><span class="op">+</span><span class="fl">2</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="76">
|
||
<pre><code>1</code></pre>
|
||
</div>
|
||
</div>
|
||
<div class="cell" data-hold="true" data-execution_count="76">
|
||
<div class="cell-output cell-output-display" data-execution_count="77">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="13533218097412710615" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_13533218097412710615">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_13533218097412710615_1">
|
||
<input class="form-check-input" type="radio" name="radio_13533218097412710615" id="radio_13533218097412710615_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
Yes
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_13533218097412710615_2">
|
||
<input class="form-check-input" type="radio" name="radio_13533218097412710615" id="radio_13533218097412710615_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
No
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="13533218097412710615_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_13533218097412710615"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 2;
|
||
var msgBox = document.getElementById('13533218097412710615_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_13533218097412710615")
|
||
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_13533218097412710615")
|
||
if (explanation != null) {
|
||
explanation.style.display = "block";
|
||
}
|
||
}
|
||
|
||
})});
|
||
|
||
</script>
|
||
</div>
|
||
</div>
|
||
<p>Why or why not:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="77">
|
||
<div class="cell-output cell-output-display" data-execution_count="78">
|
||
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="16368328513073304139" data-controltype="">
|
||
<div class="form-group ">
|
||
<div class="controls">
|
||
<div class="form" id="controls_16368328513073304139">
|
||
<div style="padding-top: 5px">
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_16368328513073304139_1">
|
||
<input class="form-check-input" type="radio" name="radio_16368328513073304139" id="radio_16368328513073304139_1" value="1">
|
||
|
||
<span class="label-body px-1">
|
||
Of course it is correct.
|
||
</span>
|
||
</label>
|
||
</div>
|
||
<div class="form-check">
|
||
<label class="form-check-label" for="radio_16368328513073304139_2">
|
||
<input class="form-check-input" type="radio" name="radio_16368328513073304139" id="radio_16368328513073304139_2" value="2">
|
||
|
||
<span class="label-body px-1">
|
||
The precedence of numeric literal coefficients used for implicit multiplication is higher than other binary operators such as multiplication (<code>*</code>), and division (<code>/</code>, <code>\</code>, and <code>//</code>)
|
||
</span>
|
||
</label>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div id="16368328513073304139_message" style="padding-bottom: 15px"></div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script text="text/javascript">
|
||
document.querySelectorAll('input[name="radio_16368328513073304139"]').forEach(function(rb) {
|
||
rb.addEventListener("change", function() {
|
||
var correct = rb.value == 2;
|
||
var msgBox = document.getElementById('16368328513073304139_message');
|
||
if(correct) {
|
||
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
||
var explanation = document.getElementById("explanation_16368328513073304139")
|
||
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_16368328513073304139")
|
||
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="../index.html" class="pagination-link">
|
||
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text">Preface</span>
|
||
</a>
|
||
</div>
|
||
<div class="nav-page nav-page-next">
|
||
<a href="../precalc/variables.html" class="pagination-link">
|
||
<span class="nav-page-text"><span class="chapter-number">2</span> <span class="chapter-title">Variables</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> |