CalculusWithJuliaNotes.jl/quarto/0e7f54ed/precalc/vectors.html

2527 lines
321 KiB
HTML
Raw Normal View History

2022-08-11 19:15:19 +02:00
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.0.32">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>Calculus with Julia - 5&nbsp; Vectors</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/ranges.html" rel="next">
<link href="../precalc/logical_expressions.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">5</span>&nbsp; <span class="chapter-title">Vectors</span></h1>
<button type="button" class="quarto-btn-toggle btn" aria-label="Show secondary navigation">
<i class="bi bi-chevron-right"></i>
</button>
</div>
</nav>
</header>
<!-- content -->
<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar">
<!-- sidebar -->
<nav id="quarto-sidebar" class="sidebar collapse sidebar-navigation floating overflow-auto">
<div class="mt-2 flex-shrink-0 align-items-center">
<div class="sidebar-search">
<div id="quarto-search" class="" title="Search"></div>
</div>
</div>
<div class="sidebar-menu-container">
<ul class="list-unstyled mt-1">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../index.html" class="sidebar-item-text sidebar-link">Preface</a>
</div>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="true">Precalculus Concepts</a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="true">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/calculator.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">From calculator to computer</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/variables.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Variables</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/numbers_types.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Number systems</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/logical_expressions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Inequalities, Logical expressions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/vectors.html" class="sidebar-item-text sidebar-link active"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Vectors</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/ranges.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">6</span>&nbsp; <span class="chapter-title">Ranges and Sets</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">7</span>&nbsp; <span class="chapter-title">Functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">The Graph of a Function</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/transformations.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Function manipulations</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/inversefunctions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">The Inverse of a Function</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/polynomial.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Polynomials</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/polynomial_roots.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">12</span>&nbsp; <span class="chapter-title">Roots of a polynomial</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/polynomials_package.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">13</span>&nbsp; <span class="chapter-title">The Polynomials package</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/rational_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">14</span>&nbsp; <span class="chapter-title">Rational functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/exp_log_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">15</span>&nbsp; <span class="chapter-title">Exponential and logarithmic functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/trig_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">16</span>&nbsp; <span class="chapter-title">Trigonometric functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/julia_overview.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">17</span>&nbsp; <span class="chapter-title">Overview of Julia commands</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" aria-expanded="false">Limits</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-2" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/limits.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">18</span>&nbsp; <span class="chapter-title">Limits</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/limits_extensions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">19</span>&nbsp; <span class="chapter-title">Limits, issues, extensions of the concept</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/continuity.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">20</span>&nbsp; <span class="chapter-title">Continuity</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/intermediate_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">21</span>&nbsp; <span class="chapter-title">Implications of continuity</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="false">Derivatives</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-3" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">22</span>&nbsp; <span class="chapter-title">Derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/numeric_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">23</span>&nbsp; <span class="chapter-title">Numeric derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/symbolic_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">24</span>&nbsp; <span class="chapter-title">Symbolic derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/mean_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">25</span>&nbsp; <span class="chapter-title">The mean value theorem for differentiable functions.</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/optimization.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">26</span>&nbsp; <span class="chapter-title">Optimization</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/first_second_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">27</span>&nbsp; <span class="chapter-title">The first and second derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/curve_sketching.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">28</span>&nbsp; <span class="chapter-title">Curve Sketching</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/linearization.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">29</span>&nbsp; <span class="chapter-title">Linearization</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/newtons_method.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">30</span>&nbsp; <span class="chapter-title">Newtons method</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/more_zeros.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">31</span>&nbsp; <span class="chapter-title">Derivative-free alternatives to Newtons method</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/lhospitals_rule.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">32</span>&nbsp; <span class="chapter-title">LHospitals Rule</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/implicit_differentiation.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">33</span>&nbsp; <span class="chapter-title">Implicit Differentiation</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/related_rates.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">34</span>&nbsp; <span class="chapter-title">Related rates</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/taylor_series_polynomials.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">35</span>&nbsp; <span class="chapter-title">Taylor Polynomials and other Approximating Polynomials</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-4" aria-expanded="false">Integrals</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-4" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-4" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/area.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">36</span>&nbsp; <span class="chapter-title">Area under a curve</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/ftc.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">37</span>&nbsp; <span class="chapter-title">Fundamental Theorem or Calculus</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/substitution.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">38</span>&nbsp; <span class="chapter-title">Substitution</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/integration_by_parts.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">39</span>&nbsp; <span class="chapter-title">Integration By Parts</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/partial_fractions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">40</span>&nbsp; <span class="chapter-title">Partial Fractions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/improper_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">41</span>&nbsp; <span class="chapter-title">Improper Integrals</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/mean_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">42</span>&nbsp; <span class="chapter-title">Mean value theorem for integrals</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/area_between_curves.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">43</span>&nbsp; <span class="chapter-title">Area between two curves</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/center_of_mass.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">44</span>&nbsp; <span class="chapter-title">Center of Mass</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/volumes_slice.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">45</span>&nbsp; <span class="chapter-title">Volumes by slicing</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/arc_length.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">46</span>&nbsp; <span class="chapter-title">Arc length</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/surface_area.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">47</span>&nbsp; <span class="chapter-title">Surface Area</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-5" aria-expanded="false">ODEs</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-5" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-5" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../ODEs/odes.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">48</span>&nbsp; <span class="chapter-title">ODEs</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../ODEs/euler.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">49</span>&nbsp; <span class="chapter-title">Eulers method</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../ODEs/solve.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">50</span>&nbsp; <span class="chapter-title">The problem-algorithm-solve interface</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../ODEs/differential_equations.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">51</span>&nbsp; <span class="chapter-title">The <code>DifferentialEquations</code> suite</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-6" aria-expanded="false">Differential vector calculus</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-6" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-6" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/polar_coordinates.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">52</span>&nbsp; <span class="chapter-title">Polar Coordinates and Curves</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/vectors.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">53</span>&nbsp; <span class="chapter-title">Vectors and matrices</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/vector_valued_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">54</span>&nbsp; <span class="chapter-title">Vector-valued functions, <span class="math inline">\(f:R \rightarrow R^n\)</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/scalar_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">55</span>&nbsp; <span class="chapter-title">Scalar functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/scalar_functions_applications.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">56</span>&nbsp; <span class="chapter-title">Applications with scalar functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/vector_fields.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">57</span>&nbsp; <span class="chapter-title">Functions <span class="math inline">\(R^n \rightarrow R^m\)</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/plots_plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">58</span>&nbsp; <span class="chapter-title">2D and 3D plots in Julia with Plots</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-7" aria-expanded="false">Integral vector calculus</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-7" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-7" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/double_triple_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">59</span>&nbsp; <span class="chapter-title">Multi-dimensional integrals</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/line_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">60</span>&nbsp; <span class="chapter-title">Line and Surface Integrals</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/div_grad_curl.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">61</span>&nbsp; <span class="chapter-title">The Gradient, Divergence, and Curl</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/stokes_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">62</span>&nbsp; <span class="chapter-title">Greens Theorem, Stokes Theorem, and the Divergence Theorem</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/review.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">63</span>&nbsp; <span class="chapter-title">Quick Review of Vector Calculus</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-8" aria-expanded="false">Alternatives</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-8" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-8" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../alternatives/plotly_plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">64</span>&nbsp; <span class="chapter-title">JavaScript based plotting libraries</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../alternatives/makie_plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">65</span>&nbsp; <span class="chapter-title">Calculus plots with Makie</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-9" aria-expanded="false">Appendices</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-9" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-9" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/getting_started_with_julia.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">66</span>&nbsp; <span class="chapter-title">Getting started with Julia</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/julia_interfaces.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">67</span>&nbsp; <span class="chapter-title">Julia interfaces</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/calculus_with_julia.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">68</span>&nbsp; <span class="chapter-title">The <code>CalculusWithJulia</code> package</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/unicode.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">69</span>&nbsp; <span class="chapter-title">Usages of Unicode symbols</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/quick_notes.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">70</span>&nbsp; <span class="chapter-title">Quick introduction to Calculus with Julia</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../references.html" class="sidebar-item-text sidebar-link">References</a>
</div>
</li>
</ul>
</div>
</nav>
<!-- margin-sidebar -->
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
<nav id="TOC" role="doc-toc">
<h2 id="toc-title">Table of contents</h2>
<ul>
<li><a href="#vectors-in-julia" id="toc-vectors-in-julia" class="nav-link active" data-scroll-target="#vectors-in-julia"> <span class="header-section-number">5.1</span> Vectors in Julia</a></li>
<li><a href="#higher-dimensional-vectors" id="toc-higher-dimensional-vectors" class="nav-link" data-scroll-target="#higher-dimensional-vectors"> <span class="header-section-number">5.2</span> Higher dimensional vectors</a></li>
<li><a href="#indexing" id="toc-indexing" class="nav-link" data-scroll-target="#indexing"> <span class="header-section-number">5.3</span> Indexing</a>
<ul class="collapse">
<li><a href="#assignment-and-indexing" id="toc-assignment-and-indexing" class="nav-link" data-scroll-target="#assignment-and-indexing"> <span class="header-section-number">5.3.1</span> Assignment and indexing</a></li>
</ul></li>
<li><a href="#some-useful-functions-for-working-with-vectors." id="toc-some-useful-functions-for-working-with-vectors." class="nav-link" data-scroll-target="#some-useful-functions-for-working-with-vectors."> <span class="header-section-number">5.4</span> Some useful functions for working with vectors.</a></li>
<li><a href="#applying-functions-element-by-element-to-values-in-a-vector" id="toc-applying-functions-element-by-element-to-values-in-a-vector" class="nav-link" data-scroll-target="#applying-functions-element-by-element-to-values-in-a-vector"> <span class="header-section-number">5.5</span> Applying functions element by element to values in a vector</a>
<ul class="collapse">
<li><a href="#broadcasting-a-function-call" id="toc-broadcasting-a-function-call" class="nav-link" data-scroll-target="#broadcasting-a-function-call"> <span class="header-section-number">5.5.1</span> Broadcasting a function call</a></li>
<li><a href="#comprehensions" id="toc-comprehensions" class="nav-link" data-scroll-target="#comprehensions"> <span class="header-section-number">5.5.2</span> Comprehensions</a></li>
</ul></li>
<li><a href="#other-container-types" id="toc-other-container-types" class="nav-link" data-scroll-target="#other-container-types"> <span class="header-section-number">5.6</span> Other container types</a></li>
<li><a href="#questions" id="toc-questions" class="nav-link" data-scroll-target="#questions"> <span class="header-section-number">5.7</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/vectors.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">5</span>&nbsp; <span class="chapter-title">Vectors</span></h1>
</div>
<div class="quarto-title-meta">
</div>
</header>
<p>One of the first models learned in physics are the equations governing the laws of motion with constant acceleration: <span class="math inline">\(x(t) = x_0 + v_0 t + 1/2 \cdot a t^2\)</span>. This is a consequence of Newtons second <a href="http://tinyurl.com/8ylk29t">law</a> of motion applied to the constant acceleration case. A related formula for the velocity is <span class="math inline">\(v(t) = v_0 + at\)</span>. The following figure is produced using these formulas applied to both the vertical position and the horizontal position:</p>
<div class="cell" data-hold="true" data-execution_count="3">
<div class="cell-output cell-output-display" data-execution_count="4">
<div class="d-flex justify-content-center"> <figure class="figure"> <img src="data:image/gif;base64,R0lGODlhAANAAvcAAAD/AAICAgKAAgYGBgkJCQuECw4ODg+h+hERERJEYhSIExYVFRaj+Rik+hql+hsbGxyNHBym+iCn+iEhISWSJSWp+iYmJiic6isrKyus+i8vLzGu+zIyMjOV0TU1NTWbNjg4ODix+jw8PDydPD1tjUC0+kGW3UJCQkRfBUe3+0pKSk1NTU5LBU5OTk6nTk+Bu0+6+1BQUFJSUlNTU1RUVFVVVVWqVVdVVFe9+1hYWFxcXFyQr16/+19fX2CLxmNjY2O0e2SxZGTC+2Wq42ezZ2pqamtvpmvE+28XCHA6J3BDRXBwcHK5cnTI/HU/LHV1dXWw43W16HlDMHl5eXtqm3t7e3x8fHx9fXylv3y+fH1HNH3M/H6/fn9/f4CAgICCgIODg4TBhIVunIaGhoa/5IbP/YdRPoeHh4lTQImJiYqKiouLi4yEroyMjI1oX42+6Y3E743GjY3S/I6Ojo9ZRpCQkJGRkZOTk5TJlJVfTJZgTZaWlpbV/JlrkZqampzX/J1Xe5+fn6CQs6DZ/aKioqOjo6OmyKSkpKTRpadFZadjhKenp6fc/aqpqaurq6ze/K2tra3XrbCwsLCxs7Ozs7Ph/bXatbe4uLu7u7vk/byEnby8vL6+vr/fv8A+VsHBwcJWbcNpgM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yQYx8DHSWMv1jM8nJ0KmcwwYf+MYqgGGNcqDjGMCoBzgi99GZDhWkR
<figcaption class="figure-caption"><div class="markdown"><p>Position, velocity, and acceleration vectors (scaled) for projectile motion. Vectors are drawn with tail on the projectile. The position vector (black) points from the origin to the projectile, the velocity vector (red) is in the direction of the trajectory, and the acceleration vector (green) is a constant pointing downward.</p>
</div> </figcaption>
</figure>
</div>
</div>
</div>
<p>For the motion in the above figure, the objects <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span> values change according to the same rule, but, as the acceleration is different in each direction, we get different formula, namely: <span class="math inline">\(x(t) = x_0 + v_{0x} t\)</span> and <span class="math inline">\(y(t) = y_0 + v_{0y}t - 1/2 \cdot gt^2\)</span>.</p>
<p>It is common to work with <em>both</em> formulas at once. Mathematically, when graphing, we naturally pair off two values using Cartesian coordinates (e.g., <span class="math inline">\((x,y)\)</span>). Another means of combining related values is to use a <em>vector</em>. The notation for a vector varies, but to distinguish them from a point we will use <span class="math inline">\(\langle x,~ y\rangle\)</span>. With this notation, we can use it to represent the position, the velocity, and the acceleration at time <span class="math inline">\(t\)</span> through:</p>
<p><span class="math display">\[
\begin{align}
\vec{x} &amp;= \langle x_0 + v_{0x}t,~ -(1/2) g t^2 + v_{0y}t + y_0 \rangle,\\
\vec{v} &amp;= \langle v_{0x},~ -gt + v_{0y} \rangle, \text{ and }\\
\vec{a} &amp;= \langle 0,~ -g \rangle.
\end{align}
\]</span></p>
<p>Dont spend time thinking about the formulas if they are unfamiliar. The point emphasized here is that we have used the notation <span class="math inline">\(\langle x,~ y \rangle\)</span> to collect the two values into a single object, which we indicate through a label on the variable name. These are vectors, and we shall see they find use far beyond this application.</p>
<p>Initially, our primary use of vectors will be as containers, but it is worthwhile to spend some time to discuss properties of vectors and their visualization.</p>
<p>A line segment in the plane connects two points <span class="math inline">\((x_0, y_0)\)</span> and <span class="math inline">\((x_1, y_1)\)</span>. The length of a line segment (its magnitude) is given by the distance formula <span class="math inline">\(\sqrt{(x_1 - x_0)^2 + (y_1 - y_0)^2}\)</span>. A line segment can be given a direction by assigning an initial point and a terminal point. A directed line segment has both a direction and a magnitude. A vector is an abstraction where just these two properties <span class="math inline">\(-\)</span> a <strong>direction</strong> and a <strong>magnitude</strong> <span class="math inline">\(-\)</span> are intrinsic. While a directed line segment can be represented by a vector, a single vector describes all such line segments found by translation. That is, how the the vector is located when visualized is for convenience, it is not a characteristic of the vector. In the figure above, all vectors are drawn with their tails at the position of the projectile over time.</p>
<p>We can visualize a (two-dimensional) vector as an arrow in space. This arrow has two components. We represent a vector mathematically as <span class="math inline">\(\langle x,~ y \rangle\)</span>. For example, the vector connecting the point <span class="math inline">\((x_0, y_0)\)</span> to <span class="math inline">\((x_1, y_1)\)</span> is <span class="math inline">\(\langle x_1 - x_0,~ y_1 - y_0 \rangle\)</span>.</p>
<p>The magnitude of a vector comes from the distance formula applied to a line segment, and is <span class="math inline">\(\| \vec{v} \| = \sqrt{x^2 + y^2}\)</span>.</p>
<div class="cell" data-hold="true" data-execution_count="4">
<div class="cell-output cell-output-display" data-execution_count="5">
<div class="d-flex justify-content-center"> <figure class="figure"> <img src="data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAwAAAAJACAIAAAC1zJYBAAAABmJLR0QA/wD/AP+gvaeTAAAgAElEQVR4nO3deXRTdf7/8XeSpi1dpFCQ3WFREa0eVhkLCCIyfkFFllEQwVFRFpfDD8eR0QFEUZxxAAcG/cqoXxy0A7TAAC6IICqKgiyVRYGhQFnL1kJpapc0+f0RjJ1QmjTNzecuz8eZ40nKbfKGOPXF+3VvYvN6vQIAAGAldtUDAAAARBsBCAAAWA4BCAAAWA4BCAAAWA4BCAAAWA4BCAAAWA4BCAAAWA4BCAAAWA4BCAAAWA4BCAAAWI6aADRixIiwv7e0tJSP77Cm8vLyiooK1VNAgYqKivLyctVTQI2SkhLVI0ANrV96NQFo6dKlYX+v2+2O4CQwEI/H4/F4VE8BBbxeL9nXsviZb1lav/RUYAAAwHIIQAAAwH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asWdOvXz/fh3P1799/zZo1EZsOCLB/v7RvLw8+yHVeAIDaiMA7Qefl5XXp0sV3u1GjRseOHQv6LRUVFaNGjfLfnTlzZmxsbIhPV1JSYrfb+TBUC3Jv3Jh0662em24qO3RI6tWTkhLVEyFKfB+GqnoKqFFSUmKCD/RFNbxeyc+3nTlz4Z9nztjy823ffmuvVy/mjTfC/DnvcDiCfnJ2BP6tcjqd/p9N5eXlcXFxQb/FZrPddttt/rvx8fEOhyP0p3M6nQQgC/J06VK2Y
<figcaption class="figure-caption"><div class="markdown"><p>A vector and its unit vector. They share the same direction, but the unit vector has a standardized magnitude.</p>
</div> </figcaption>
</figure>
</div>
</div>
</div>
<p>We call the values <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span> of the vector <span class="math inline">\(\vec{v} = \langle x,~ y \rangle\)</span> the components of the <span class="math inline">\(v\)</span>.</p>
<p>Two operations on vectors are fundamental.</p>
<ul>
<li>Vectors can be multiplied by a scalar (a real number): <span class="math inline">\(c\vec{v} = \langle cx,~ cy \rangle\)</span>. Geometrically this scales the vector by a factor of <span class="math inline">\(\lvert c \rvert\)</span> and switches the direction of the vector by <span class="math inline">\(180\)</span> degrees (in the <span class="math inline">\(2\)</span>-dimensional case) when <span class="math inline">\(c &lt; 0\)</span>. A <em>unit vector</em> is one with magnitude <span class="math inline">\(1\)</span>, and, except for the <span class="math inline">\(\vec{0}\)</span> vector, can be formed from <span class="math inline">\(\vec{v}\)</span> by dividing <span class="math inline">\(\vec{v}\)</span> by its magnitude. A vectors two parts are summarized by its direction given by a unit vector <strong>and</strong> its magnitude given by the norm.</li>
<li>Vectors can be added: <span class="math inline">\(\vec{v} + \vec{w} = \langle v_x + w_x,~ v_y + w_y \rangle\)</span>. That is, each corresponding component adds to form a new vector. Similarly for subtraction. The <span class="math inline">\(\vec{0}\)</span> vector then would be just <span class="math inline">\(\langle 0,~ 0 \rangle\)</span> and would satisfy <span class="math inline">\(\vec{0} + \vec{v} = \vec{v}\)</span> for any vector <span class="math inline">\(\vec{v}\)</span>. Vector addition, <span class="math inline">\(\vec{v} + \vec{w}\)</span>, is visualized by placing the tail of <span class="math inline">\(\vec{w}\)</span> at the tip of <span class="math inline">\(\vec{v}\)</span> and then considering the new vector with tail coming from <span class="math inline">\(\vec{v}\)</span> and tip coming from the position of the tip of <span class="math inline">\(\vec{w}\)</span>. Subtraction is different, place both the tails of <span class="math inline">\(\vec{v}\)</span> and <span class="math inline">\(\vec{w}\)</span> at the same place and the new vector has tail at the tip of <span class="math inline">\(\vec{v}\)</span> and tip at the tip of <span class="math inline">\(\vec{w}\)</span>.</li>
</ul>
<div class="cell" data-hold="true" data-execution_count="5">
<div class="cell-output cell-output-display" data-execution_count="6">
<div class="d-flex justify-content-center"> <figure class="figure"> <img src="data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAwAAAAJACAIAAAC1zJYBAAAABmJLR0QA/wD/AP+gvaeTAAAgAElEQVR4nOzdf0DN9////1vntIN2xMtML8y8UPImzWtbK0ZKv4hEfjTmR/N7qBfbPq/5OWyv18s0xnuvvfzKr3lZITJSYm0UM6PUjKTCu5dh0leWxqFzTt8/8rJfKDnn3M85z9vlr+VdPa/v9/vIrfPr4VBVVQUiIiIiJVFJBxARERFZGgcQERERKQ4HEBERESkOBxAREREpDgcQERERKQ4HEBERESkOBxAREREpDgcQERERKQ4HEBERESkOBxAREREpjlkG0OjRo41GY92+1mg03rlzx7Q9ZFvu3LlT59sP2QedTiedQMJ4G1A4g8FQWVlp1kuYZQDt2LHjcY4Y0+v1Jowhm2MwGHhEncLxhwDxNqBwRqPR3L8J8yEwIiIiUhwOICIiIlIcDiAiIiJSHA4gIiIiUhwOICIiIlIcDiAiIiJSHA4gIiIiUhwOICIiIlIcDiAiIiJSnJoH0OXLl0ePHt21a9eXX3555syZFRUVFsgiIiIiMp9a3QPUr1+/devWffzxx8eOHfvrX/9q7iYiIiIis3Ks8TOaN28+ZMiQ6v8eM2bM8uXLzZxEREREZF41DyAAVVVVX3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dQkR1xAFERDUIDQ11cnJatWqVd
<figcaption class="figure-caption"><div class="markdown"><p>The sum of two vectors can be visualized by placing the tail of one at the tip of the other</p>
</div> </figcaption>
</figure>
</div>
</div>
</div>
<div class="cell" data-hold="true" data-execution_count="6">
<div class="cell-output cell-output-display" data-execution_count="7">
<div class="d-flex justify-content-center"> <figure class="figure"> <img src="data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAwAAAAJACAIAAAC1zJYBAAAABmJLR0QA/wD/AP+gvaeTAAAgAElEQVR4nOzde1zT99338Y+aJRwiCeAJaEoVZyGtNoyqBLtbuodaGx9ebAzWNUJr6VrWrNg1N8KllB5E2gJXo201Ekurjl0wC7JytWa26kPYkGiVW6pdStEw21wip58YBgkgxfuPdF0PHgCTfHN4P/+iNpDXMtF3+Sb5Tbp69SoBAAAA+JLJrAMAAAAAXA0DCAAAAHwOBhAAAAD4HAwgAAAA8DkYQAAAAOBzMIAAAADA52AAAQAAgM/BAAIAAACfgwEEAAAAPgcDCAAAAHwOgwF0+fLlrKysCX/64OCgA2OA8JA6AR5SxxoZGRkZGWFd4VWGhoZwHSTHwne9wzn7IWUwgAYHB/V6/YQ/HX8OOhweUofDQ+pYV69e/eqrr1hXeBX8FnU4PKQO5+yHFEdgAAAA4HMwgAAAAMDnYAABAACAz8EAAgAAAJ+DAQQAAAA+BwMIAAAAfA4GEAAAAPgcDCAAAADwORhAAAAA4HNuPoCOHTu2du3a+Pj4FStW/OlPf7rmbSoqKu6777777rvvejcAAAAAcB+8m96iqanppz/96fr167/88stHHnlEJBI9+OCD377B8ePH1Wr1e++9R0Q///nP58yZs2jRImf1AgAAANyymw+g3/3ud/YP7rrrruTk5Pr6+u8NoJ07dz7xxBPx8fFE9MQTT7z11lsYQAAAAODOxvEcoCtXrhw9evQnP/nJ9379s88+u+eee+wfy2Syzz77zGF1AAAAAE5w858AfUOtVt92222pqanf+/Xe3t6pU6faP546dSrHcTf9Uj09PcHBwfaPQ0JCmpubx57xcnh46dBQkl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MRisUaj6ejoOHnyZHR0dEZGhp+fn0KhMBqNrNMAAAC8k5cOoOefJ5uNdu1i3TE+sbGxNTU1NputrKysvb19/vz5oaGharW6v7+fdRoAAIBX8dIBNHkypabSpk2sOybIfjTW29urUqmqqqpEIpFUKtVqtay7AAAAvISXDiAi2r6dzGY6dox1x8QFBQUVFBSYzeampqbo6Ojs7Gz70djp06dZpwEAAHg27x1AQUG0ZIl7vh5+vGQyWU1NjdVq3bt3b29vb2xsbGhoaGZmZk9PD+s0AAAAj+S9A4iIduygkyfJbGbd4TBJSUkGg8Fms+Xm5ur1+pkzZ0ZFRRUXF4+OjrJOAwAA8CRePYCkUpo7l9atY93hYHw+Pycnx2w2nzt3LiEhobCw0N/fPzExsaGhgXUaAACAZ/DqAUREr79OH3xAXnrtrdmzZ5eXl1sslurq6qGhocTERJFIlJ6e3uVOVwIBAABwQ94+gFauJLGYNm5k3eFcq1evNhgMVqs1Ly+vsbExLCwMR2MAAAA34O0DiIiys2nnTtYRrmA/GjOZTG1tbfajMYFAIJfL6+vrWacBAAC4Fx8YQLm5NDpKOh3rDteJjIy0H43V1tYKBIJly5bZj8YuXrzIOg0AAMAt+MAAIiKlkgoKWEcwoFAo6urqbDbbK6+80tTUdNttt0kkkvz8/OHhYdZpAAAALPnGAHrjDerspCNHWHewwePxVCqV0Wg8f/68QqHQarUBAQFyufzgwYOs0wAAANjwjQEUEECJifTss6w7GJNIJDqdjuO4hoaG4ODgVatWBQYGJicnm0wm1mkAAAAu5RsDiIhKS+nMGTp7lnWHW4iPj9fr9VartaSkpKWlJTY21n40Nuil7xcAAADwPT4zgKKiSCr1jitjOMo3R
<figcaption class="figure-caption"><div class="markdown"><p>The difference of two vectors can be visualized by placing the tail of one at the tip of the other</p>
</div> </figcaption>
</figure>
</div>
</div>
</div>
<p>The concept of scalar multiplication and addition, allow the decomposition of vectors into standard vectors. The standard unit vectors in two dimensions are <span class="math inline">\(e_x = \langle 1,~ 0 \rangle\)</span> and <span class="math inline">\(e_y = \langle 0,~ 1 \rangle\)</span>. Any two dimensional vector can be written uniquely as <span class="math inline">\(a e_x + b e_y\)</span> for some pair of scalars <span class="math inline">\(a\)</span> and <span class="math inline">\(b\)</span> (or as, <span class="math inline">\(\langle a, b \rangle\)</span>). This is true more generally where the two vectors are not the standard unit vectors - they can be <em>any</em> two non-parallel vectors.</p>
<div class="cell" data-hold="true" data-execution_count="7">
<div class="cell-output cell-output-display" data-execution_count="8">
<div class="d-flex justify-content-center"> <figure class="figure"> <img src="data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAwAAAAJACAIAAAC1zJYBAAAABmJLR0QA/wD/AP+gvaeTAAAgAElEQVR4nOzde0DT9f4/8CdjbGOM64ybIAgMyktF6E9FRcu8ZGllpNbXShPE7NvpdPN4PXb5nk55TM1KOx0zMzS/Zn5Tu/hFT33tpEmeU500hA3YYHIbF9ncxhhj+/1BcWrHUpTxYdvz8Vd83uzzeUpjnyefwecV4HK5QERERORPREIHICIiIuprLEBERETkd1iAiIiIyO+wABEREZHfYQEiIiIiv8MCRERERH6HBYiIiIj8DgsQERER+R0WICIiIvI7LEBERETkdzxSgB544AGn03l5j3U6nXa7vXfzkHex2+2X/fwh32Cz2YSOQALjc8DPdXZ2dnR0ePQQHilA//M//3MlI8YcDkcvhiGv09nZyRF1fo4vAsTngJ9zOp2e/kmYb4ERERGR32EBIiIiIr/DAkRERER+hwWIiIiI/A4LEBEREfkdFiAiIiLyOyxARERE5HdYgIiIiMjvsAARERGR37l4Aaqrq3vggQfGjBkzduzY5cuXm83mPohFRERE5DmXdAXotttu27Zt26uvvnry5MmlS5d6OhMRERGRR4kv+hlxcXF33313138/+OCDmzdv9nAkIiIi8l1NxXCcv8B2keyH/3A6AuzmAGkMrsqE6OJF5fJc0n5dLtdf//rXxsbGDRs2PPnkkx6KQkRERL7v3Ddoq/+FNSeMpTCeDpReFTAgBzYdku72UIpLKkBOp/ONN944f/683W5PTk6+6Ofb7fYBAwZ0f3jq1Knw8PBLDOR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6A5GDgDl/A21uOPP75p06b8/PwtW7Z4JKdwWICIiIh8iFWPiu1oOAqXw31JkYKk2Yifdim7aWlpuemmmzQazSeffDJ58uTezyk0FiAiIiKfYK6CdgcMR+G8ouoDYP/+/XPnzs3IyKirqwsLu8BdEH0ACxAREZGXM2tRvg1Nx+Byui8pUpA6H9E5l76zgoKCN998c+XKlc8880wvZuxvWICIiIi8lrEElTvQ/NUFqk9YBtLyoBx56TvT6/XZ2dlms9lLp1v0CAsQERGRFzp3GrrCC1SfgACED0XKAih71mC2bdu2ePHi7Oxs751u0SMsQERERF7l3HfQbkfLN3C5fr4QgIihSMtD5PU92l/XUPeDBw+uX7/+kUce6cWk/RkLEBERkZdoLkblOzB+f4Hqo8xE6iKEX93TXZ4+fXrixIlBQUE+MN2iR1iAiIiI+r3GE9AVovW0+/aAQChHIm0hQi+nu7z44ourVq2aMWOGb0y36BEWICIion6s8QQq34KpzH17V/VR5UORehl7tdls06ZNO378+JYtW/Ly8nohp7dhASIiIuqXDEdRvg2WKvftAYEYkI30xZAPvLwdd023iIiIqKioSExMvNKc3okFiIiIqD9xOlFfBN0uWKrdl0QSRI9H6oOXXX0APPnkkxs2bLj99tv37dt3RTm9HAsQERFRP+FEbRF0O2HRu6/8UH3yII+77L13TbcoLS3dt2/f7bfffkVJvR8LEBERkeCc0B9E1S60NbivBEoROwlpeZBEXckBDh48OHv27Pj4+Nra2qioK9qVb2ABIiIiEo7TDv1+VL8Hm8F9SRyCuMlIvh+yK+0rBQUFW7duffTRR9evX3+Fu/IZLEBERERC+KH67IGt0X2pq/qkzIck4goPotfrx40b19LS8tlnn+Xk9GAimM9jASIiIupbTjuq96B6L9pb3ZfECsRPR
<figcaption class="figure-caption"><div class="markdown"><p>The vector \(\langle 4,3 \rangle\) is written as \(2/3 \cdot\langle 1,2 \rangle + 5/3 \cdot\langle 2,1 \rangle\). Any vector \(\vec{c}\) can be written uniquely as \(\alpha\cdot\vec{a} + \beta \cdot \vec{b}\) provided \(\vec{a}\) and \(\vec{b}\) are not parallel.</p>
</div> </figcaption>
</figure>
</div>
</div>
</div>
<p>The two operations of scalar multiplication and vector addition are defined in a component-by-component basis. We will see that there are many other circumstances where performing the same action on each component in a vector is desirable.</p>
<hr>
<p>When a vector is placed with its tail at the origin, it can be described in terms of the angle it makes with the <span class="math inline">\(x\)</span> axis, <span class="math inline">\(\theta\)</span>, and its length, <span class="math inline">\(r\)</span>. The following formulas apply:</p>
<p><span class="math display">\[
r = \sqrt{x^2 + y^2}, \quad \tan(\theta) = y/x.
\]</span></p>
<p>If we are given <span class="math inline">\(r\)</span> and <span class="math inline">\(\theta\)</span>, then the vector is <span class="math inline">\(v = \langle r \cdot \cos(\theta),~ r \cdot \sin(\theta) \rangle\)</span>.</p>
<div class="cell" data-hold="true" data-execution_count="8">
<div class="cell-output cell-output-display" data-execution_count="9">
<div class="d-flex justify-content-center"> <figure class="figure"> <img src="data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAwAAAAJACAIAAAC1zJYBAAAABmJLR0QA/wD/AP+gvaeTAAAgAElEQVR4nOzde0CUdd7//wsFFOKoiAIVEGoqykJuJQwMCHIwD7Gka22FeKBRq93WVVdJTTfbbk0TtdK8S2+P+XWzXTOVyPWQgBCu0YqI4LTGMDIDiOSgIoeZ3x+zP9bFAwdn5prD8/EXMBczL3XSV+/PMG87nU4nAAAA2JIeYgcAAAAwNQoQAACwORQgAABgcyhAAADA5lCAAACAzaEAAQAAm0MBAgAANocCBAAAbA4FCAAA2BwKEAAAsDlGKUBTp07VarXd+16tVtvU1GTYPLAsTU1N3X7+wDo0NjaKHQEi4zlg41pbW5ubm436EEYpQH/9618fZMVYS0uLAcPA4rS2trKizsbxlwB4Dtg4rVZr7P8T5ggMAADYHAoQAACwORQgAABgcyhAAADA5lCAAACAzaEAAQAAm0MBAgAANocCBAAAbA4FCAAA2JyOC1BVVdXUqVPDw8MlEsmiRYsaGhpMEAsAAMB4OjUBGj9+/JYtWz744IPCwsIFCxYYOxMAAI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AAAB0gUwmGzduXFpaGtstLBpHYAAAdEpVVZVEIqmurs7Ozo6LixM7Dh4IEyAAADq2e/fugIAANzc3lUpF+
<figcaption class="figure-caption"><div class="markdown"><p>A vector \(\langle x, y \rangle\) can be written as \(\langle r\cdot \cos(\theta), r\cdot\sin(\theta) \rangle\) for values \(r\) and \(\theta\). The value \(r\) is a magnitude, the direction parameterized by \(\theta\).</p>
</div> </figcaption>
</figure>
</div>
</div>
</div>
<section id="vectors-in-julia" class="level2" data-number="5.1">
<h2 data-number="5.1" class="anchored" data-anchor-id="vectors-in-julia"><span class="header-section-number">5.1</span> Vectors in Julia</h2>
<p>A vector in <code>Julia</code> can be represented by its individual components, but it is more convenient to combine them into a collection using the <code>[,]</code> notation:</p>
<div class="cell" data-execution_count="9">
<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>x, y <span class="op">=</span> <span class="fl">1</span>, <span class="fl">2</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>v <span class="op">=</span> [x, y] <span class="co"># square brackets, not angles</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="10">
<pre><code>2-element Vector{Int64}:
1
2</code></pre>
</div>
</div>
<p>The basic vector operations are implemented for vector objects. For example, the vector <code>v</code> has scalar multiplication defined for it:</p>
<div class="cell" data-execution_count="10">
<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">10</span> <span class="op">*</span> v</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>2-element Vector{Int64}:
10
20</code></pre>
</div>
</div>
<p>The <code>norm</code> function returns the magnitude of the vector (by default):</p>
<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="im">import</span> <span class="bu">LinearAlgebra</span>: norm</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell" data-execution_count="12">
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="fu">norm</span>(v)</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.23606797749979</code></pre>
</div>
</div>
<p>A unit vector is then found by scaling by the reciprocal of the magnitude:</p>
<div class="cell" data-execution_count="13">
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>v <span class="op">/</span> <span class="fu">norm</span>(v)</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>2-element Vector{Float64}:
0.4472135954999579
0.8944271909999159</code></pre>
</div>
</div>
<p>In addition, if <code>w</code> is another vector, we can add and subtract:</p>
<div class="cell" data-execution_count="14">
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>w <span class="op">=</span> [<span class="fl">3</span>, <span class="fl">2</span>]</span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a>v <span class="op">+</span> w, v <span class="op">-</span> <span class="fl">2</span>w</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>([4, 4], [-5, -2])</code></pre>
</div>
</div>
<p>We see above that scalar multiplication, addition, and subtraction can be done without new notation. This is because the usual operators have methods defined for vectors.</p>
<p>Finally, to find an angle <span class="math inline">\(\theta\)</span> from a vector <span class="math inline">\(\langle x,~ y\rangle\)</span>, we can employ the <code>atan</code> function using two arguments:</p>
<div class="cell" data-execution_count="15">
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="fu">norm</span>(v), <span class="fu">atan</span>(y, x) <span class="co"># v = [x, y]</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>(2.23606797749979, 1.1071487177940904)</code></pre>
</div>
</div>
</section>
<section id="higher-dimensional-vectors" class="level2" data-number="5.2">
<h2 data-number="5.2" class="anchored" data-anchor-id="higher-dimensional-vectors"><span class="header-section-number">5.2</span> Higher dimensional vectors</h2>
<p>Mathematically, vectors can be generalized to more than <span class="math inline">\(2\)</span> dimensions. For example, using <span class="math inline">\(3\)</span>-dimensional vectors are common when modeling events happening in space, and <span class="math inline">\(4\)</span>-dimensional vectors are common when modeling space and time.</p>
<p>In <code>Julia</code> there are many uses for vectors outside of physics applications. A vector in <code>Julia</code> is just a one-dimensional collection of similarly typed values and a special case of an array. Such objects find widespread usage. For example:</p>
<ul>
<li>In plotting graphs with <code>Julia</code>, vectors are used to hold the <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span> coordinates of a collection of points to plot and connect with straight lines. There can be hundreds of such points in a plot.</li>
<li>Vectors are a natural container to hold the roots of a polynomial or zeros of a function.</li>
<li>Vectors may be used to record the state of an iterative process.</li>
<li>Vectors are naturally used to represent a data set, such as arise when collecting survey data.</li>
</ul>
<p>Creating higher-dimensional vectors is similar to creating a two-dimensional vector, we just include more components:</p>
<div class="cell" data-execution_count="16">
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a>fibs <span class="op">=</span> [<span class="fl">1</span>, <span class="fl">1</span>, <span class="fl">2</span>, <span class="fl">3</span>, <span class="fl">5</span>, <span class="fl">8</span>, <span class="fl">13</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>7-element Vector{Int64}:
1
1
2
3
5
8
13</code></pre>
</div>
</div>
<p>Later we will discuss different ways to modify the values of a vector to create new ones, similar to how scalar multiplication does.</p>
<p>As mentioned, vectors in <code>Julia</code> are comprised of elements of a similar type, but the type is not limited to numeric values. For example, a vector of strings might be useful for text processing, a vector of Boolean values can naturally arise, some applications are even naturally represented in terms of vectors of vectors (such as happens when plotting a collection points). Look at the output of these two vectors:</p>
<div class="cell" data-execution_count="17">
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a>[<span class="st">"one"</span>, <span class="st">"two"</span>, <span class="st">"three"</span>] <span class="co"># Array{T, 1} is shorthand for Vector{T}. Here T - the type - is String</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>3-element Vector{String}:
"one"
"two"
"three"</code></pre>
</div>
</div>
<div class="cell" data-execution_count="18">
<div class="sourceCode cell-code" id="cb18"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>[<span class="cn">true</span>, <span class="cn">false</span>, <span class="cn">true</span>] <span class="co"># vector of Bool values</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>3-element Vector{Bool}:
1
0
1</code></pre>
</div>
</div>
<p>Finally, we mention that if <code>Julia</code> has values of different types it will promote them to a common type if possible. Here we combine three types of numbers, and see that each is promoted to <code>Float64</code>:</p>
<div class="cell" data-execution_count="19">
<div class="sourceCode cell-code" id="cb20"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a>[<span class="fl">1</span>, <span class="fl">2.0</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="20">
<pre><code>3-element Vector{Float64}:
1.0
2.0
3.0</code></pre>
</div>
</div>
<p>Whereas, in this example where there is no common type to promote the values to, a catch-all type of <code>Any</code> is used to hold the components.</p>
<div class="cell" data-execution_count="20">
<div class="sourceCode cell-code" id="cb22"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a>[<span class="st">"one"</span>, <span class="fl">2</span>, <span class="fl">3.0</span>, <span class="fl">4</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="21">
<pre><code>4-element Vector{Any}:
"one"
2
3.0
4//1</code></pre>
</div>
</div>
</section>
<section id="indexing" class="level2" data-number="5.3">
<h2 data-number="5.3" class="anchored" data-anchor-id="indexing"><span class="header-section-number">5.3</span> Indexing</h2>
<p>Getting the components out of a vector can be done in a manner similar to multiple assignment:</p>
<div class="cell" data-execution_count="21">
<div class="sourceCode cell-code" id="cb24"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a>vs <span class="op">=</span> [<span class="fl">1</span>, <span class="fl">2</span>]</span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a>v₁, v₂ <span class="op">=</span> vs</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>2-element Vector{Int64}:
1
2</code></pre>
</div>
</div>
<p>When the same number of variable names are on the left hand side of the assignment as in the container on the right, each is assigned in order.</p>
<p>Though this is convenient for small vectors, it is far from being so if the vector has a large number of components. However, the vector is stored in order with a first, second, third, <span class="math inline">\(\dots\)</span> component. <code>Julia</code> allows these values to be referred to by <em>index</em>. This too uses the <code>[]</code> notation, though differently. Here is how we get the second component of <code>vs</code>:</p>
<div class="cell" data-execution_count="22">
<div class="sourceCode cell-code" id="cb26"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a>vs[<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="23">
<pre><code>2</code></pre>
</div>
</div>
<p>The last value of a vector is usually denoted by <span class="math inline">\(v_n\)</span>. In <code>Julia</code>, the <code>length</code> function will return <span class="math inline">\(n\)</span>, the number of items in the container. So <code>v[length(v)]</code> will refer to the last component. However, the special keyword <code>end</code> will do so as well, when put into the context of indexing. So <code>v[end]</code> is more idiomatic. (Similarly, there is a <code>begin</code> keyword that is useful when the vector is not <span class="math inline">\(1\)</span>-based, as is typical but not mandatory.)</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">
More on indexing
</div>
</div>
<div class="callout-body-container callout-body">
<p>There is <a href="http://julia.readthedocs.org/en/latest/manual/arrays/#indexing">much more</a> to indexing than just indexing by a single integer value. For example, the following can be used for indexing:</p>
<ul>
<li>a scalar integer (as seen)</li>
</ul>
</div>
</div>
<ul>
<li>a range</li>
<li>a vector of integers</li>
<li>a boolean vector</li>
</ul>
<p>Some add-on packages extend this further.</p>
<section id="assignment-and-indexing" class="level3" data-number="5.3.1">
<h3 data-number="5.3.1" class="anchored" data-anchor-id="assignment-and-indexing"><span class="header-section-number">5.3.1</span> Assignment and indexing</h3>
<p>Indexing notation can also be used with assignment, meaning it can appear on the left hand side of an equals sign. The following expression replaces the second component with a new value:</p>
<div class="cell" data-execution_count="23">
<div class="sourceCode cell-code" id="cb28"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a>vs[<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>10</code></pre>
</div>
</div>
<p>The value of the right hand side is returned, not the value for <code>vs</code>. We can check that <code>vs</code> is then <span class="math inline">\(\langle 1,~ 10 \rangle\)</span> by showing it:</p>
<div class="cell" data-hold="true" data-execution_count="24">
<div class="sourceCode cell-code" id="cb30"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a>vs <span class="op">=</span> [<span class="fl">1</span>,<span class="fl">2</span>]</span>
<span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a>vs[<span class="fl">2</span>] <span class="op">=</span> <span class="fl">10</span></span>
<span id="cb30-3"><a href="#cb30-3" aria-hidden="true" tabindex="-1"></a>vs</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>2-element Vector{Int64}:
1
10</code></pre>
</div>
</div>
<p>The assignment <code>vs[2]</code> is different than the initial assignment <code>vs=[1,2]</code> in that, <code>vs[2]=10</code> <strong>modifies</strong> the container that <code>vs</code> points to, whereas <code>v=[1,2]</code> <strong>replaces</strong> the binding for <code>vs</code>. The indexed assignment is then more memory efficient when vectors are large. This point is also of interest when passing vectors to functions, as a function may modify components of the vector passed to it, though cant replace the container itself.</p>
</section>
</section>
<section id="some-useful-functions-for-working-with-vectors." class="level2" data-number="5.4">
<h2 data-number="5.4" class="anchored" data-anchor-id="some-useful-functions-for-working-with-vectors."><span class="header-section-number">5.4</span> Some useful functions for working with vectors.</h2>
<p>As mentioned, the <code>length</code> function returns the number of components in a vector. It is one of several useful functions for vectors.</p>
<p>The <code>sum</code> and <code>prod</code> function will add and multiply the elements in a vector:</p>
<div class="cell" data-execution_count="25">
<div class="sourceCode cell-code" id="cb32"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a>v1 <span class="op">=</span> [<span class="fl">1</span>,<span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">3</span>,<span class="fl">5</span>,<span class="fl">8</span>]</span>
<span id="cb32-2"><a href="#cb32-2" aria-hidden="true" tabindex="-1"></a><span class="fu">sum</span>(v1), <span class="fu">prod</span>(v1)</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>(20, 240)</code></pre>
</div>
</div>
<p>The <code>unique</code> function will throw out any duplicates:</p>
<div class="cell" data-execution_count="26">
<div class="sourceCode cell-code" id="cb34"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a><span class="fu">unique</span>(v1) <span class="co"># drop a `1`</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="27">
<pre><code>5-element Vector{Int64}:
1
2
3
5
8</code></pre>
</div>
</div>
<p>The functions <code>maximum</code> and <code>minimum</code> will return the largest and smallest values of an appropriate vector.</p>
<div class="cell" data-execution_count="27">
<div class="sourceCode cell-code" id="cb36"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a><span class="fu">maximum</span>(v1)</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>8</code></pre>
</div>
</div>
<p>(These should not be confused with <code>max</code> and <code>min</code> which give the largest or smallest value over all their arguments.)</p>
<p>The <code>extrema</code> function returns both the smallest and largest value of a collection:</p>
<div class="cell" data-execution_count="28">
<div class="sourceCode cell-code" id="cb38"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb38-1"><a href="#cb38-1" aria-hidden="true" tabindex="-1"></a><span class="fu">extrema</span>(v1)</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>(1, 8)</code></pre>
</div>
</div>
<p>Consider now</p>
<div class="cell" data-execution_count="29">
<div class="sourceCode cell-code" id="cb40"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb40-1"><a href="#cb40-1" aria-hidden="true" tabindex="-1"></a>𝒗 <span class="op">=</span> [<span class="fl">1</span>,<span class="fl">4</span>,<span class="fl">2</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="30">
<pre><code>4-element Vector{Int64}:
1
4
2
3</code></pre>
</div>
</div>
<p>The <code>sort</code> function will rearrange the values in <code>𝒗</code>:</p>
<div class="cell" data-execution_count="30">
<div class="sourceCode cell-code" id="cb42"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb42-1"><a href="#cb42-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sort</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>4-element Vector{Int64}:
1
2
3
4</code></pre>
</div>
</div>
<p>The keyword argument, <code>rev=false</code> can be given to get values in decreasing order:</p>
<div class="cell" data-execution_count="31">
<div class="sourceCode cell-code" id="cb44"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb44-1"><a href="#cb44-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sort</span>(𝒗, rev<span class="op">=</span><span class="cn">false</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>4-element Vector{Int64}:
1
2
3
4</code></pre>
</div>
</div>
<p>For adding a new element to a vector the <code>push!</code> method can be used, as in</p>
<div class="cell" data-execution_count="32">
<div class="sourceCode cell-code" id="cb46"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb46-1"><a href="#cb46-1" aria-hidden="true" tabindex="-1"></a><span class="fu">push!</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="33">
<pre><code>5-element Vector{Int64}:
1
4
2
3
5</code></pre>
</div>
</div>
<p>To append more than one value, the <code>append!</code> function can be used:</p>
<div class="cell" data-execution_count="33">
<div class="sourceCode cell-code" id="cb48"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb48-1"><a href="#cb48-1" aria-hidden="true" tabindex="-1"></a><span class="fu">append!</span>(v1, [<span class="fl">6</span>,<span class="fl">8</span>,<span class="fl">7</span>])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="34">
<pre><code>9-element Vector{Int64}:
1
1
2
3
5
8
6
8
7</code></pre>
</div>
</div>
<p>These two functions modify or mutate the values stored within the vector <code>𝒗</code> that passed as an argument. In the <code>push!</code> example above, the value <code>5</code> is added to the vector of <span class="math inline">\(4\)</span> elements. In <code>Julia</code>, a convention is to name mutating functions with a trailing exclamation mark. (Again, these do not mutate the binding of <code>𝒗</code> to the container, but do mutate the contents of the container.) There are functions with mutating and non-mutating definitions, an example is <code>sort</code> and <code>sort!</code>.</p>
<p>If only a mutating function is available, like <code>push!</code>, and this is not desired a copy of the vector can be made. It is not enough to copy by assignment, as with <code>w = 𝒗</code>. As both <code>w</code> and <code>𝒗</code> will be bound to the same memory location. Rather, you call <code>copy</code> to make a new container with copied contents, as in <code>w = copy(𝒗)</code>.</p>
<p>Creating new vectors of a given size is common for programming, though not much use will be made here. There are many different functions to do so: <code>ones</code> to make a vector of ones, <code>zeros</code> to make a vector of zeros, <code>trues</code> and <code>falses</code> to make Boolean vectors of a given size, and <code>similar</code> to make a similar-sized vector (with no particular values assigned).</p>
</section>
<section id="applying-functions-element-by-element-to-values-in-a-vector" class="level2" data-number="5.5">
<h2 data-number="5.5" class="anchored" data-anchor-id="applying-functions-element-by-element-to-values-in-a-vector"><span class="header-section-number">5.5</span> Applying functions element by element to values in a vector</h2>
<p>Functions such as <code>sum</code> or <code>length</code> are known as <em>reductions</em> as they reduce the “dimensionality” of the data: a vector is in some sense <span class="math inline">\(1\)</span>-dimensional, the sum or length are <span class="math inline">\(0\)</span>-dimensional numbers. Applying a reduction is straightforward it is just a regular function call.</p>
<div class="cell" data-hold="true" data-execution_count="34">
<div class="sourceCode cell-code" id="cb50"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb50-1"><a href="#cb50-1" aria-hidden="true" tabindex="-1"></a>v <span class="op">=</span> [<span class="fl">1</span>, <span class="fl">2</span>, <span class="fl">3</span>, <span class="fl">4</span>]</span>
<span id="cb50-2"><a href="#cb50-2" aria-hidden="true" tabindex="-1"></a><span class="fu">sum</span>(v), <span class="fu">length</span>(v)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="35">
<pre><code>(10, 4)</code></pre>
</div>
</div>
<p>Other desired operations with vectors act differently. Rather than reduce a collection of values using some formula, the goal is to apply some formula to <em>each</em> of the values, returning a modified vector. A simple example might be to square each element, or subtract the average value from each element. An example comes from statistics. When computing a variance, we start with data <span class="math inline">\(x_1, x_2, \dots, x_n\)</span> and along the way form the values <span class="math inline">\((x_1-\bar{x})^2, (x_2-\bar{x})^2, \dots, (x_n-\bar{x})^2\)</span>.</p>
<p>Such things can be done in <em>many</em> differents ways. Here we describe two, but will primarily utilize the first.</p>
<section id="broadcasting-a-function-call" class="level3" data-number="5.5.1">
<h3 data-number="5.5.1" class="anchored" data-anchor-id="broadcasting-a-function-call"><span class="header-section-number">5.5.1</span> Broadcasting a function call</h3>
<p>If we have a vector, <code>xs</code>, and a function, <code>f</code>, to apply to each value, there is a simple means to achieve this task. By adding a “dot” between the function name and the parenthesis that enclose the arguments, instructs <code>Julia</code> to “broadcast” the function call. The details allow for more flexibility, but, for this purpose, broadcasting will take each value in <code>xs</code> and apply <code>f</code> to it, returning a vector of the same size as <code>xs</code>. When more than one argument is involved, broadcasting will try to fill out different sized objects.</p>
<p>For example, the following will find, using <code>sqrt</code>, the square root of each value in a vector:</p>
<div class="cell" data-execution_count="35">
<div class="sourceCode cell-code" id="cb52"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb52-1"><a href="#cb52-1" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> [<span class="fl">1</span>, <span class="fl">1</span>, <span class="fl">3</span>, <span class="fl">4</span>, <span class="fl">7</span>]</span>
<span id="cb52-2"><a href="#cb52-2" aria-hidden="true" tabindex="-1"></a><span class="fu">sqrt</span>.(xs)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="36">
<pre><code>5-element Vector{Float64}:
1.0
1.0
1.7320508075688772
2.0
2.6457513110645907</code></pre>
</div>
</div>
<p>This would find the sine of each number in <code>xs</code>:</p>
<div class="cell" data-execution_count="36">
<div class="sourceCode cell-code" id="cb54"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb54-1"><a href="#cb54-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sin</span>.(xs)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="37">
<pre><code>5-element Vector{Float64}:
0.8414709848078965
0.8414709848078965
0.1411200080598672
-0.7568024953079282
0.6569865987187891</code></pre>
</div>
</div>
<p>For each function, the <code>.(</code> (and not <code>(</code>) after the name is the surface syntax for broadcasting.</p>
<p>The <code>^</code> operator is an <em>infix</em> operator. Infix operators can be broadcast, as well, by using the form <code>.</code> prior to the operator, as in:</p>
<div class="cell" data-execution_count="37">
<div class="sourceCode cell-code" id="cb56"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb56-1"><a href="#cb56-1" aria-hidden="true" tabindex="-1"></a>xs <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="38">
<pre><code>5-element Vector{Int64}:
1
1
9
16
49</code></pre>
</div>
</div>
<p>Here is an example involving the logarithm of a set of numbers. In astronomy, a logarithm with base <span class="math inline">\(100^{1/5}\)</span> is used for star <a href="http://tinyurl.com/ycp7k8ay">brightness</a>. We can use broadcasting to find this value for several values at once through:</p>
<div class="cell" data-execution_count="38">
<div class="sourceCode cell-code" id="cb58"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb58-1"><a href="#cb58-1" aria-hidden="true" tabindex="-1"></a>ys <span class="op">=</span> [<span class="fl">1</span><span class="op">/</span><span class="fl">5000</span>, <span class="fl">1</span><span class="op">/</span><span class="fl">500</span>, <span class="fl">1</span><span class="op">/</span><span class="fl">50</span>, <span class="fl">1</span><span class="op">/</span><span class="fl">5</span>, <span class="fl">5</span>, <span class="fl">50</span>]</span>
<span id="cb58-2"><a href="#cb58-2" aria-hidden="true" tabindex="-1"></a>base <span class="op">=</span> (<span class="fl">100</span>)<span class="op">^</span>(<span class="fl">1</span><span class="op">/</span><span class="fl">5</span>)</span>
<span id="cb58-3"><a href="#cb58-3" aria-hidden="true" tabindex="-1"></a><span class="fu">log</span>.(base, ys)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="39">
<pre><code>6-element Vector{Float64}:
-9.247425010840049
-6.747425010840047
-4.247425010840047
-1.747425010840047
1.747425010840047
4.247425010840047</code></pre>
</div>
</div>
<p>Broadcasting with multiple arguments allows for mixing of vectors and scalar values, as above, making it convenient when parameters are used.</p>
<p>As a final example, the task from statistics of centering and then squaring can be done with broadcasting. We go a bit further, showing how to compute the <a href="http://tinyurl.com/p6wa4r8">sample variance</a> of a data set. This has the formula</p>
<p><span class="math display">\[
\frac{1}{n-1}\cdot ((x_1-\bar{x})^2 + \cdots + (x_n - \bar{x})^2).
\]</span></p>
<p>This can be computed, with broadcasting, through:</p>
<div class="cell" data-hold="true" data-execution_count="39">
<div class="sourceCode cell-code" id="cb60"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb60-1"><a href="#cb60-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> <span class="bu">Statistics</span>: mean</span>
<span id="cb60-2"><a href="#cb60-2" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> [<span class="fl">1</span>, <span class="fl">1</span>, <span class="fl">2</span>, <span class="fl">3</span>, <span class="fl">5</span>, <span class="fl">8</span>, <span class="fl">13</span>]</span>
<span id="cb60-3"><a href="#cb60-3" aria-hidden="true" tabindex="-1"></a>n <span class="op">=</span> <span class="fu">length</span>(xs)</span>
<span id="cb60-4"><a href="#cb60-4" aria-hidden="true" tabindex="-1"></a>(<span class="fl">1</span><span class="op">/</span>(n<span class="op">-</span><span class="fl">1</span>)) <span class="op">*</span> <span class="fu">sum</span>(<span class="fu">abs2</span>.(xs <span class="op">.-</span> <span class="fu">mean</span>(xs)))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="40">
<pre><code>19.57142857142857</code></pre>
</div>
</div>
<p>This shows many of the manipulations that can be made with vectors. Rather than write <code>.^2</code>, we follow the definition of <code>var</code> and chose the possibly more performant <code>abs2</code> function which, in general, efficiently finds <span class="math inline">\(|x|^2\)</span> for various number types. The <code>.-</code> uses broadcasting to subtract a scalar (<code>mean(xs)</code>) from a vector (<code>xs</code>). Without the <code>.</code>, this would error.</p>
<div class="callout-note callout callout-style-default callout-captioned">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-caption-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>The <code>map</code> function is very much related to broadcasting and similarly named functions are found in many different programming languages. (The “dot” broadcast is mostly limited to <code>Julia</code> and mirrors on a similar usage of a dot in <code>MATLAB</code>.) For those familiar with other programming languages, using <code>map</code> may seem more natural. Its syntax is <code>map(f, xs)</code>.</p>
</div>
</div>
</section>
<section id="comprehensions" class="level3" data-number="5.5.2">
<h3 data-number="5.5.2" class="anchored" data-anchor-id="comprehensions"><span class="header-section-number">5.5.2</span> Comprehensions</h3>
<p>In mathematics, set notation is often used to describe elements in a set.</p>
<p>For example, the first <span class="math inline">\(5\)</span> cubed numbers can be described by:</p>
<p><span class="math display">\[
\{x^3: x \text{ in } 1, 2,\dots, 5\}
\]</span></p>
<p>Comprehension notation is similar. The above could be created in <code>Julia</code> with:</p>
<div class="cell" data-execution_count="40">
<div class="sourceCode cell-code" id="cb62"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb62-1"><a href="#cb62-1" aria-hidden="true" tabindex="-1"></a>𝒙s <span class="op">=</span> [<span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">3</span>,<span class="fl">4</span>,<span class="fl">5</span>]</span>
<span id="cb62-2"><a href="#cb62-2" aria-hidden="true" tabindex="-1"></a>[x<span class="op">^</span><span class="fl">3</span> for x <span class="kw">in</span> 𝒙s]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="41">
<pre><code>5-element Vector{Int64}:
1
8
27
64
125</code></pre>
</div>
</div>
<p>Something similar can be done more succinctly:</p>
<div class="cell" data-execution_count="41">
<div class="sourceCode cell-code" id="cb64"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb64-1"><a href="#cb64-1" aria-hidden="true" tabindex="-1"></a>𝒙s <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="42">
<pre><code>5-element Vector{Int64}:
1
8
27
64
125</code></pre>
</div>
</div>
<p>However, comprehensions have a value when more complicated expressions are desired as they work with an expression of <code>𝒙s</code>, and not a pre-defined or user-defined function.</p>
<p>Another typical example of set notation might include a condition, such as, the numbers divisible by <span class="math inline">\(7\)</span> between <span class="math inline">\(1\)</span> and <span class="math inline">\(100\)</span>. Set notation might be:</p>
<p><span class="math display">\[
\{x: \text{rem}(x, 7) = 0 \text{ for } x \text{ in } 1, 2, \dots, 100\}.
\]</span></p>
<p>This would be read: “the set of <span class="math inline">\(x\)</span> such that the remainder on division by <span class="math inline">\(7\)</span> is <span class="math inline">\(0\)</span> for all x in <span class="math inline">\(1, 2, \dots, 100\)</span>.”</p>
<p>In <code>Julia</code>, a comprehension can include an <code>if</code> clause to mirror, somewhat, the math notation. For example, the above would become (using <code>1:100</code> as a means to create the numbers <span class="math inline">\(1,2,\dots, 100\)</span>, as will be described in an upcoming section):</p>
<div class="cell" data-execution_count="42">
<div class="sourceCode cell-code" id="cb66"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb66-1"><a href="#cb66-1" aria-hidden="true" tabindex="-1"></a>[x for x <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">100</span> if <span class="fu">rem</span>(x,<span class="fl">7</span>) <span class="op">==</span> <span class="fl">0</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="43">
<pre><code>14-element Vector{Int64}:
7
14
21
28
35
42
49
56
63
70
77
84
91
98</code></pre>
</div>
</div>
<p>Comprehensions can be a convenient means to describe a collection of numbers, especially when no function is defined, but the simplicity of the broadcast notation (just adding a judicious “.”) leads to its more common use in these notes.</p>
<section id="example-creating-a-t-table-for-creating-a-graph" class="level5">
<h5 class="anchored" data-anchor-id="example-creating-a-t-table-for-creating-a-graph">Example: creating a “T” table for creating a graph</h5>
<p>The process of plotting a function is usually first taught by generating a “T” table: values of <span class="math inline">\(x\)</span> and corresponding values of <span class="math inline">\(y\)</span>. These pairs are then plotted on a Cartesian grid and the points are connected with lines to form the graph. Generating a “T” table in <code>Julia</code> is easy: create the <span class="math inline">\(x\)</span> values, then create the <span class="math inline">\(y\)</span> values for each <span class="math inline">\(x\)</span>.</p>
<p>To be concrete, lets generate <span class="math inline">\(7\)</span> points to plot <span class="math inline">\(f(x) = x^2\)</span> over <span class="math inline">\([-1,1]\)</span>.</p>
<p>The first task is to create the data. We will soon see more convenient ways to generate patterned data, but for now, we do this by hand:</p>
<div class="cell" data-execution_count="43">
<div class="sourceCode cell-code" id="cb68"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb68-1"><a href="#cb68-1" aria-hidden="true" tabindex="-1"></a>a,b, n <span class="op">=</span> <span class="op">-</span><span class="fl">1</span>, <span class="fl">1</span>, <span class="fl">7</span></span>
<span id="cb68-2"><a href="#cb68-2" aria-hidden="true" tabindex="-1"></a>d <span class="op">=</span> (b<span class="op">-</span>a) <span class="op">//</span> (n<span class="op">-</span><span class="fl">1</span>)</span>
<span id="cb68-3"><a href="#cb68-3" aria-hidden="true" tabindex="-1"></a>𝐱s <span class="op">=</span> [a, a<span class="op">+</span>d, a<span class="op">+</span><span class="fl">2</span>d, a<span class="op">+</span><span class="fl">3</span>d, a<span class="op">+</span><span class="fl">4</span>d, a<span class="op">+</span><span class="fl">5</span>d, a<span class="op">+</span><span class="fl">6</span>d] <span class="co"># 7 points</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="44">
<pre><code>7-element Vector{Rational{Int64}}:
-1//1
-2//3
-1//3
0//1
1//3
2//3
1//1</code></pre>
</div>
</div>
<p>To get the corresponding <span class="math inline">\(y\)</span> values, we can use a compression (or define a function and broadcast):</p>
<div class="cell" data-execution_count="44">
<div class="sourceCode cell-code" id="cb70"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb70-1"><a href="#cb70-1" aria-hidden="true" tabindex="-1"></a>𝐲s <span class="op">=</span> [x<span class="op">^</span><span class="fl">2</span> for x <span class="kw">in</span> 𝐱s]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="45">
<pre><code>7-element Vector{Rational{Int64}}:
1//1
4//9
1//9
0//1
1//9
4//9
1//1</code></pre>
</div>
</div>
<p>Vectors can be compared together by combining them into a separate container, as follows:</p>
<div class="cell" data-execution_count="45">
<div class="sourceCode cell-code" id="cb72"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb72-1"><a href="#cb72-1" aria-hidden="true" tabindex="-1"></a>[𝐱s 𝐲s]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="46">
<pre><code>7×2 Matrix{Rational{Int64}}:
-1//1 1//1
-2//3 4//9
-1//3 1//9
0//1 0//1
1//3 1//9
2//3 4//9
1//1 1//1</code></pre>
</div>
</div>
<p>(If there is a space between objects they are horizontally combined. In our construction of vectors using <code>[]</code> we used a comma for vertical combination. More generally we should use a <code>;</code> for vertical concatenation.)</p>
<p>In the sequel, we will typically use broadcasting for this task using two steps: one to define a function the second to broadcast it.</p>
<div class="callout-note callout callout-style-default callout-captioned">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-caption-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>The style generally employed here is to use plural variable names for a collection of values, such as the vector of <span class="math inline">\(y\)</span> values and singular names when a single value is being referred to, leading to expressions like “<code>x in xs</code>”.</p>
</div>
</div>
</section>
</section>
</section>
<section id="other-container-types" class="level2" data-number="5.6">
<h2 data-number="5.6" class="anchored" data-anchor-id="other-container-types"><span class="header-section-number">5.6</span> Other container types</h2>
<p>Vectors in <code>Julia</code> are a container, one of many different types. Another useful type for programming purposes are <em>tuples</em>. If a vector is formed by placing comma-separated values within a <code>[]</code> pair (e.g., <code>[1,2,3]</code>), a tuple is formed by placing comma-separated values withing a <code>()</code> pair. A tuple of length <span class="math inline">\(1\)</span> uses a convention of a trailing comma to distinguish it from a parethesized expression (e.g.&nbsp;<code>(1,)</code> is a tuple, <code>(1)</code> is just the value <code>1</code>).</p>
<p>Tuples are used in programming, as they dont typically require allocated memory to be used so they can be faster. Internal usages are for function arguments and function return types. Unlike vectors, tuples can be heterogeneous collections. (When commas are used to combine more than one output into a cell, a tuple is being used.) (Also, a big technical distinction is that tuples are also different from vectors and other containers in that tuple types are <em>covariant</em> in their parameters, not <em>invariant</em>.)</p>
<p>Unlike vectors, tuples can have names which can be used for referencing a value, similar to indexing but possibly more convenient. Named tuples are similar to <em>dictionaries</em> which are used to associate a key (like a name) with a value.</p>
<p>For example, here a named tuple is constructed, and then its elements referenced:</p>
<div class="cell" data-execution_count="46">
<div class="sourceCode cell-code" id="cb74"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb74-1"><a href="#cb74-1" aria-hidden="true" tabindex="-1"></a>nt <span class="op">=</span> (one<span class="op">=</span><span class="fl">1</span>, two<span class="op">=</span><span class="st">"two"</span>, three<span class="op">=:</span>three) <span class="co"># heterogeneous values (Int, String, Symbol)</span></span>
<span id="cb74-2"><a href="#cb74-2" aria-hidden="true" tabindex="-1"></a>nt.one, nt[<span class="fl">2</span>], n[<span class="kw">end</span>] <span class="co"># named tuples have name or index access</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>(1, "two", 7)</code></pre>
</div>
</div>
</section>
<section id="questions" class="level2" data-number="5.7">
<h2 data-number="5.7" class="anchored" data-anchor-id="questions"><span class="header-section-number">5.7</span> Questions</h2>
<section id="question" class="level6">
<h6 class="anchored" data-anchor-id="question">Question</h6>
<p>Which command will create the vector <span class="math inline">\(\vec{v} = \langle 4,~ 3 \rangle\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="47">
<div class="cell-output cell-output-display" data-execution_count="48">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15919515204309133271" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_15919515204309133271">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_15919515204309133271_1">
<input class="form-check-input" type="radio" name="radio_15919515204309133271" id="radio_15919515204309133271_1" value="1">
<span class="label-body px-1">
<code>v = [4,3]</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_15919515204309133271_2">
<input class="form-check-input" type="radio" name="radio_15919515204309133271" id="radio_15919515204309133271_2" value="2">
<span class="label-body px-1">
<code>v = '4, 3'</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_15919515204309133271_3">
<input class="form-check-input" type="radio" name="radio_15919515204309133271" id="radio_15919515204309133271_3" value="3">
<span class="label-body px-1">
<code>v = {4, 3}</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_15919515204309133271_4">
<input class="form-check-input" type="radio" name="radio_15919515204309133271" id="radio_15919515204309133271_4" value="4">
<span class="label-body px-1">
<code>v = (4,3)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_15919515204309133271_5">
<input class="form-check-input" type="radio" name="radio_15919515204309133271" id="radio_15919515204309133271_5" value="5">
<span class="label-body px-1">
<code>v = &lt;4,3&gt;</code>
</span>
</label>
</div>
</div>
</div>
<div id="15919515204309133271_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_15919515204309133271"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('15919515204309133271_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_15919515204309133271")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_15919515204309133271")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-1" class="level6">
<h6 class="anchored" data-anchor-id="question-1">Question</h6>
<p>Which command will create the vector with components “4,3,2,1”?</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="1205993544128186880" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_1205993544128186880">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_1205993544128186880_1">
<input class="form-check-input" type="radio" name="radio_1205993544128186880" id="radio_1205993544128186880_1" value="1">
<span class="label-body px-1">
<code>v = (4,3,2,1)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1205993544128186880_2">
<input class="form-check-input" type="radio" name="radio_1205993544128186880" id="radio_1205993544128186880_2" value="2">
<span class="label-body px-1">
<code>v = &lt;4,3,2,1&gt;</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1205993544128186880_3">
<input class="form-check-input" type="radio" name="radio_1205993544128186880" id="radio_1205993544128186880_3" value="3">
<span class="label-body px-1">
<code>v = '4, 3, 2, 1'</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1205993544128186880_4">
<input class="form-check-input" type="radio" name="radio_1205993544128186880" id="radio_1205993544128186880_4" value="4">
<span class="label-body px-1">
<code>v = [4,3,2,1]</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1205993544128186880_5">
<input class="form-check-input" type="radio" name="radio_1205993544128186880" id="radio_1205993544128186880_5" value="5">
<span class="label-body px-1">
<code>v = {4,3,2,1}</code>
</span>
</label>
</div>
</div>
</div>
<div id="1205993544128186880_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_1205993544128186880"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 4;
var msgBox = document.getElementById('1205993544128186880_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_1205993544128186880")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_1205993544128186880")
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>What is the magnitude of the vector <span class="math inline">\(\vec{v} = \langle 10,~ 15 \rangle\)</span>?</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="17301933021342422251" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_17301933021342422251">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="17301933021342422251" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="17301933021342422251_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("17301933021342422251").addEventListener("change", function() {
var correct = (Math.abs(this.value - 18.027756377319946) <= 0.001);
var msgBox = document.getElementById('17301933021342422251_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_17301933021342422251")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_17301933021342422251")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
</section>
<section id="question-3" class="level6">
<h6 class="anchored" data-anchor-id="question-3">Question</h6>
<p>Which of the following is the unit vector in the direction of <span class="math inline">\(\vec{v} = \langle 3,~ 4 \rangle\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="50">
<div class="cell-output cell-output-display" data-execution_count="51">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="13690001024305285793" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_13690001024305285793">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_13690001024305285793_1">
<input class="form-check-input" type="radio" name="radio_13690001024305285793" id="radio_13690001024305285793_1" value="1">
<span class="label-body px-1">
<code>[0.6, 0.8]</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13690001024305285793_2">
<input class="form-check-input" type="radio" name="radio_13690001024305285793" id="radio_13690001024305285793_2" value="2">
<span class="label-body px-1">
<code>[3, 4]</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13690001024305285793_3">
<input class="form-check-input" type="radio" name="radio_13690001024305285793" id="radio_13690001024305285793_3" value="3">
<span class="label-body px-1">
<code>[1, 1]</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13690001024305285793_4">
<input class="form-check-input" type="radio" name="radio_13690001024305285793" id="radio_13690001024305285793_4" value="4">
<span class="label-body px-1">
<code>[1.0, 1.33333]</code>
</span>
</label>
</div>
</div>
</div>
<div id="13690001024305285793_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_13690001024305285793"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('13690001024305285793_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_13690001024305285793")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_13690001024305285793")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-4" class="level6">
<h6 class="anchored" data-anchor-id="question-4">Question</h6>
<p>What vector is in the same direction as <span class="math inline">\(\vec{v} = \langle 3,~ 4 \rangle\)</span> but is 10 times as long?</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="17101551730632304050" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_17101551730632304050">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_17101551730632304050_1">
<input class="form-check-input" type="radio" name="radio_17101551730632304050" id="radio_17101551730632304050_1" value="1">
<span class="label-body px-1">
<code>[3, 4]</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_17101551730632304050_2">
<input class="form-check-input" type="radio" name="radio_17101551730632304050" id="radio_17101551730632304050_2" value="2">
<span class="label-body px-1">
<code>[9.48683, 12.6491 ]</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_17101551730632304050_3">
<input class="form-check-input" type="radio" name="radio_17101551730632304050" id="radio_17101551730632304050_3" value="3">
<span class="label-body px-1">
<code>[30, 40]</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_17101551730632304050_4">
<input class="form-check-input" type="radio" name="radio_17101551730632304050" id="radio_17101551730632304050_4" value="4">
<span class="label-body px-1">
<code>[10, 10]</code>
</span>
</label>
</div>
</div>
</div>
<div id="17101551730632304050_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_17101551730632304050"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('17101551730632304050_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_17101551730632304050")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_17101551730632304050")
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>If <span class="math inline">\(\vec{v} = \langle 3,~ 4 \rangle\)</span> and <span class="math inline">\(\vec{w} = \langle 1,~ 2 \rangle\)</span> find <span class="math inline">\(2\vec{v} + 5 \vec{w}\)</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="7858453383884604512" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_7858453383884604512">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_7858453383884604512_1">
<input class="form-check-input" type="radio" name="radio_7858453383884604512" id="radio_7858453383884604512_1" value="1">
<span class="label-body px-1">
<code>[11, 18]</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7858453383884604512_2">
<input class="form-check-input" type="radio" name="radio_7858453383884604512" id="radio_7858453383884604512_2" value="2">
<span class="label-body px-1">
<code>[6, 8]</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7858453383884604512_3">
<input class="form-check-input" type="radio" name="radio_7858453383884604512" id="radio_7858453383884604512_3" value="3">
<span class="label-body px-1">
<code>[5, 10]</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7858453383884604512_4">
<input class="form-check-input" type="radio" name="radio_7858453383884604512" id="radio_7858453383884604512_4" value="4">
<span class="label-body px-1">
<code>[4, 6]</code>
</span>
</label>
</div>
</div>
</div>
<div id="7858453383884604512_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_7858453383884604512"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('7858453383884604512_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_7858453383884604512")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_7858453383884604512")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-6" class="level6">
<h6 class="anchored" data-anchor-id="question-6">Question</h6>
<p>Let <code>v</code> be defined by:</p>
<div class="sourceCode cell-code" id="cb76"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb76-1"><a href="#cb76-1" aria-hidden="true" tabindex="-1"></a>v <span class="op">=</span> [<span class="fl">1</span>, <span class="fl">1</span>, <span class="fl">2</span>, <span class="fl">3</span>, <span class="fl">5</span>, <span class="fl">8</span>, <span class="fl">13</span>, <span class="fl">21</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>What is the length of <code>v</code>?</p>
<div class="cell" data-hold="true" data-execution_count="54">
<div class="cell-output cell-output-display" data-execution_count="54">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="10198185180197456846" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_10198185180197456846">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="10198185180197456846" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="10198185180197456846_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("10198185180197456846").addEventListener("change", function() {
var correct = (Math.abs(this.value - 8) <= 0);
var msgBox = document.getElementById('10198185180197456846_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_10198185180197456846")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_10198185180197456846")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>What is the <code>sum</code> of <code>v</code>?</p>
<div class="cell" data-hold="true" data-execution_count="55">
<div class="cell-output cell-output-display" data-execution_count="55">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="6841170247975483561" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_6841170247975483561">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="6841170247975483561" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="6841170247975483561_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("6841170247975483561").addEventListener("change", function() {
var correct = (Math.abs(this.value - 54) <= 0);
var msgBox = document.getElementById('6841170247975483561_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_6841170247975483561")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_6841170247975483561")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>What is the <code>prod</code> of <code>v</code>?</p>
<div class="cell" data-hold="true" data-execution_count="56">
<div class="cell-output cell-output-display" data-execution_count="56">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="17828309580919115720" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_17828309580919115720">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="17828309580919115720" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="17828309580919115720_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("17828309580919115720").addEventListener("change", function() {
var correct = (Math.abs(this.value - 65520) <= 0);
var msgBox = document.getElementById('17828309580919115720_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_17828309580919115720")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_17828309580919115720")
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>From <a href="http://www.transum.org/Maths/Exam/Online_Exercise.asp?Topic=Vectors">transum.org</a>.</p>
<div class="cell" data-hold="true" data-execution_count="57">
<div class="cell-output cell-output-display" data-execution_count="57">
<p><img src="vectors_files/figure-html/cell-58-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The figure shows <span class="math inline">\(5\)</span> vectors.</p>
<p>Express vector <strong>c</strong> in terms of <strong>a</strong> and <strong>b</strong>:</p>
<div class="cell" data-hold="true" data-execution_count="58">
<div class="cell-output cell-output-display" data-execution_count="58">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="4220634931002647995" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_4220634931002647995">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_4220634931002647995_1">
<input class="form-check-input" type="radio" name="radio_4220634931002647995" id="radio_4220634931002647995_1" value="1">
<span class="label-body px-1">
3b
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4220634931002647995_2">
<input class="form-check-input" type="radio" name="radio_4220634931002647995" id="radio_4220634931002647995_2" value="2">
<span class="label-body px-1">
b-a
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4220634931002647995_3">
<input class="form-check-input" type="radio" name="radio_4220634931002647995" id="radio_4220634931002647995_3" value="3">
<span class="label-body px-1">
a + b
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4220634931002647995_4">
<input class="form-check-input" type="radio" name="radio_4220634931002647995" id="radio_4220634931002647995_4" value="4">
<span class="label-body px-1">
3a
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4220634931002647995_5">
<input class="form-check-input" type="radio" name="radio_4220634931002647995" id="radio_4220634931002647995_5" value="5">
<span class="label-body px-1">
a - b
</span>
</label>
</div>
</div>
</div>
<div id="4220634931002647995_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_4220634931002647995"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 4;
var msgBox = document.getElementById('4220634931002647995_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_4220634931002647995")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_4220634931002647995")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Express vector <strong>d</strong> in terms of <strong>a</strong> and <strong>b</strong>:</p>
<div class="cell" data-hold="true" data-execution_count="59">
<div class="cell-output cell-output-display" data-execution_count="59">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="7419942125058795152" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_7419942125058795152">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_7419942125058795152_1">
<input class="form-check-input" type="radio" name="radio_7419942125058795152" id="radio_7419942125058795152_1" value="1">
<span class="label-body px-1">
3a
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7419942125058795152_2">
<input class="form-check-input" type="radio" name="radio_7419942125058795152" id="radio_7419942125058795152_2" value="2">
<span class="label-body px-1">
3b
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7419942125058795152_3">
<input class="form-check-input" type="radio" name="radio_7419942125058795152" id="radio_7419942125058795152_3" value="3">
<span class="label-body px-1">
b-a
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7419942125058795152_4">
<input class="form-check-input" type="radio" name="radio_7419942125058795152" id="radio_7419942125058795152_4" value="4">
<span class="label-body px-1">
a - b
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7419942125058795152_5">
<input class="form-check-input" type="radio" name="radio_7419942125058795152" id="radio_7419942125058795152_5" value="5">
<span class="label-body px-1">
a + b
</span>
</label>
</div>
</div>
</div>
<div id="7419942125058795152_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_7419942125058795152"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 5;
var msgBox = document.getElementById('7419942125058795152_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_7419942125058795152")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_7419942125058795152")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Express vector <strong>e</strong> in terms of <strong>a</strong> and <strong>b</strong>:</p>
<div class="cell" data-hold="true" data-execution_count="60">
<div class="cell-output cell-output-display" data-execution_count="60">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="4156908700407626613" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_4156908700407626613">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_4156908700407626613_1">
<input class="form-check-input" type="radio" name="radio_4156908700407626613" id="radio_4156908700407626613_1" value="1">
<span class="label-body px-1">
3b
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4156908700407626613_2">
<input class="form-check-input" type="radio" name="radio_4156908700407626613" id="radio_4156908700407626613_2" value="2">
<span class="label-body px-1">
a + b
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4156908700407626613_3">
<input class="form-check-input" type="radio" name="radio_4156908700407626613" id="radio_4156908700407626613_3" value="3">
<span class="label-body px-1">
a - b
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4156908700407626613_4">
<input class="form-check-input" type="radio" name="radio_4156908700407626613" id="radio_4156908700407626613_4" value="4">
<span class="label-body px-1">
3a
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4156908700407626613_5">
<input class="form-check-input" type="radio" name="radio_4156908700407626613" id="radio_4156908700407626613_5" value="5">
<span class="label-body px-1">
b-a
</span>
</label>
</div>
</div>
</div>
<div id="4156908700407626613_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_4156908700407626613"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('4156908700407626613_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_4156908700407626613")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_4156908700407626613")
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>If <code>xs=[1, 2, 3, 4]</code> and <code>f(x) = x^2</code> which of these will not produce the vector <code>[1, 4, 9, 16]</code>?</p>
<div class="cell" data-hold="true" data-execution_count="61">
<div class="cell-output cell-output-display" data-execution_count="61">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="13715890711580048732" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_13715890711580048732">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_13715890711580048732_1">
<input class="form-check-input" type="radio" name="radio_13715890711580048732" id="radio_13715890711580048732_1" value="1">
<span class="label-body px-1">
<code>f.(xs)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13715890711580048732_2">
<input class="form-check-input" type="radio" name="radio_13715890711580048732" id="radio_13715890711580048732_2" value="2">
<span class="label-body px-1">
<code>map(f, xs)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13715890711580048732_3">
<input class="form-check-input" type="radio" name="radio_13715890711580048732" id="radio_13715890711580048732_3" value="3">
<span class="label-body px-1">
<code>[f(x) for x in xs]</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_13715890711580048732_4">
<input class="form-check-input" type="radio" name="radio_13715890711580048732" id="radio_13715890711580048732_4" value="4">
<span class="label-body px-1">
All three of them work
</span>
</label>
</div>
</div>
</div>
<div id="13715890711580048732_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_13715890711580048732"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 4;
var msgBox = document.getElementById('13715890711580048732_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_13715890711580048732")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_13715890711580048732")
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>Let <span class="math inline">\(f(x) = \sin(x)\)</span> and <span class="math inline">\(g(x) = \cos(x)\)</span>. In the interval <span class="math inline">\([0, 2\pi]\)</span> the zeros of <span class="math inline">\(g(x)\)</span> are given by</p>
<div class="cell" data-execution_count="62">
<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>zs <span class="op">=</span> [<span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, <span class="fl">3</span>pi<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="62">
<pre><code>2-element Vector{Float64}:
1.5707963267948966
4.71238898038469</code></pre>
</div>
</div>
<p>What construct will give the function values of <span class="math inline">\(f\)</span> at the zeros of <span class="math inline">\(g\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="63">
<div class="cell-output cell-output-display" data-execution_count="63">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="14664177588021501663" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_14664177588021501663">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_14664177588021501663_1">
<input class="form-check-input" type="radio" name="radio_14664177588021501663" id="radio_14664177588021501663_1" value="1">
<span class="label-body px-1">
<code>sin(zs)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14664177588021501663_2">
<input class="form-check-input" type="radio" name="radio_14664177588021501663" id="radio_14664177588021501663_2" value="2">
<span class="label-body px-1">
<code>sin.(zs)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14664177588021501663_3">
<input class="form-check-input" type="radio" name="radio_14664177588021501663" id="radio_14664177588021501663_3" value="3">
<span class="label-body px-1">
<code>sin(.zs)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14664177588021501663_4">
<input class="form-check-input" type="radio" name="radio_14664177588021501663" id="radio_14664177588021501663_4" value="4">
<span class="label-body px-1">
<code>.sin(zs)</code>
</span>
</label>
</div>
</div>
</div>
<div id="14664177588021501663_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_14664177588021501663"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('14664177588021501663_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_14664177588021501663")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_14664177588021501663")
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>If <code>zs = [1,4,9,16]</code> which of these commands will return <code>[1.0, 2.0, 3.0, 4.0]</code>?</p>
<div class="cell" data-hold="true" data-execution_count="64">
<div class="cell-output cell-output-display" data-execution_count="64">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="7953307207162496861" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_7953307207162496861">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_7953307207162496861_1">
<input class="form-check-input" type="radio" name="radio_7953307207162496861" id="radio_7953307207162496861_1" value="1">
<span class="label-body px-1">
<code>sqrt(zs)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7953307207162496861_2">
<input class="form-check-input" type="radio" name="radio_7953307207162496861" id="radio_7953307207162496861_2" value="2">
<span class="label-body px-1">
<code>sqrt.(zs)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7953307207162496861_3">
<input class="form-check-input" type="radio" name="radio_7953307207162496861" id="radio_7953307207162496861_3" value="3">
<span class="label-body px-1">
<code>zs^(1/2)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7953307207162496861_4">
<input class="form-check-input" type="radio" name="radio_7953307207162496861" id="radio_7953307207162496861_4" value="4">
<span class="label-body px-1">
<code>zs^(1./2)</code>
</span>
</label>
</div>
</div>
</div>
<div id="7953307207162496861_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_7953307207162496861"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('7953307207162496861_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_7953307207162496861")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_7953307207162496861")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
</section>
</main> <!-- /main -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const clipboard = new window.ClipboardJS('.code-copy-button', {
target: function(trigger) {
return trigger.previousElementSibling;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
setTimeout(function() {
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
});
function tippyHover(el, contentFn) {
const config = {
allowHTML: true,
content: contentFn,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start'
};
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
let href = ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
return note.innerHTML;
});
}
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const cites = ref.parentNode.getAttribute('data-cites').split(' ');
tippyHover(ref, function() {
var popup = window.document.createElement('div');
cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
var filterRegex = new RegExp('/' + window.location.host + '/');
var isInternal = (href) => {
return filterRegex.test(href) || localhostRegex.test(href);
}
// Inspect non-navigation links and adorn them if external
var links = window.document.querySelectorAll('a:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external)');
for (var i=0; i<links.length; i++) {
const link = links[i];
if (!isInternal(link.href)) {
// target, if specified
link.setAttribute("target", "_blank");
}
}
});
</script>
<nav class="page-navigation">
<div class="nav-page nav-page-previous">
<a href="../precalc/logical_expressions.html" class="pagination-link">
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Inequalities, Logical expressions</span></span>
</a>
</div>
<div class="nav-page nav-page-next">
<a href="../precalc/ranges.html" class="pagination-link">
<span class="nav-page-text"><span class="chapter-number">6</span>&nbsp; <span class="chapter-title">Ranges and Sets</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>