CalculusWithJuliaNotes.jl/quarto/0e7f54ed/differentiable_vector_calculus/vectors.html
2022-08-11 13:15:19 -04:00

3212 lines
215 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.0.32">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>Calculus with Julia - 53&nbsp; Vectors and matrices</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="../differentiable_vector_calculus/vector_valued_functions.html" rel="next">
<link href="../differentiable_vector_calculus/polar_coordinates.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">53</span>&nbsp; <span class="chapter-title">Vectors and matrices</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 collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="false">Precalculus Concepts</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/calculator.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">From calculator to computer</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/variables.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Variables</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/numbers_types.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Number systems</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/logical_expressions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Inequalities, Logical expressions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/vectors.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Vectors</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/ranges.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">6</span>&nbsp; <span class="chapter-title">Ranges and Sets</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">7</span>&nbsp; <span class="chapter-title">Functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">The Graph of a Function</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/transformations.html" class="sidebar-item-text sidebar-link"><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" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-6" aria-expanded="true">Differential vector calculus</a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-6" aria-expanded="true">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-6" class="collapse list-unstyled sidebar-section depth1 show">
<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 active"><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="#vector-addition-scalar-multiplication" id="toc-vector-addition-scalar-multiplication" class="nav-link active" data-scroll-target="#vector-addition-scalar-multiplication"> <span class="header-section-number">53.1</span> Vector addition, scalar multiplication</a></li>
<li><a href="#the-length-and-direction-of-a-vector" id="toc-the-length-and-direction-of-a-vector" class="nav-link" data-scroll-target="#the-length-and-direction-of-a-vector"> <span class="header-section-number">53.2</span> The length and direction of a vector</a></li>
<li><a href="#visualization-of-vectors" id="toc-visualization-of-vectors" class="nav-link" data-scroll-target="#visualization-of-vectors"> <span class="header-section-number">53.3</span> Visualization of vectors</a></li>
<li><a href="#aside-review-of-julias-use-of-dots-to-work-with-containers" id="toc-aside-review-of-julias-use-of-dots-to-work-with-containers" class="nav-link" data-scroll-target="#aside-review-of-julias-use-of-dots-to-work-with-containers"> <span class="header-section-number">53.4</span> Aside: review of <code>Julia</code>s use of dots to work with containers</a></li>
<li><a href="#the-dot-product" id="toc-the-dot-product" class="nav-link" data-scroll-target="#the-dot-product"> <span class="header-section-number">53.5</span> The dot product</a></li>
<li><a href="#matrices" id="toc-matrices" class="nav-link" data-scroll-target="#matrices"> <span class="header-section-number">53.6</span> Matrices</a>
<ul class="collapse">
<li><a href="#matrix-multiplication" id="toc-matrix-multiplication" class="nav-link" data-scroll-target="#matrix-multiplication"> <span class="header-section-number">53.6.1</span> Matrix multiplication</a></li>
<li><a href="#matrices-in-julia" id="toc-matrices-in-julia" class="nav-link" data-scroll-target="#matrices-in-julia"> <span class="header-section-number">53.6.2</span> Matrices in Julia</a></li>
</ul></li>
<li><a href="#cross-product" id="toc-cross-product" class="nav-link" data-scroll-target="#cross-product"> <span class="header-section-number">53.7</span> Cross product</a></li>
<li><a href="#questions" id="toc-questions" class="nav-link" data-scroll-target="#questions"> <span class="header-section-number">53.8</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/differentiable_vector_calculus/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">53</span>&nbsp; <span class="chapter-title">Vectors and matrices</span></h1>
</div>
<div class="quarto-title-meta">
</div>
</header>
<p>This section uses these add-on package:</p>
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">CalculusWithJulia</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">Plots</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">LinearAlgebra</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">SymPy</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<hr>
<p>In <a href="../precalc/vectors.html">vectors</a> we introduced the concept of a vector. For <code>Julia</code>, vectors are a useful storage container and are used to hold, for example, zeros of functions or the coefficients of a polynomial. This section is about their mathematical properties. A <a href="https://en.wikipedia.org/wiki/Euclidean_vector">vector</a> mathematically is a geometric object with two attributes a magnitude and a direction. (The direction is undefined in the case the magnitude is <span class="math inline">\(0\)</span>.) Vectors are typically visualized with an arrow, where the anchoring of the arrow is context dependent and is not particular to a given vector.</p>
<p>Vectors and points are related, but distinct. They are identified when the tail of the vector is taken to be the origin. Lets focus on <span class="math inline">\(3\)</span> dimensions. Mathematically, the notation for a point is <span class="math inline">\(p=(x,y,z)\)</span> while the notation for a vector is <span class="math inline">\(\vec{v} = \langle x, y, z \rangle\)</span>. The <span class="math inline">\(i\)</span>th component in a vector is referenced by a subscript: <span class="math inline">\(v_i\)</span>. With this, we may write a typical vector as <span class="math inline">\(\vec{v} = \langle v_1, v_2, \dots, v_n \rangle\)</span> and a vector in <span class="math inline">\(n=3\)</span> as <span class="math inline">\(\vec{v} =\langle v_1, v_2, v_3 \rangle\)</span>. The different grouping notation distinguishes the two objects. As another example, the notation <span class="math inline">\(\{x, y, z\}\)</span> indicates a set. Vectors and points may be <em>identified</em> by anchoring the vector at the origin. Sets are quite different from both, as the order of their entries is not unique.</p>
<p>In <code>Julia</code>, the notation to define a point and a vector would be identical, using square brackets to group like-type values: <code>[x, y, z]</code>. The notation <code>(x,y,z)</code> would form a <a href="https://en.wikipedia.org/wiki/Euclidean_vector">tuple</a> which though similar in many respects, are different, as tuples do not have the operations associated with a point or a vector defined for them.</p>
<p>The square bracket constructor has some subtleties:</p>
<ul>
<li><code>[x,y,z]</code> calls <code>vect</code> and creates a 1-dimensional array</li>
<li><code>[x; y; z]</code> calls <code>vcat</code> to <strong>v</strong>ertically con<strong>cat</strong>enate values together. With simple (scalar) values <code>[x,y,z]</code> and <code>[x; y; z]</code> are identical, but not in other cases. (For example, is <code>A</code> is a matrix then <code>[A, A]</code> is a vector of matrices, <code>[A; A]</code> is a matrix combined from the two pieces.</li>
<li><code>[x y z]</code> calls <code>hcat</code> to <strong>h</strong>orizontally con<strong>cat</strong>enate values together. If <code>x</code>, <code>y</code> are numbers then <code>[x y]</code> is <em>not</em> a vector, but rather a <span class="math inline">\(2\)</span>D array with a single row and two columns.</li>
<li>finally <code>[w x; y z]</code> calls <code>hvcat</code> to horizontally and vertically concatenate values together to create a container in two dimensions, like a matrix.</li>
</ul>
<p>(A vector, mathematically, is a one-dimensional collection of numbers, a matrix a two-dimensional <em>rectangular</em> collection of numbers, and an array an <span class="math inline">\(n\)</span>-dimensional rectangular-like collection of numbers. In <code>Julia</code>, a vector can hold a collection of objects of arbitrary type, though each will be promoted to a common type.)</p>
<section id="vector-addition-scalar-multiplication" class="level2" data-number="53.1">
<h2 data-number="53.1" class="anchored" data-anchor-id="vector-addition-scalar-multiplication"><span class="header-section-number">53.1</span> Vector addition, scalar multiplication</h2>
<p>As seen earlier, vectors have some arithmetic operations defined for them. As a typical use of vectors, mathematically, is to collect the <span class="math inline">\(x\)</span>, <span class="math inline">\(y\)</span>, and <span class="math inline">\(z\)</span> (in <span class="math inline">\(3\)</span>D) components together, operations like addition and subtraction operate component wise. With this, addition can be visualized geometrically: put the tail of <span class="math inline">\(\vec{v}\)</span> at the tip of <span class="math inline">\(\vec{u}\)</span> and draw a vector from the tail of <span class="math inline">\(\vec{u}\)</span> to the tip of <span class="math inline">\(\vec{v}\)</span> and you have <span class="math inline">\(\vec{u}+\vec{v}\)</span>. This is identical by <span class="math inline">\(\vec{v} + \vec{u}\)</span> as vector addition is commutative. Unless <span class="math inline">\(\vec{u}\)</span> and <span class="math inline">\(\vec{v}\)</span> are parallel or one has <span class="math inline">\(0\)</span> length, the addition will create a vector with a different direction from the two.</p>
<p>Another operation for vectors is <em>scalar</em> multiplication. Geometrically this changes the magnitude, but not the direction of a vector, when the <em>scalar</em> is positive. Scalar multiplication is defined component wise, like addition so the <span class="math inline">\(i\)</span>th component of <span class="math inline">\(c \vec{v}\)</span> is <span class="math inline">\(c\)</span> times the <span class="math inline">\(i\)</span>th component of <span class="math inline">\(\vec{v}\)</span>. When the scalar is negative, the direction is “reversed.”</p>
<p>To illustrate we define two <span class="math inline">\(3\)</span>-dimensional vectors:</p>
<div class="cell" data-execution_count="4">
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>u, 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 class="fl">3</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="5">
<pre><code>([1, 2, 3], [4, 3, 2])</code></pre>
</div>
</div>
<p>The sum is component-wise summation (<code>1+4, 2+3, 3+2</code>):</p>
<div class="cell" data-execution_count="5">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>u <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="6">
<pre><code>3-element Vector{Int64}:
5
5
5</code></pre>
</div>
</div>
<p>For addition, as the components must pair off, the two vectors being added must be the same dimension.</p>
<p>Scalar multiplication by <code>2</code>, say, multiplies each entry by <code>2</code>:</p>
<div class="cell" data-execution_count="6">
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="fl">2</span> <span class="op">*</span> u</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="7">
<pre><code>3-element Vector{Int64}:
2
4
6</code></pre>
</div>
</div>
</section>
<section id="the-length-and-direction-of-a-vector" class="level2" data-number="53.2">
<h2 data-number="53.2" class="anchored" data-anchor-id="the-length-and-direction-of-a-vector"><span class="header-section-number">53.2</span> The length and direction of a vector</h2>
<p>If a vector <span class="math inline">\(\vec{v} = \langle v_1, v_2, \dots, v_n\rangle\)</span> then the <em>norm</em> (also Euclidean norm or length) of <span class="math inline">\(\vec{v}\)</span> is defined by:</p>
<p><span class="math display">\[
\| \vec{v} \| = \sqrt{ v_1^2 + v_2^2 + \cdots + v_n^2}.
\]</span></p>
<p>The definition of a norm leads to a few properties. First, if <span class="math inline">\(c\)</span> is a scalar, <span class="math inline">\(\| c\vec{v} \| = |c| \| \vec{v} \|\)</span> - which says scalar multiplication by <span class="math inline">\(c\)</span> changes the length by <span class="math inline">\(|c|\)</span>. (Sometimes, scalar multiplication is described as “scaling by….”) The other property is an analog of the triangle inequality, in which for any two vectors <span class="math inline">\(\| \vec{v} + \vec{w} \| \leq \| \vec{v} \| + \| \vec{w} \|\)</span>. The right hand side is equal only when the two vectors are parallel.</p>
<p>A vector with length <span class="math inline">\(1\)</span> is called a <em>unit</em> vector. Dividing a non-zero vector by its norm will yield a unit vector, a consequence of the first property above. Unit vectors are often written with a “hat:” <span class="math inline">\(\hat{v}\)</span>.</p>
<p>The direction indicated by <span class="math inline">\(\vec{v}\)</span> can be visualized as an angle in <span class="math inline">\(2\)</span>- or <span class="math inline">\(3\)</span>-dimensions, but in higher dimensions, visualization is harder. For <span class="math inline">\(2\)</span>-dimensions, we might associate with a vector, its unit vector. This in turn may be identified with a point on the unit circle, which from basic trigonometry can be associated with an angle. Something similar, can be done in <span class="math inline">\(3\)</span> dimensions, using two angles. However, the “direction” of a vector is best thought of in terms of its associated unit vector. With this, we have a decomposition of a non-zero vector <span class="math inline">\(\vec{v}\)</span> into a magnitude and a direction when we write <span class="math inline">\(\vec{v} = \|\vec{v}\| \cdot (\vec{v} / \|\vec{v}\|)=\|\vec{v}\| \hat{v}\)</span>.</p>
</section>
<section id="visualization-of-vectors" class="level2" data-number="53.3">
<h2 data-number="53.3" class="anchored" data-anchor-id="visualization-of-vectors"><span class="header-section-number">53.3</span> Visualization of vectors</h2>
<p>Vectors may be visualized in <span class="math inline">\(2\)</span> or <span class="math inline">\(3\)</span> dimensions using <code>Plots</code>. In <span class="math inline">\(2\)</span> dimensions, the <code>quiver</code> function may be used. To graph a vector, it must have its tail placed at a point, so two values are needed.</p>
<p>To plot <code>u=[1,2]</code> from <code>p=[0,0]</code> we have the following usage:</p>
<div class="cell" data-execution_count="7">
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">quiver</span>([<span class="fl">0</span>],[<span class="fl">0</span>], quiver<span class="op">=</span>([<span class="fl">1</span>],[<span class="fl">2</span>]))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="8">
<p><img src="vectors_files/figure-html/cell-8-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The cumbersome syntax is typical here. We naturally describe vectors and points using <code>[a,b,c]</code> to combine them, but the plotting functions want to plot many such at a time and expect vectors containing just the <code>x</code> values, just the <code>y</code> values, etc. The above usage looks a bit odd, as these vectors of <code>x</code> and <code>y</code> values have only one entry. Converting from the one representation to the other requires reshaping the data. We will use the <code>unzip</code> function from <code>CalculusWithJulia</code> which in turn just uses the the <code>invert</code> function of the <code>SplitApplyCombine</code> package (“return a new nested container by reversing the order of the nested container”) for the bulk of its work.</p>
<p>This function takes a vector of vectors, and returns a vector containing the <code>x</code> values, the <code>y</code> values, etc. So if <code>u=[1,2,3]</code> and <code>v=[4,5,6]</code>, then <code>unzip([u,v])</code> becomes <code>[[1,4],[2,5],[3,6]]</code>, etc. (The <code>zip</code> function in base does essentially the reverse operation, hence the name.) Notationally, <code>A = [u,v]</code> can have the third element of the first vector (<code>u</code>) accessed by <code>A[1][3]</code>, where as <code>unzip(A)[3][1]</code> will do the same. We use <code>unzip([u])</code> in the following, which for this <code>u</code> returns <code>([1],[2],[3])</code>. (Note the <code>[u]</code> to make a vector of a vector.)</p>
<p>With <code>unzip</code> defined, we can plot a <span class="math inline">\(2\)</span>-dimensional vector <code>v</code> anchored at point <code>p</code> through <code>quiver(unzip([p])..., quiver=unzip([v]))</code>.</p>
<p>To illustrate, the following defines <span class="math inline">\(3\)</span> vectors (the third through addition), then graphs all three, though in different starting points to emphasize the geometric interpretation of vector addition.</p>
<div class="cell" data-hold="true" data-execution_count="8">
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>u <span class="op">=</span> [<span class="fl">1</span>, <span class="fl">2</span>]</span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>v <span class="op">=</span> [<span class="fl">4</span>, <span class="fl">2</span>]</span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a>w <span class="op">=</span> u <span class="op">+</span> v</span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> [<span class="fl">0</span>,<span class="fl">0</span>]</span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a><span class="fu">quiver</span>(<span class="fu">unzip</span>([p])<span class="op">...</span>, quiver<span class="op">=</span><span class="fu">unzip</span>([u]))</span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true" tabindex="-1"></a><span class="fu">quiver!</span>(<span class="fu">unzip</span>([u])<span class="op">...</span>, quiver<span class="op">=</span><span class="fu">unzip</span>([v]))</span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true" tabindex="-1"></a><span class="fu">quiver!</span>(<span class="fu">unzip</span>([p])<span class="op">...</span>, quiver<span class="op">=</span><span class="fu">unzip</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="9">
<p><img src="vectors_files/figure-html/cell-9-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>Plotting a <span class="math inline">\(3\)</span>-d vector is not supported in all toolkits with <code>quiver</code>. A line segment may be substituted and can be produced with <code>plot(unzip([p,p+v])...)</code>. To avoid all these details, the <code>CalculusWithJulia</code> provides the <code>arrow!</code> function to <em>add</em> a vector to an existing plot. The function requires a point, <code>p</code>, and the vector, <code>v</code>:</p>
<p>With this, the above simplifies to:</p>
<div class="cell" data-hold="true" data-execution_count="9">
<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>u <span class="op">=</span> [<span class="fl">1</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> [<span class="fl">4</span>, <span class="fl">2</span>]</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a>w <span class="op">=</span> u <span class="op">+</span> v</span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> [<span class="fl">0</span>,<span class="fl">0</span>]</span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(legend<span class="op">=</span><span class="cn">false</span>)</span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(p, u)</span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(u, v)</span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(p, 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="10">
<p><img src="vectors_files/figure-html/cell-10-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The distinction between a point and a vector within <code>Julia</code> is only mental. We use the same storage type. Mathematically, we can <strong>identify</strong> a point and a vector, by considering the vector with its tail placed at the origin. In this case, the tip of the arrow is located at the point. But this is only an identification, though a useful one. It allows us to “add” a point and a vector (e.g., writing <span class="math inline">\(P + \vec{v}\)</span>) by imagining the point as a vector anchored at the origin.</p>
<p>To see that a unit vector has the same “direction” as the vector, we might draw them with different widths:</p>
<div class="cell" data-hold="true" data-execution_count="10">
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>v <span class="op">=</span> [<span class="fl">2</span>, <span class="fl">3</span>]</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a>u <span class="op">=</span> v <span class="op">/</span> <span class="fu">norm</span>(v)</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> [<span class="fl">0</span>, <span class="fl">0</span>]</span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(legend<span class="op">=</span><span class="cn">false</span>)</span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(p, v)</span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(p, u, linewidth<span class="op">=</span><span class="fl">5</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="11">
<p><img src="vectors_files/figure-html/cell-11-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The <code>norm</code> function is in the standard library, <code>LinearAlgebra</code>, which must be loaded first through the command <code>using LinearAlgebra</code>. (Though here it is redundant, as that package is loaded and reexported when the <code>CalculusWithJulia</code> package is loaded.)</p>
</section>
<section id="aside-review-of-julias-use-of-dots-to-work-with-containers" class="level2" data-number="53.4">
<h2 data-number="53.4" class="anchored" data-anchor-id="aside-review-of-julias-use-of-dots-to-work-with-containers"><span class="header-section-number">53.4</span> Aside: review of <code>Julia</code>s use of dots to work with containers</h2>
<p><code>Julia</code> makes use of the dot, “<code>.</code>”, in a few ways to simplify usage when containers, such as vectors, are involved:</p>
<ul>
<li><strong>Splatting</strong>. The use of three dots, “<code>...</code>”, to “splat” the values from a container like a vector (or tuple) into <em>arguments</em> of a function can be very convenient. It was used above in the definition for the <code>arrow!</code> function: essentially <code>quiver!(unzip([p])..., quiver=unzip([v]))</code>. The <code>quiver</code> function expects <span class="math inline">\(2\)</span> (or <span class="math inline">\(3\)</span>) arguments describing the <code>xs</code> and <code>ys</code> (and sometimes <code>zs</code>). The <code>unzip</code> function returns these in a container, so splatting is used to turn the values in the container into distinct arguments of the function. Whereas the <code>quiver</code> argument expects a tuple of vectors, so no splatting is used for that part of the definition. Another use of splatting we will see is with functions of vectors. These can be defined in terms of the vectors components or the vector as a whole, as below:</li>
</ul>
<div class="cell" data-execution_count="11">
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x, y, z) <span class="op">=</span> x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> z<span class="op">^</span><span class="fl">2</span></span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(v) <span class="op">=</span> v[<span class="fl">1</span>]<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> v[<span class="fl">2</span>]<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> v[<span class="fl">3</span>]<span class="op">^</span><span class="fl">2</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="12">
<pre><code>f (generic function with 2 methods)</code></pre>
</div>
</div>
<p>The first uses the components and is arguably, much easier to read. The second uses indexing in the function body to access the components. It has an advantage, as it can more easily handle different length vectors (e.g.&nbsp;using <code>sum(v.^2)</code>). Both uses have their merits, though the latter is more idiomatic throughout <code>Julia</code>.</p>
<p>If a function is easier to write in terms of its components, but an interface expects a vector of components as it argument, then splatting can be useful, to go from one style to another, similar to this:</p>
<div class="cell" data-execution_count="12">
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="fu">g</span>(x, y, z) <span class="op">=</span> x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> z<span class="op">^</span><span class="fl">2</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a><span class="fu">g</span>(v) <span class="op">=</span> <span class="fu">g</span>(v<span class="op">...</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="13">
<pre><code>g (generic function with 2 methods)</code></pre>
</div>
</div>
<p>The splatting will mean <code>g(v)</code> eventually calls <code>g(x, y, z)</code> through <code>Julia</code>s multiple dispatch machinery when <code>v = [x, y, z]</code>.</p>
<p>(The three dots can also appear in the definition of the arguments to a function, but there the usage is not splatting but rather a specification of a variable number of arguments.)</p>
<ul>
<li><strong>Broadcasting</strong>. For a univariate function, <code>f</code>, and vector, <code>xs</code>, the call <code>f.(xs)</code> <em>broadcasts</em> <code>f</code> over each value of <code>xs</code> and returns a container holding all the values. This is a compact alternative to a comprehension when a function is defined. When <code>f</code> depends on more than one value, broadcasting can still be used: <code>f.(xs, ys)</code> will broadcast <code>f</code> over values formed from <em>both</em> <code>xs</code> and <code>ys</code>. Broadcasting has the extra feature (over <code>map</code>) of attempting to match up the shapes of <code>xs</code> and <code>ys</code> when they are not identical. (See the help page for <code>broadcast</code> for more details.)</li>
</ul>
<p>For example, if <code>xs</code> is a vector and <code>ys</code> a scalar, then the value in <code>ys</code> is repeated many times to match up with the values of <code>xs</code>. Or if <code>xs</code> and <code>ys</code> have different dimensions, the values of one will be repeated. Consider this:</p>
<div class="cell" data-execution_count="13">
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="fu">𝐟</span>(x,y) <span class="op">=</span> x <span class="op">+</span> y</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>𝐟 (generic function with 1 method)</code></pre>
</div>
</div>
<div class="cell" data-hold="true" data-execution_count="14">
<div class="sourceCode cell-code" id="cb18"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> [<span class="fl">0</span>, <span class="fl">1</span>]</span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a><span class="fu">𝐟</span>.(xs, ys)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="15">
<pre><code>2-element Vector{Int64}:
0
2</code></pre>
</div>
</div>
<p>This matches <code>xs</code> and <code>ys</code> to pass <code>(0,0)</code> and then <code>(1,1)</code> to <code>f</code>, returning <code>0</code> and <code>2</code>. Now consider</p>
<div class="cell" data-hold="true" data-execution_count="15">
<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>xs <span class="op">=</span> [<span class="fl">0</span>, <span class="fl">1</span>]; ys <span class="op">=</span> [<span class="fl">0</span> <span class="fl">1</span>] <span class="co"># xs is a column vector, ys a row vector</span></span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a><span class="fu">𝐟</span>.(xs, ys)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="16">
<pre><code>2×2 Matrix{Int64}:
0 1
1 2</code></pre>
</div>
</div>
<p>The two dimensions are different so for each value of <code>xs</code> the vector of <code>ys</code> is broadcast. This returns a matrix now. This will be important for some plotting usages where a grid (matrix) of values is needed.</p>
<p>At times using the “apply” notation: <code>x |&gt; f</code>, in place of using <code>f(x)</code> is useful, as it can move the wrapping function to the right of the expression. To broadcast, <code>.|&gt;</code> is available.</p>
</section>
<section id="the-dot-product" class="level2" data-number="53.5">
<h2 data-number="53.5" class="anchored" data-anchor-id="the-dot-product"><span class="header-section-number">53.5</span> The dot product</h2>
<p>There is no concept of multiplying two vectors, or for that matter dividing two vectors. However, there are two operations between vectors that are somewhat similar to multiplication, these being the dot product and the cross product. Each has an algebraic definition, but their geometric properties are what motivate their usage. We begin by discussing the dot product.</p>
<p>The dot product between two vectors can be viewed algebraically in terms of the following product. If <span class="math inline">\(\vec{v} = \langle v_1, v_2, \dots, v_n\rangle\)</span> and <span class="math inline">\(\vec{w} = \langle w_1, w_2, \dots, w_n\rangle\)</span>, then the <em>dot product</em> of <span class="math inline">\(\vec{v}\)</span> and <span class="math inline">\(\vec{w}\)</span> is defined by:</p>
<p><span class="math display">\[
\vec{v} \cdot \vec{w} = v_1 w_1 + v_2 w_2 + \cdots + v_n w_n.
\]</span></p>
<p>From this, we can see the relationship between the norm, or Euclidean length of a vector: <span class="math inline">\(\vec{v} \cdot \vec{v} = \| \vec{v} \|^2\)</span>. We can also see that the dot product is commutative, that is <span class="math inline">\(\vec{v} \cdot \vec{w} = \vec{w} \cdot \vec{v}\)</span>.</p>
<p>The dot product has an important geometrical interpolation. Two (non-parallel) vectors will lie in the same “plane”, even in higher dimensions. Within this plane, there will be an angle between them within <span class="math inline">\([0, \pi]\)</span>. Call this angle <span class="math inline">\(\theta\)</span>. (This means the angle between the two vectors is the same regardless of their order of consideration.) Then</p>
<p><span class="math display">\[
\vec{v} \cdot \vec{w} = \|\vec{v}\| \|\vec{w}\| \cos(\theta).
\]</span></p>
<p>If we denoted <span class="math inline">\(\hat{v} = \vec{v} / \| \vec{v} \|\)</span>, the unit vector in the direction of <span class="math inline">\(\vec{v}\)</span>, then by dividing, we see that <span class="math inline">\(\cos(\theta) = \hat{v} \cdot \hat{w}\)</span>. That is the angle does not depend on the magnitude of the vectors involved.</p>
<p>The dot product is computed in <code>Julia</code> by the <code>dot</code> function, which is in the <code>LinearAlgebra</code> package of the standard library. This must be loaded (as above) before its use either directly or through the <code>CalculusWithJulia</code> package:</p>
<div class="cell" data-execution_count="16">
<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="op">=</span> [<span class="fl">1</span>, <span class="fl">2</span>]</span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a>𝒗 <span class="op">=</span> [<span class="fl">2</span>, <span class="fl">1</span>]</span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a><span class="fu">dot</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>4</code></pre>
</div>
</div>
<div class="callout-note callout callout-style-default callout-captioned">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-caption-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>In <code>Julia</code>, the unicode operator entered by <code>\cdot[tab]</code> can also be used to mirror the math notation:</p>
</div>
</div>
<div class="cell" data-execution_count="17">
<div class="sourceCode cell-code" id="cb24"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a>𝒖 <span class="op"></span> 𝒗 <span class="co"># u \cdot[tab] v</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>4</code></pre>
</div>
</div>
<p>Continuing, to find the angle between <span class="math inline">\(\vec{u}\)</span> and <span class="math inline">\(\vec{v}\)</span>, we might do this:</p>
<div class="cell" data-execution_count="18">
<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>𝒄theta <span class="op">=</span> <span class="fu">dot</span>(𝒖<span class="op">/</span><span class="fu">norm</span>(𝒖), 𝒗<span class="op">/</span><span class="fu">norm</span>(𝒗))</span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a><span class="fu">acos</span>(𝒄theta)</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>0.6435011087932845</code></pre>
</div>
</div>
<p>The cosine of <span class="math inline">\(\pi/2\)</span> is <span class="math inline">\(0\)</span>, so two vectors which are at right angles to each other will have a dot product of <span class="math inline">\(0\)</span>:</p>
<div class="cell" data-hold="true" data-execution_count="19">
<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>u <span class="op">=</span> [<span class="fl">1</span>, <span class="fl">2</span>]</span>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a>v <span class="op">=</span> [<span class="fl">2</span>, <span class="op">-</span><span class="fl">1</span>]</span>
<span id="cb28-3"><a href="#cb28-3" aria-hidden="true" tabindex="-1"></a>u <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="20">
<pre><code>0</code></pre>
</div>
</div>
<p>In two dimensions, we learn that a perpendicular line to a line with slope <span class="math inline">\(m\)</span> will have slope <span class="math inline">\(-1/m\)</span>. From a <span class="math inline">\(2\)</span>-dimensional vector, say <span class="math inline">\(\vec{u} = \langle u_1, u_2 \rangle\)</span>, the slope is <span class="math inline">\(u_2/u_1\)</span> so a perpendicular vector to <span class="math inline">\(\vec{u}\)</span> will be <span class="math inline">\(\langle u_2, -u_1 \rangle\)</span>, as above. For higher dimensions, where the angle is harder to visualize, the dot product defines perpendicularness, or <em>orthogonality</em>.</p>
<p>For example, these two vectors are orthogonal, as their dot product is <span class="math inline">\(0\)</span>, even though we cant readily visualize them:</p>
<div class="cell" data-hold="true" data-execution_count="20">
<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>u <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="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a>v <span class="op">=</span> [<span class="op">-</span><span class="fl">30</span>, <span class="fl">4</span>, <span class="fl">3</span>, <span class="fl">2</span>, <span class="fl">1</span>]</span>
<span id="cb30-3"><a href="#cb30-3" aria-hidden="true" tabindex="-1"></a>u <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="21">
<pre><code>0</code></pre>
</div>
</div>
<section id="projection" class="level4">
<h4 class="anchored" data-anchor-id="projection">Projection</h4>
<p>From right triangle trigonometry, we learn that <span class="math inline">\(\cos(\theta) = \text{adjacent}/\text{hypotenuse}\)</span>. If we use a vector, <span class="math inline">\(\vec{h}\)</span> for the hypotenuse, and <span class="math inline">\(\vec{a} = \langle 1, 0 \rangle\)</span>, we have this picture:</p>
<div class="cell" data-hold="true" data-execution_count="21">
<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>h <span class="op">=</span> [<span class="fl">2</span>, <span class="fl">3</span>]</span>
<span id="cb32-2"><a href="#cb32-2" aria-hidden="true" tabindex="-1"></a>a <span class="op">=</span> [<span class="fl">1</span>, <span class="fl">0</span>] <span class="co"># unit vector</span></span>
<span id="cb32-3"><a href="#cb32-3" aria-hidden="true" tabindex="-1"></a>h_hat <span class="op">=</span> h <span class="op">/</span> <span class="fu">norm</span>(h)</span>
<span id="cb32-4"><a href="#cb32-4" aria-hidden="true" tabindex="-1"></a>theta <span class="op">=</span> <span class="fu">acos</span>(h_hat <span class="op"></span> a)</span>
<span id="cb32-5"><a href="#cb32-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb32-6"><a href="#cb32-6" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(legend<span class="op">=</span><span class="cn">false</span>)</span>
<span id="cb32-7"><a href="#cb32-7" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>([<span class="fl">0</span>,<span class="fl">0</span>], h)</span>
<span id="cb32-8"><a href="#cb32-8" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>([<span class="fl">0</span>,<span class="fl">0</span>], <span class="fu">norm</span>(h) <span class="op">*</span> <span class="fu">cos</span>(theta) <span class="op">*</span> a)</span>
<span id="cb32-9"><a href="#cb32-9" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>([<span class="fl">0</span>,<span class="fl">0</span>], a, linewidth<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="22">
<p><img src="vectors_files/figure-html/cell-22-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>We used vectors to find the angle made by <code>h</code>, and from there, using the length of the hypotenuse is <code>norm(h)</code>, we can identify the length of the adjacent side, it being the length of the hypotenuse times the cosine of <span class="math inline">\(\theta\)</span>. Geometrically, we call the vector <code>norm(h) * cos(theta) * a</code> the <em>projection</em> of <span class="math inline">\(\vec{h}\)</span> onto <span class="math inline">\(\vec{a}\)</span>, the word coming from the shadow <span class="math inline">\(\vec{h}\)</span> would cast on the direction of <span class="math inline">\(\vec{a}\)</span> were there light coming perpendicular to <span class="math inline">\(\vec{a}\)</span>.</p>
<p>The projection can be made for any pair of vectors, and in any dimension <span class="math inline">\(n &gt; 1\)</span>. The projection of <span class="math inline">\(\vec{u}\)</span> on <span class="math inline">\(\vec{v}\)</span> would be a vector of length <span class="math inline">\(\vec{u}\)</span> (the hypotenuse) times the cosine of the angle in the direction of <span class="math inline">\(\vec{v}\)</span>. In dot-product notation:</p>
<p><span class="math display">\[
proj_{\vec{v}}(\vec{u}) = \| \vec{u} \| \frac{\vec{u}\cdot\vec{v}}{\|\vec{u}\|\|\vec{v}\|} \frac{\vec{v}}{\|\vec{v}\|}.
\]</span></p>
<p>This can simplify. After cancelling, and expressing norms in terms of dot products, we have:</p>
<p><span class="math display">\[
proj_{\vec{v}}(\vec{u}) = \frac{\vec{u} \cdot \vec{v}}{\vec{v} \cdot \vec{v}} \vec{v} = (\vec{u} \cdot \hat{v}) \hat{v},
\]</span></p>
<p>where <span class="math inline">\(\hat{v}\)</span> is the unit vector in the direction of <span class="math inline">\(\vec{v}\)</span>.</p>
<section id="example" class="level5">
<h5 class="anchored" data-anchor-id="example">Example</h5>
<p>A pendulum, a bob on a string, swings back and forth due to the force of gravity. When the bob is displaced from rest by an angle <span class="math inline">\(\theta\)</span>, then the tension force of the string on the bob is directed along the string and has magnitude given by the <em>projection</em> of the force due to gravity.</p>
<p>A <a href="https://en.wikipedia.org/wiki/Free_body_diagram">force diagram</a> is a useful visualization device of physics to illustrate the applied forces involved in a scenario. In this case the bob has two forces acting on it: a force due to tension in the string of unknown magnitude, but in the direction of the string; and a force due to gravity. The latter is in the downward direction and has magnitude <span class="math inline">\(mg\)</span>, <span class="math inline">\(g=9.8m/sec^2\)</span> being the gravitational constant.</p>
<div class="cell" data-execution_count="22">
<div class="sourceCode cell-code" id="cb33"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a>𝗍heta <span class="op">=</span> <span class="cn">pi</span><span class="op">/</span><span class="fl">12</span></span>
<span id="cb33-2"><a href="#cb33-2" aria-hidden="true" tabindex="-1"></a>𝗆ass, 𝗀ravity <span class="op">=</span> <span class="fl">1</span><span class="op">/</span><span class="fl">9.8</span>, <span class="fl">9.8</span></span>
<span id="cb33-3"><a href="#cb33-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb33-4"><a href="#cb33-4" aria-hidden="true" tabindex="-1"></a>𝗅 <span class="op">=</span> [<span class="fu">-sin</span>(𝗍heta), <span class="fu">cos</span>(𝗍heta)]</span>
<span id="cb33-5"><a href="#cb33-5" aria-hidden="true" tabindex="-1"></a>𝗉 <span class="op">=</span> <span class="op">-</span>𝗅</span>
<span id="cb33-6"><a href="#cb33-6" aria-hidden="true" tabindex="-1"></a>𝖥g <span class="op">=</span> [<span class="fl">0</span>, <span class="op">-</span>𝗆ass <span class="op">*</span> 𝗀ravity]</span>
<span id="cb33-7"><a href="#cb33-7" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(legend<span class="op">=</span><span class="cn">false</span>)</span>
<span id="cb33-8"><a href="#cb33-8" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(𝗉, 𝗅)</span>
<span id="cb33-9"><a href="#cb33-9" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(𝗉, 𝖥g)</span>
<span id="cb33-10"><a href="#cb33-10" aria-hidden="true" tabindex="-1"></a><span class="fu">scatter!</span>(𝗉[<span class="fl">1</span><span class="op">:</span><span class="fl">1</span>], 𝗉[<span class="fl">2</span><span class="op">:</span><span class="fl">2</span>], markersize<span class="op">=</span><span class="fl">5</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="23">
<p><img src="vectors_files/figure-html/cell-23-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The magnitude of the tension force is exactly that of the force of gravity projected onto <span class="math inline">\(\vec{l}\)</span>, as the bob is not accelerating in that direction. The component of the gravity force in the perpendicular direction is the part of the gravitational force that causes acceleration in the pendulum. Here we find the projection onto <span class="math inline">\(\vec{l}\)</span> and visualize the two components of the gravitational force.</p>
<div class="cell" data-execution_count="23">
<div class="sourceCode cell-code" id="cb34"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(legend<span class="op">=</span><span class="cn">false</span>, aspect_ratio<span class="op">=:</span>equal)</span>
<span id="cb34-2"><a href="#cb34-2" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(𝗉, 𝗅)</span>
<span id="cb34-3"><a href="#cb34-3" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(𝗉, 𝖥g)</span>
<span id="cb34-4"><a href="#cb34-4" aria-hidden="true" tabindex="-1"></a><span class="fu">scatter!</span>(𝗉[<span class="fl">1</span><span class="op">:</span><span class="fl">1</span>], 𝗉[<span class="fl">2</span><span class="op">:</span><span class="fl">2</span>], markersize<span class="op">=</span><span class="fl">5</span>)</span>
<span id="cb34-5"><a href="#cb34-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb34-6"><a href="#cb34-6" aria-hidden="true" tabindex="-1"></a>𝗉roj <span class="op">=</span> (𝖥g <span class="op"></span> 𝗅) <span class="op">/</span> (𝗅 <span class="op"></span> 𝗅) <span class="op">*</span> 𝗅 <span class="co"># force of gravity in direction of tension</span></span>
<span id="cb34-7"><a href="#cb34-7" aria-hidden="true" tabindex="-1"></a>𝗉orth <span class="op">=</span> 𝖥g <span class="op">-</span> 𝗉roj <span class="co"># force of gravity perpendicular to tension</span></span>
<span id="cb34-8"><a href="#cb34-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb34-9"><a href="#cb34-9" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(𝗉, 𝗉roj)</span>
<span id="cb34-10"><a href="#cb34-10" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(𝗉, 𝗉orth, linewidth<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="24">
<p><img src="vectors_files/figure-html/cell-24-output-1.svg" class="img-fluid"></p>
</div>
</div>
</section>
<section id="example-1" class="level5">
<h5 class="anchored" data-anchor-id="example-1">Example</h5>
<p>Starting with three vectors, we can create three orthogonal vectors using projection and subtraction. The creation of <code>porth</code> above is the pattern we will exploit.</p>
<p>Lets begin with three vectors in <span class="math inline">\(R^3\)</span>:</p>
<div class="cell" data-execution_count="24">
<div class="sourceCode cell-code" id="cb35"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a>u <span class="op">=</span> [<span class="fl">1</span>, <span class="fl">2</span>, <span class="fl">3</span>]</span>
<span id="cb35-2"><a href="#cb35-2" 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>
<span id="cb35-3"><a href="#cb35-3" aria-hidden="true" tabindex="-1"></a>w <span class="op">=</span> [<span class="fl">1</span>, <span class="fl">2</span>, <span class="fl">4</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="25">
<pre><code>3-element Vector{Int64}:
1
2
4</code></pre>
</div>
</div>
<p>We can find a vector from <code>v</code> orthogonal to <code>u</code> using:</p>
<div class="cell" data-execution_count="25">
<div class="sourceCode cell-code" id="cb37"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb37-1"><a href="#cb37-1" aria-hidden="true" tabindex="-1"></a><span class="fu">unit_vec</span>(u) <span class="op">=</span> u <span class="op">/</span> <span class="fu">norm</span>(u)</span>
<span id="cb37-2"><a href="#cb37-2" aria-hidden="true" tabindex="-1"></a><span class="fu">projection</span>(u, v) <span class="op">=</span> (u <span class="op"></span> <span class="fu">unit_vec</span>(v)) <span class="op">*</span> <span class="fu">unit_vec</span>(v)</span>
<span id="cb37-3"><a href="#cb37-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb37-4"><a href="#cb37-4" aria-hidden="true" tabindex="-1"></a>vₚ <span class="op">=</span> v <span class="op">-</span> <span class="fu">projection</span>(v, u)</span>
<span id="cb37-5"><a href="#cb37-5" aria-hidden="true" tabindex="-1"></a>wₚ <span class="op">=</span> w <span class="op">-</span> <span class="fu">projection</span>(w, u) <span class="op">-</span> <span class="fu">projection</span>(w, 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="26">
<pre><code>3-element Vector{Float64}:
-0.33333333333333265
-0.3333333333333336
0.33333333333333354</code></pre>
</div>
</div>
<p>We can verify the orthogonality through:</p>
<div class="cell" data-execution_count="26">
<div class="sourceCode cell-code" id="cb39"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb39-1"><a href="#cb39-1" aria-hidden="true" tabindex="-1"></a>u <span class="op"></span> vₚ, u <span class="op"></span> wₚ, vₚ <span class="op"></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="27">
<pre><code>(-3.3306690738754696e-16, 8.881784197001252e-16, 3.677613769070831e-16)</code></pre>
</div>
</div>
<p>This only works when the three vectors do not all lie in the same plane. In general, this is the beginning of the <a href="https://en.wikipedia.org/wiki/Gram-Schmidt_process">Gram-Schmidt</a> process for creating <em>orthogonal</em> vectors from a collection of vectors.</p>
</section>
</section>
<section id="algebraic-properties" class="level4">
<h4 class="anchored" data-anchor-id="algebraic-properties">Algebraic properties</h4>
<p>The dot product is similar to multiplication, but different, as it is an operation defined between vectors of the same dimension. However, many algebraic properties carry over:</p>
<ul>
<li>commutative: <span class="math inline">\(\vec{u} \cdot \vec{v} = \vec{v} \cdot \vec{u}\)</span></li>
<li>scalar multiplication: <span class="math inline">\((c\vec{u})\cdot\vec{v} = c(\vec{u}\cdot\vec{v})\)</span>.</li>
<li>distributive <span class="math inline">\(\vec{u} \cdot (\vec{v} + \vec{w}) = \vec{u} \cdot \vec{v} + \vec{u} \cdot \vec{w}\)</span></li>
</ul>
<p>The last two can be combined: <span class="math inline">\(\vec{u}\cdot(s \vec{v} + t \vec{w}) = s(\vec{u}\cdot\vec{v}) + t (\vec{u}\cdot\vec{w})\)</span>.</p>
<p>But the associative property does not make sense, as <span class="math inline">\((\vec{u} \cdot \vec{v}) \cdot \vec{w}\)</span> does not make sense as two dot products: the result of the first is not a vector, but a scalar.</p>
</section>
</section>
<section id="matrices" class="level2" data-number="53.6">
<h2 data-number="53.6" class="anchored" data-anchor-id="matrices"><span class="header-section-number">53.6</span> Matrices</h2>
<p>Algebraically, the dot product of two vectors - pair off by components, multiply these, then add - is a common operation. Take for example, the general equation of a line, or a plane:</p>
<p><span class="math display">\[
ax + by = c, \quad ax + by + cz = d.
\]</span></p>
<p>The left hand sides are in the form of a dot product, in this case <span class="math inline">\(\langle a,b \rangle \cdot \langle x, y\rangle\)</span> and <span class="math inline">\(\langle a,b,c \rangle \cdot \langle x, y, z\rangle\)</span> respectively. When there is a system of equations, something like:</p>
<p><span class="math display">\[
\begin{array}{}
3x &amp;+&amp; 4y &amp;- &amp;5z &amp;= 10\\
3x &amp;-&amp; 5y &amp;+ &amp;7z &amp;= 11\\
-3x &amp;+&amp; 6y &amp;+ &amp;9z &amp;= 12,
\end{array}
\]</span></p>
<p>Then we might think of <span class="math inline">\(3\)</span> vectors <span class="math inline">\(\langle 3,4,-5\rangle\)</span>, <span class="math inline">\(\langle 3,-5,7\rangle\)</span>, and <span class="math inline">\(\langle -3,6,9\rangle\)</span> being dotted with <span class="math inline">\(\langle x,y,z\rangle\)</span>. Mathematically, matrices and their associated algebra are used to represent this. In this example, the system of equations above would be represented by a matrix and two vectors:</p>
<p><span class="math display">\[
M = \left[
\begin{array}{}
3 &amp; 4 &amp; -5\\
5 &amp;-5 &amp; 7\\
-3&amp; 6 &amp; 9
\end{array}
\right],\quad
\vec{x} = \langle x, y , z\rangle,\quad
\vec{b} = \langle 10, 11, 12\rangle,
\]</span></p>
<p>and the expression <span class="math inline">\(M\vec{x} = \vec{b}\)</span>. The matrix <span class="math inline">\(M\)</span> is a rectangular collection of numbers or expressions arranged in rows and columns with certain algebraic definitions. There are <span class="math inline">\(m\)</span> rows and <span class="math inline">\(n\)</span> columns in an <span class="math inline">\(m\times n\)</span> matrix. In this example <span class="math inline">\(m=n=3\)</span>, and in such a case the matrix is called square. A vector, like <span class="math inline">\(\vec{x}\)</span> is usually identified with the <span class="math inline">\(n \times 1\)</span> matrix (a column vector). Were that done, the system of equations would be written <span class="math inline">\(Mx=b\)</span>.</p>
<p>If we refer to a matrix <span class="math inline">\(M\)</span> by its components, a convention is to use <span class="math inline">\((M)_{ij}\)</span> or <span class="math inline">\(m_{ij}\)</span> to denote the entry in the <span class="math inline">\(i\)</span>th <em>row</em> and <span class="math inline">\(j\)</span>th <em>column</em>. Following <code>Julia</code>s syntax, we would use <span class="math inline">\(m_{i:}\)</span> to refer to <em>all</em> entries in the <span class="math inline">\(i\)</span>th row, and <span class="math inline">\(m_{:j}\)</span> to denote <em>all</em> entries in the <span class="math inline">\(j\)</span> column.</p>
<p>In addition to square matrices, there are some other common types of matrices worth naming: square matrices with <span class="math inline">\(0\)</span> entries below the diagonal are called upper triangular; square matrices with <span class="math inline">\(0\)</span> entries above the diagonal are called lower triangular matrices; square matrices which are <span class="math inline">\(0\)</span> except possibly along the diagonal are diagonal matrices; and a diagonal matrix whose diagonal entries are all <span class="math inline">\(1\)</span> is called an <em>identity matrix</em>.</p>
<p>Matrices, like vectors, have scalar multiplication defined for them. then scalar multiplication of a matrix <span class="math inline">\(M\)</span> by <span class="math inline">\(c\)</span> just multiplies each entry by <span class="math inline">\(c\)</span>, so the new matrix would have components defined by <span class="math inline">\(cm_{ij}\)</span>.</p>
<p>Matrices of the same size, like vectors, have addition defined for them. As with scalar multiplication, addition is defined component wise. So <span class="math inline">\(A+B\)</span> is the matrix with <span class="math inline">\(ij\)</span> entry <span class="math inline">\(A_{ij} + B_{ij}\)</span>.</p>
<section id="matrix-multiplication" class="level3" data-number="53.6.1">
<h3 data-number="53.6.1" class="anchored" data-anchor-id="matrix-multiplication"><span class="header-section-number">53.6.1</span> Matrix multiplication</h3>
<p>Matrix multiplication may be viewed as a collection of dot product operations. First, matrix multiplication is only defined between <span class="math inline">\(A\)</span> and <span class="math inline">\(B\)</span>, as <span class="math inline">\(AB\)</span>, if the size of <span class="math inline">\(A\)</span> is <span class="math inline">\(m\times n\)</span> and the size of <span class="math inline">\(B\)</span> is <span class="math inline">\(n \times k\)</span>. That is the number of columns of <span class="math inline">\(A\)</span> must match the number of rows of <span class="math inline">\(B\)</span> for the left multiplication of <span class="math inline">\(AB\)</span> to be defined. If this is so, then we have the <span class="math inline">\(ij\)</span> entry of <span class="math inline">\(AB\)</span> is:</p>
<p><span class="math display">\[
(AB)_{ij} = A_{i:} \cdot B_{:j}.
\]</span></p>
<p>That is, if we view the <span class="math inline">\(i\)</span>th row of <span class="math inline">\(A\)</span> and the <span class="math inline">\(j\)</span>th column of B as <em>vectors</em>, then the <span class="math inline">\(ij\)</span> entry is the dot product.</p>
<p>This is why <span class="math inline">\(M\)</span> in the example above, has the coefficients for each equation in a row and not a column, and why <span class="math inline">\(\vec{x}\)</span> is thought of as a <span class="math inline">\(n\times 1\)</span> matrix (a column vector) and not as a row vector.</p>
<p>Matrix multiplication between <span class="math inline">\(A\)</span> and <span class="math inline">\(B\)</span> is not, in general, commutative. Not only may the sizes not permit <span class="math inline">\(BA\)</span> to be found when <span class="math inline">\(AB\)</span> may be, there is just no guarantee when the sizes match that the components will be the same.</p>
<hr>
<p>Matrices have other operations defined on them. We mention three here:</p>
<ul>
<li>The <em>transpose</em> of a matrix flips the difference between row and column, so the <span class="math inline">\(ij\)</span> entry of the transpose is the <span class="math inline">\(ji\)</span> entry of the matrix. This means the transpose will have size <span class="math inline">\(n \times m\)</span> when <span class="math inline">\(M\)</span> has size <span class="math inline">\(m \times n\)</span>. Mathematically, the transpose is denoted <span class="math inline">\(M^t\)</span>.</li>
<li>The <em>determinant</em> of a <em>square</em> matrix is a number that can be used to characterize the matrix. The determinant may be computed different ways, but its <a href="https://en.wikipedia.org/wiki/Leibniz_formula_for_determinants">definition</a> by the Leibniz formula is common. Two special cases are all we need. The <span class="math inline">\(2\times 2\)</span> case and the <span class="math inline">\(3 \times 3\)</span> case:</li>
</ul>
<p><span class="math display">\[
\left|
\begin{array}{}
a&amp;b\\
c&amp;d
\end{array}
\right| =
ad - bc, \quad
\left|
\begin{array}{}
a&amp;b&amp;c\\
d&amp;e&amp;f\\
g&amp;h&amp;i
\end{array}
\right| =
a \left|
\begin{array}{}
e&amp;f\\
h&amp;i
\end{array}
\right|
- b \left|
\begin{array}{}
d&amp;f\\
g&amp;i
\end{array}
\right|
+c \left|
\begin{array}{}
d&amp;e\\
g&amp;h
\end{array}
\right|.
\]</span></p>
<p>The <span class="math inline">\(3\times 3\)</span> case shows how determinants may be <a href="https://en.wikipedia.org/wiki/Determinant#Definition">computed recursively</a>, using “cofactor” expansion.</p>
<ul>
<li>The <em>inverse</em> of a square matrix. If <span class="math inline">\(M\)</span> is a square matrix and its determinant is non-zero, then there is an <em>inverse</em> matrix, denoted <span class="math inline">\(M^{-1}\)</span>, with the properties that <span class="math inline">\(MM^{-1} = M^{-1}M = I\)</span>, where <span class="math inline">\(I\)</span> is the diagonal matrix of all <span class="math inline">\(1\)</span>s called the identify matrix.</li>
</ul>
</section>
<section id="matrices-in-julia" class="level3" data-number="53.6.2">
<h3 data-number="53.6.2" class="anchored" data-anchor-id="matrices-in-julia"><span class="header-section-number">53.6.2</span> Matrices in Julia</h3>
<p>As mentioned previously, a matrix in <code>Julia</code> is defined component by component with <code>[]</code>. We separate row entries with spaces and columns with semicolons:</p>
<div class="cell" data-execution_count="27">
<div class="sourceCode cell-code" id="cb41"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb41-1"><a href="#cb41-1" aria-hidden="true" tabindex="-1"></a> <span class="op">=</span> [<span class="fl">3</span> <span class="fl">4</span> <span class="op">-</span><span class="fl">5</span>; <span class="fl">5</span> <span class="op">-</span><span class="fl">5</span> <span class="fl">7</span>; <span class="op">-</span><span class="fl">3</span> <span class="fl">6</span> <span class="fl">9</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="28">
<pre><code>3×3 Matrix{Int64}:
3 4 -5
5 -5 7
-3 6 9</code></pre>
</div>
</div>
<p>Space is the separator, which means computing a component during definition (i.e., writing <code>2 + 3</code> in place of <code>5</code>) can be problematic, as no space can be used in the computation, lest it be parsed as a separator.</p>
<p>Vectors are defined similarly. As they are identified with <em>column</em> vectors, we use a semicolon (or a comma with simple numbers) to separate:</p>
<div class="cell" data-execution_count="28">
<div class="sourceCode cell-code" id="cb43"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb43-1"><a href="#cb43-1" aria-hidden="true" tabindex="-1"></a>𝒷 <span class="op">=</span> [<span class="fl">10</span>, <span class="fl">11</span>, <span class="fl">12</span>] <span class="co"># not 𝒷 = [10 11 12], which would be a row vector.</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="29">
<pre><code>3-element Vector{Int64}:
10
11
12</code></pre>
</div>
</div>
<p>In <code>Julia</code>, entries in a matrix (or a vector) are stored in a container with a type wide enough accomodate each entry. In this example, the type is SymPys <code>Sym</code> type:</p>
<div class="cell" data-execution_count="29">
<div class="sourceCode cell-code" id="cb45"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb45-1"><a href="#cb45-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> x1 x2 x3</span>
<span id="cb45-2"><a href="#cb45-2" aria-hidden="true" tabindex="-1"></a>𝓍 <span class="op">=</span> [x1, x2, x3]</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>3-element Vector{Sym}:
x₁
x₂
x₃</code></pre>
</div>
</div>
<p>Matrices may also be defined from blocks. This example shows how to make two column vectors into a matrix:</p>
<div class="cell" data-execution_count="30">
<div class="sourceCode cell-code" id="cb47"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb47-1"><a href="#cb47-1" aria-hidden="true" tabindex="-1"></a>𝓊 <span class="op">=</span> [<span class="fl">10</span>, <span class="fl">11</span>, <span class="fl">12</span>]</span>
<span id="cb47-2"><a href="#cb47-2" aria-hidden="true" tabindex="-1"></a>𝓋 <span class="op">=</span> [<span class="fl">13</span>, <span class="fl">14</span>, <span class="fl">15</span>]</span>
<span id="cb47-3"><a href="#cb47-3" aria-hidden="true" tabindex="-1"></a>[𝓊 𝓋] <span class="co"># horizontally combine</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>3×2 Matrix{Int64}:
10 13
11 14
12 15</code></pre>
</div>
</div>
<p>Vertically combining the two will stack them:</p>
<div class="cell" data-execution_count="31">
<div class="sourceCode cell-code" id="cb49"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb49-1"><a href="#cb49-1" aria-hidden="true" tabindex="-1"></a>[𝓊; 𝓋]</span></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>6-element Vector{Int64}:
10
11
12
13
14
15</code></pre>
</div>
</div>
<p>Scalar multiplication will just work as expected:</p>
<div class="cell" data-execution_count="32">
<div class="sourceCode cell-code" id="cb51"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb51-1"><a href="#cb51-1" aria-hidden="true" tabindex="-1"></a><span class="fl">2</span> <span class="op">*</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>3×3 Matrix{Int64}:
6 8 -10
10 -10 14
-6 12 18</code></pre>
</div>
</div>
<p>Matrix addition is also straightforward:</p>
<div class="cell" data-execution_count="33">
<div class="sourceCode cell-code" id="cb53"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb53-1"><a href="#cb53-1" aria-hidden="true" tabindex="-1"></a> <span class="op">+</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>3×3 Matrix{Int64}:
6 8 -10
10 -10 14
-6 12 18</code></pre>
</div>
</div>
<p>Matrix addition expects matrices of the same size. An error will otherwise be thrown. However, if addition is <em>broadcasted</em> then the sizes need only be commensurate. For example, this will add <code>1</code> to each entry of <code>M</code>:</p>
<div class="cell" data-execution_count="34">
<div class="sourceCode cell-code" id="cb55"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb55-1"><a href="#cb55-1" aria-hidden="true" tabindex="-1"></a> <span class="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="35">
<pre><code>3×3 Matrix{Int64}:
4 5 -4
6 -4 8
-2 7 10</code></pre>
</div>
</div>
<p>Matrix multiplication is defined by <code>*</code>:</p>
<div class="cell" data-execution_count="35">
<div class="sourceCode cell-code" id="cb57"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb57-1"><a href="#cb57-1" aria-hidden="true" tabindex="-1"></a> <span class="op">*</span> </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="36">
<pre><code>3×3 Matrix{Int64}:
44 -38 -32
-31 87 3
-6 12 138</code></pre>
</div>
</div>
<p>We can then see how the system of equations is represented with matrices:</p>
<div class="cell" data-execution_count="36">
<div class="sourceCode cell-code" id="cb59"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb59-1"><a href="#cb59-1" aria-hidden="true" tabindex="-1"></a> <span class="op">*</span> 𝓍 <span class="op">-</span> 𝒷</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="37">
<pre><code>3-element Vector{Sym}:
3⋅x₁ + 4⋅x₂ - 5⋅x₃ - 10
5⋅x₁ - 5⋅x₂ + 7⋅x₃ - 11
-3⋅x₁ + 6⋅x₂ + 9⋅x₃ - 12</code></pre>
</div>
</div>
<p>Here we use <code>SymPy</code> to verify the above:</p>
<div class="cell" data-execution_count="37">
<div class="sourceCode cell-code" id="cb61"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb61-1"><a href="#cb61-1" aria-hidden="true" tabindex="-1"></a>𝒜 <span class="op">=</span> [<span class="fu">symbols</span>(<span class="st">"A</span><span class="sc">$</span>i<span class="sc">$</span>j<span class="st">"</span>, real<span class="op">=</span><span class="cn">true</span>) for i <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">3</span>, j <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">2</span>]</span>
<span id="cb61-2"><a href="#cb61-2" aria-hidden="true" tabindex="-1"></a> <span class="op">=</span> [<span class="fu">symbols</span>(<span class="st">"B</span><span class="sc">$</span>i<span class="sc">$</span>j<span class="st">"</span>, real<span class="op">=</span><span class="cn">true</span>) for i <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">2</span>, j <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">2</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="38">
<pre><code>2×2 Matrix{Sym}:
B₁₁ B₁₂
B₂₁ B₂₂</code></pre>
</div>
</div>
<p>The matrix product has the expected size: the number of rows of <code>A</code> (<span class="math inline">\(3\)</span>) by the number of columns of <code>B</code> (<span class="math inline">\(2\)</span>):</p>
<div class="cell" data-execution_count="38">
<div class="sourceCode cell-code" id="cb63"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb63-1"><a href="#cb63-1" aria-hidden="true" tabindex="-1"></a>𝒜 <span class="op">*</span> </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="39">
<pre><code>3×2 Matrix{Sym}:
A₁₁⋅B₁₁ + A₁₂⋅B₂₁ A₁₁⋅B₁₂ + A₁₂⋅B₂₂
A₂₁⋅B₁₁ + A₂₂⋅B₂₁ A₂₁⋅B₁₂ + A₂₂⋅B₂₂
A₃₁⋅B₁₁ + A₃₂⋅B₂₁ A₃₁⋅B₁₂ + A₃₂⋅B₂₂</code></pre>
</div>
</div>
<p>This confirms how each entry (<code>(A*B)[i,j]</code>) is from a dot product (<code>A[i,:] ⋅ B[:,j]</code>):</p>
<div class="cell" data-execution_count="39">
<div class="sourceCode cell-code" id="cb65"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb65-1"><a href="#cb65-1" aria-hidden="true" tabindex="-1"></a>[ (𝒜 <span class="op">*</span> )[i,j] <span class="op">==</span> 𝒜[i,<span class="op">:</span>] <span class="op"></span> [<span class="op">:</span>,j] for i <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">3</span>, j <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">2</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="40">
<pre><code>3×2 Matrix{Bool}:
1 1
1 1
1 1</code></pre>
</div>
</div>
<p>When the multiplication is broadcasted though, with <code>.*</code>, the operation will be component wise:</p>
<div class="cell" data-execution_count="40">
<div class="sourceCode cell-code" id="cb67"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb67-1"><a href="#cb67-1" aria-hidden="true" tabindex="-1"></a> <span class="op">.*</span> <span class="co"># component wise (Hadamard product)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="41">
<pre><code>3×3 Matrix{Int64}:
9 16 25
25 25 49
9 36 81</code></pre>
</div>
</div>
<hr>
<p>The determinant is found by <code>det</code> provided by the <code>LinearAlgebra</code> package:</p>
<div class="cell" data-execution_count="41">
<div class="sourceCode cell-code" id="cb69"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb69-1"><a href="#cb69-1" aria-hidden="true" tabindex="-1"></a><span class="fu">det</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>-600.0000000000001</code></pre>
</div>
</div>
<hr>
<p>The transpose of a matrix is found through <code>transpose</code> which doesnt create a new object, but rather an object which knows to switch indices when referenced:</p>
<div class="cell" data-execution_count="42">
<div class="sourceCode cell-code" id="cb71"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb71-1"><a href="#cb71-1" aria-hidden="true" tabindex="-1"></a><span class="fu">transpose</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>3×3 transpose(::Matrix{Int64}) with eltype Int64:
3 5 -3
4 -5 6
-5 7 9</code></pre>
</div>
</div>
<p>For matrices with <em>real</em> numbers, the transpose can be performed with the postfix operation <code>'</code>:</p>
<div class="cell" data-execution_count="43">
<div class="sourceCode cell-code" id="cb73"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb73-1"><a href="#cb73-1" aria-hidden="true" tabindex="-1"></a><span class="ch">'</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>3×3 adjoint(::Matrix{Int64}) with eltype Int64:
3 5 -3
4 -5 6
-5 7 9</code></pre>
</div>
</div>
<p>(However, this is not true for matrices with complex numbers as <code>'</code> is the “adjoint,” that is, the transpose of the matrix <em>after</em> taking complex conjugates.)</p>
<p>With <code>u</code> and <code>v</code>, vectors from above, we have:</p>
<div class="cell" data-execution_count="44">
<div class="sourceCode cell-code" id="cb75"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb75-1"><a href="#cb75-1" aria-hidden="true" tabindex="-1"></a>[𝓊<span class="ch">' 𝓋'</span>] <span class="co"># [𝓊 𝓋] was a 3 × 2 matrix, above</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="45">
<pre><code>1×6 adjoint(::Vector{Int64}) with eltype Int64:
10 11 12 13 14 15</code></pre>
</div>
</div>
<p>and</p>
<div class="cell" data-execution_count="45">
<div class="sourceCode cell-code" id="cb77"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb77-1"><a href="#cb77-1" aria-hidden="true" tabindex="-1"></a>[𝓊<span class="ch">'; 𝓋'</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="46">
<pre><code>2×3 Matrix{Int64}:
10 11 12
13 14 15</code></pre>
</div>
</div>
<div class="cell" data-execution_count="46">
<div class="cell-output cell-output-display" data-execution_count="47">
<div class="markdown"><div class="admonition info"><p class="admonition-title">Info</p><p>The adjoint is defined <em>recursively</em> in <code>Julia</code>. In the <code>CalculusWithJulia</code> package, we overload the <code>'</code> notation for <em>functions</em> to yield a univariate derivative found with automatic differentiation. This can lead to problems: if we have a matrix of functions, <code>M</code>, and took the transpose with <code>M'</code>, then the entries of <code>M'</code> would be the derivatives of the functions in <code>M</code> - not the original functions. This is very much likely to not be what is desired. The <code>CalculusWithJulia</code> package commits <strong>type piracy</strong> here <em>and</em> abuses the generic idea for <code>'</code> in Julia. In general type piracy is very much frowned upon, as it can change expected behaviour. It is defined in <code>CalculusWithJulia</code>, as that package is intended only to act as a means to ease users into the wider package ecosystem of <code>Julia</code>.</p>
</div>
</div>
</div>
</div>
<hr>
<p>The dot product and matrix multiplication are related, and mathematically identified through the relation: <span class="math inline">\(\vec{u} \cdot \vec{v} = u^t v\)</span>, where the right hand side identifies <span class="math inline">\(\vec{u}\)</span> and <span class="math inline">\(\vec{v}\)</span> with a <span class="math inline">\(n\times 1\)</span> column matrix, and <span class="math inline">\(u^t\)</span> is the transpose, or a <span class="math inline">\(1\times n\)</span> row matrix. However, mathematically the left side is a scalar, but the right side a <span class="math inline">\(1\times 1\)</span> matrix. While distinct, the two are identified as the same. This is similar to the useful identification of a point and a vector. Within <code>Julia</code>, these identifications are context dependent. <code>Julia</code> stores vectors as <span class="math inline">\(1\)</span>-dimensional arrays, transposes as <span class="math inline">\(1\)</span>-dimensional objects, and matrices as <span class="math inline">\(2\)</span>-dimensional arrays. The product of a transpose and a vector is a scalar:</p>
<div class="cell" data-hold="true" data-execution_count="47">
<div class="sourceCode cell-code" id="cb79"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb79-1"><a href="#cb79-1" aria-hidden="true" tabindex="-1"></a>u, 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>
<span id="cb79-2"><a href="#cb79-2" aria-hidden="true" tabindex="-1"></a>u<span class="op">'</span> <span class="op">*</span> v <span class="co"># a scalar</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="48">
<pre><code>24</code></pre>
</div>
</div>
<p>But if we make <code>u</code> a matrix (here by “<code>reshape</code>ing” in a matrix with <span class="math inline">\(1\)</span> row and <span class="math inline">\(3\)</span> columns), we will get a matrix (actually a vector) in return:</p>
<div class="cell" data-hold="true" data-execution_count="48">
<div class="sourceCode cell-code" id="cb81"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb81-1"><a href="#cb81-1" aria-hidden="true" tabindex="-1"></a>u, 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>
<span id="cb81-2"><a href="#cb81-2" aria-hidden="true" tabindex="-1"></a><span class="fu">reshape</span>(u,(<span class="fl">1</span>,<span class="fl">3</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="49">
<pre><code>1-element Vector{Int64}:
24</code></pre>
</div>
</div>
</section>
</section>
<section id="cross-product" class="level2" data-number="53.7">
<h2 data-number="53.7" class="anchored" data-anchor-id="cross-product"><span class="header-section-number">53.7</span> Cross product</h2>
<p>In three dimensions, there is a another operation between vectors that is similar to multiplication, though we will see with many differences.</p>
<p>Let <span class="math inline">\(\vec{u}\)</span> and <span class="math inline">\(\vec{v}\)</span> be two <span class="math inline">\(3\)</span>-dimensional vectors, then the <em>cross</em> product, <span class="math inline">\(\vec{u} \times \vec{v}\)</span>, is defined as a vector with length:</p>
<p><span class="math display">\[
\| \vec{u} \times \vec{v} \| = \| \vec{u} \| \| \vec{v} \| \sin(\theta),
\]</span></p>
<p>with <span class="math inline">\(\theta\)</span> being the angle in <span class="math inline">\([0, \pi]\)</span> between <span class="math inline">\(\vec{u}\)</span> and <span class="math inline">\(\vec{v}\)</span>. Consequently, <span class="math inline">\(\sin(\theta) \geq 0\)</span>.</p>
<p>The direction of the cross product is such that it is <em>orthogonal</em> to <em>both</em> <span class="math inline">\(\vec{u}\)</span> and <span class="math inline">\(\vec{v}\)</span>. There are two such directions, to identify which is correct, the <a href="https://en.wikipedia.org/wiki/Cross_product#Definition">right-hand rule</a> is used. This rule points the right hand fingers in the direction of <span class="math inline">\(\vec{u}\)</span> and curls them towards <span class="math inline">\(\vec{v}\)</span> (so that the angle between the two vectors is in <span class="math inline">\([0, \pi]\)</span>). The thumb will point in the direction. Call this direction <span class="math inline">\(\hat{n}\)</span>, a normal unit vector. Then the cross product can be defined by:</p>
<p><span class="math display">\[
\vec{u} \times \vec{v} = \| \vec{u} \| \| \vec{v} \| \sin(\theta) \hat{n}.
\]</span></p>
<div class="cell" data-execution_count="49">
<div class="cell-output cell-output-display" data-execution_count="50">
<div class="markdown"><div class="admonition info"><p class="admonition-title">Info</p><p>The right-hand rule is also useful to understand how standard household screws will behave when twisted with a screwdriver. If the right hand fingers curl in the direction of the twisting screwdriver, then the screw will go in or out following the direction pointed to by the thumb.</p>
</div>
</div>
</div>
</div>
<p>The right-hand rule depends on the order of consideration of the vectors. If they are reversed, the opposite direction is determined. A consequence is that the cross product is <strong>anti</strong>-commutative, unlike multiplication:</p>
<p><span class="math display">\[
\vec{u} \times \vec{v} = - \vec{v} \times \vec{u}.
\]</span></p>
<p>Mathematically, the definition in terms of its components is a bit involved:</p>
<p><span class="math display">\[
\vec{u} \times \vec{v} = \langle u_2 v_3 - u_3 v_2, u_3 v_1 - u_1 v_3, u_1 v_2 - u_2 v_1 \rangle.
\]</span></p>
<p>There is a matrix notation that can simplify this computation. If we <em>formally</em> define <span class="math inline">\(\hat{i}\)</span>, <span class="math inline">\(\hat{j}\)</span>, and <span class="math inline">\(\hat{k}\)</span> to represent unit vectors in the <span class="math inline">\(x\)</span>, <span class="math inline">\(y\)</span>, and <span class="math inline">\(z\)</span> direction, then a vector <span class="math inline">\(\langle u_1, u_2, u_3 \rangle\)</span> could be written <span class="math inline">\(u_1\hat{i} + u_2\hat{j} + u_3\hat{k}\)</span>. With this the cross product of <span class="math inline">\(\vec{u}\)</span> and <span class="math inline">\(\vec{v}\)</span> is the vector associated with the <em>determinant</em> of the matrix</p>
<p><span class="math display">\[
\left[
\begin{array}{}
\hat{i} &amp; \hat{j} &amp; \hat{k}\\
u_1 &amp; u_2 &amp; u_3\\
v_1 &amp; v_2 &amp; v_3
\end{array}
\right]
\]</span></p>
<p>From the <span class="math inline">\(\sin(\theta)\)</span> term in the definition, we see that <span class="math inline">\(\vec{u}\times\vec{u}=0\)</span>. In fact, the cross product is <span class="math inline">\(0\)</span> only if the two vectors involved are parallel or there is a zero vector.</p>
<p>In <code>Julia</code>, the <code>cross</code> function from the <code>LinearAlgebra</code> package implements the cross product. For example:</p>
<div class="cell" data-execution_count="50">
<div class="sourceCode cell-code" id="cb83"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb83-1"><a href="#cb83-1" aria-hidden="true" tabindex="-1"></a>𝓪 <span class="op">=</span> [<span class="fl">1</span>, <span class="fl">2</span>, <span class="fl">3</span>]</span>
<span id="cb83-2"><a href="#cb83-2" aria-hidden="true" tabindex="-1"></a>𝓫 <span class="op">=</span> [<span class="fl">4</span>, <span class="fl">2</span>, <span class="fl">1</span>]</span>
<span id="cb83-3"><a href="#cb83-3" aria-hidden="true" tabindex="-1"></a><span class="fu">cross</span>(𝓪, 𝓫)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="51">
<pre><code>3-element Vector{Int64}:
-4
11
-6</code></pre>
</div>
</div>
<p>There is also the <em>infix</em> unicode operator <code>\times[tab]</code> that can be used for similarity to traditional mathematical syntax.</p>
<div class="cell" data-execution_count="51">
<div class="sourceCode cell-code" id="cb85"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb85-1"><a href="#cb85-1" aria-hidden="true" tabindex="-1"></a>𝓪 <span class="op">×</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="52">
<pre><code>3-element Vector{Int64}:
-4
11
-6</code></pre>
</div>
</div>
<p>We can see the cross product is anti-commutative by comparing the last answer with:</p>
<div class="cell" data-execution_count="52">
<div class="sourceCode cell-code" id="cb87"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb87-1"><a href="#cb87-1" aria-hidden="true" tabindex="-1"></a>𝓫 <span class="op">×</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="53">
<pre><code>3-element Vector{Int64}:
4
-11
6</code></pre>
</div>
</div>
<p>Using vectors of size different than <span class="math inline">\(n=3\)</span> produces a dimension mismatch error:</p>
<div class="cell" data-execution_count="53">
<div class="sourceCode cell-code" id="cb89"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb89-1"><a href="#cb89-1" aria-hidden="true" tabindex="-1"></a>[<span class="fl">1</span>, <span class="fl">2</span>] <span class="op">×</span> [<span class="fl">3</span>, <span class="fl">4</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-error">
<pre><code>LoadError: DimensionMismatch("cross product is only defined for vectors of length 3")</code></pre>
</div>
</div>
<p>(It can prove useful to pad <span class="math inline">\(2\)</span>-dimensional vectors into <span class="math inline">\(3\)</span>-dimensional vectors by adding a <span class="math inline">\(0\)</span> third component. We will see this in the discussion on curvature in the plane.)</p>
<p>Lets see that the matrix definition will be identical (after identifications) to <code>cross</code>:</p>
<div class="cell" data-execution_count="54">
<div class="sourceCode cell-code" id="cb91"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb91-1"><a href="#cb91-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> î ĵ k̂</span>
<span id="cb91-2"><a href="#cb91-2" aria-hidden="true" tabindex="-1"></a>𝓜 <span class="op">=</span> [î ĵ k̂; <span class="fl">3</span> <span class="fl">4</span> <span class="fl">5</span>; <span class="fl">3</span> <span class="fl">6</span> <span class="fl">7</span>]</span>
<span id="cb91-3"><a href="#cb91-3" aria-hidden="true" tabindex="-1"></a><span class="fu">det</span>(𝓜) <span class="op">|&gt;</span> simplify</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="55">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
6 k̂ - 2 î - 6 ĵ
\]
</span>
</div>
</div>
<p>Compare with</p>
<div class="cell" data-execution_count="55">
<div class="sourceCode cell-code" id="cb92"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb92-1"><a href="#cb92-1" aria-hidden="true" tabindex="-1"></a>𝓜[<span class="fl">2</span>,<span class="op">:</span>] <span class="op">×</span> 𝓜[<span class="fl">3</span>,<span class="op">:</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="56">
<pre><code>3-element Vector{Sym}:
-2
-6
6</code></pre>
</div>
</div>
<hr>
<p>Consider this extended picture involving two vectors <span class="math inline">\(\vec{u}\)</span> and <span class="math inline">\(\vec{v}\)</span> drawn in two dimensions:</p>
<div class="cell" data-execution_count="56">
<div class="sourceCode cell-code" id="cb94"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb94-1"><a href="#cb94-1" aria-hidden="true" tabindex="-1"></a>u₁ <span class="op">=</span> [<span class="fl">1</span>, <span class="fl">2</span>]</span>
<span id="cb94-2"><a href="#cb94-2" aria-hidden="true" tabindex="-1"></a>v₁ <span class="op">=</span> [<span class="fl">2</span>, <span class="fl">1</span>]</span>
<span id="cb94-3"><a href="#cb94-3" aria-hidden="true" tabindex="-1"></a>p₁ <span class="op">=</span> [<span class="fl">0</span>,<span class="fl">0</span>]</span>
<span id="cb94-4"><a href="#cb94-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb94-5"><a href="#cb94-5" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(aspect_ratio<span class="op">=:</span>equal)</span>
<span id="cb94-6"><a href="#cb94-6" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(p₁, u₁)</span>
<span id="cb94-7"><a href="#cb94-7" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(p₁, v₁)</span>
<span id="cb94-8"><a href="#cb94-8" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(u₁, v₁)</span>
<span id="cb94-9"><a href="#cb94-9" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(v₁, u₁)</span>
<span id="cb94-10"><a href="#cb94-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb94-11"><a href="#cb94-11" aria-hidden="true" tabindex="-1"></a>puv₁ <span class="op">=</span> (u₁ <span class="op"></span> v₁) <span class="op">/</span> (v₁ <span class="op"></span> v₁) <span class="op">*</span> v₁</span>
<span id="cb94-12"><a href="#cb94-12" aria-hidden="true" tabindex="-1"></a>porth₁ <span class="op">=</span> u₁ <span class="op">-</span> puv₁</span>
<span id="cb94-13"><a href="#cb94-13" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(puv₁, porth₁)</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="57">
<p><img src="vectors_files/figure-html/cell-57-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The enclosed shape is a parallelogram. To this we added the projection of <span class="math inline">\(\vec{u}\)</span> onto <span class="math inline">\(\vec{v}\)</span> (<code>puv</code>) and then the <em>orthogonal</em> part (<code>porth</code>).</p>
<p>The <em>area</em> of a parallelogram is the length of one side times the perpendicular height. The perpendicular height could be found from <code>norm(porth)</code>, so the area is:</p>
<div class="cell" data-execution_count="57">
<div class="sourceCode cell-code" id="cb95"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb95-1"><a href="#cb95-1" aria-hidden="true" tabindex="-1"></a><span class="fu">norm</span>(v₁) <span class="op">*</span> <span class="fu">norm</span>(porth₁)</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="58">
<pre><code>3.0</code></pre>
</div>
</div>
<p>However, from trigonometry we have the height would also be the norm of <span class="math inline">\(\vec{u}\)</span> times <span class="math inline">\(\sin(\theta)\)</span>, a value that is given through the length of the cross product of <span class="math inline">\(\vec{u}\)</span> and <span class="math inline">\(\hat{v}\)</span>, the unit vector, were these vectors viewed as <span class="math inline">\(3\)</span> dimensional by adding a <span class="math inline">\(0\)</span> third component. In formulas, this is also the case:</p>
<p><span class="math display">\[
\text{area of the parallelogram} = \| \vec{u} \times \hat{v} \| \| \vec{v} \| = \| \vec{u} \times \vec{v} \|.
\]</span></p>
<p>We have, for our figure, after extending <code>u</code> and <code>v</code> to be three dimensional the area of the parallelogram:</p>
<div class="cell" data-execution_count="58">
<div class="sourceCode cell-code" id="cb97"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb97-1"><a href="#cb97-1" aria-hidden="true" tabindex="-1"></a>u₂ <span class="op">=</span> [<span class="fl">1</span>, <span class="fl">2</span>, <span class="fl">0</span>]</span>
<span id="cb97-2"><a href="#cb97-2" aria-hidden="true" tabindex="-1"></a>v₂ <span class="op">=</span> [<span class="fl">2</span>, <span class="fl">1</span>, <span class="fl">0</span>]</span>
<span id="cb97-3"><a href="#cb97-3" aria-hidden="true" tabindex="-1"></a><span class="fu">norm</span>(u₂ <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="59">
<pre><code>3.0</code></pre>
</div>
</div>
<hr>
<p>This analysis can be extended to the case of 3 vectors, which - when not co-planar - will form a <em>parallelepiped</em>.</p>
<div class="cell" data-execution_count="59">
<div class="sourceCode cell-code" id="cb99"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb99-1"><a href="#cb99-1" aria-hidden="true" tabindex="-1"></a>u₃, v₃, w₃ <span class="op">=</span> [<span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">3</span>], [<span class="fl">2</span>,<span class="fl">1</span>,<span class="fl">0</span>], [<span class="fl">1</span>,<span class="fl">1</span>,<span class="fl">2</span>]</span>
<span id="cb99-2"><a href="#cb99-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>()</span>
<span id="cb99-3"><a href="#cb99-3" aria-hidden="true" tabindex="-1"></a>p₃ <span class="op">=</span> [<span class="fl">0</span>,<span class="fl">0</span>,<span class="fl">0</span>]</span>
<span id="cb99-4"><a href="#cb99-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb99-5"><a href="#cb99-5" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(legend<span class="op">=</span><span class="cn">false</span>)</span>
<span id="cb99-6"><a href="#cb99-6" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(p₃, u₃); <span class="fu">arrow!</span>(p₃, v₃); <span class="fu">arrow!</span>(p₃, w₃)</span>
<span id="cb99-7"><a href="#cb99-7" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(u₃, v₃); <span class="fu">arrow!</span>(u₃, w₃)</span>
<span id="cb99-8"><a href="#cb99-8" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(v₃, u₃); <span class="fu">arrow!</span>(v₃, w₃)</span>
<span id="cb99-9"><a href="#cb99-9" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(w₃, u₃); <span class="fu">arrow!</span>(w₃, v₃)</span>
<span id="cb99-10"><a href="#cb99-10" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(u₃ <span class="op">+</span> v₃, w₃); <span class="fu">arrow!</span>(u₃ <span class="op">+</span> w₃, v₃); <span class="fu">arrow!</span>(v₃ <span class="op">+</span> w₃, u₃)</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="60">
<p><img src="vectors_files/figure-html/cell-60-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>The volume of a parallelepiped is the area of a base parallelogram times the height of a perpendicular. If <span class="math inline">\(\vec{u}\)</span> and <span class="math inline">\(\vec{v}\)</span> form the base parallelogram, then the perpendicular will have height <span class="math inline">\(\|\vec{w}\| \cos(\theta)\)</span> where the angle is the one made by <span class="math inline">\(\vec{w}\)</span> with the normal, <span class="math inline">\(\vec{n}\)</span>. Since <span class="math inline">\(\vec{u} \times \vec{v} = \| \vec{u} \times \vec{v}\| \hat{n} = \hat{n}\)</span> times the area of the base parallelogram, we have if we dot this answer with <span class="math inline">\(\vec{w}\)</span>:</p>
<p><span class="math display">\[
(\vec{u} \times \vec{v}) \cdot \vec{w} =
\|\vec{u} \times \vec{v}\| (\vec{n} \cdot \vec{w}) =
\|\vec{u} \times \vec{v}\| \| \vec{w}\| \cos(\theta),
\]</span></p>
<p>that is, the area of the parallelepiped. Wait, what about <span class="math inline">\((\vec{v}\times\vec{u})\cdot\vec{w}\)</span>? That will have an opposite sign. Yes, in the above, there is an assumption that <span class="math inline">\(\vec{n}\)</span> and <span class="math inline">\(\vec{w}\)</span> have a an angle between them within <span class="math inline">\([0, \pi/2]\)</span>, otherwise an absolute value must be used, as volume is non-negative.</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">
Orientation
</div>
</div>
<div class="callout-body-container callout-body">
<p>The triple-scalar product, <span class="math inline">\(\vec{u}\cdot(\vec{v}\times\vec{w})\)</span>, gives the volume of the parallelepiped up to sign. If the sign of this is positive, the <span class="math inline">\(3\)</span> vectors are said to have a <em>positive</em> orientation, if the triple-scalar product is negative, the vectors have a <em>negative</em> orientation.</p>
</div>
</div>
<section id="algebraic-properties-1" class="level4">
<h4 class="anchored" data-anchor-id="algebraic-properties-1">Algebraic properties</h4>
<p>The cross product has many properties, some different from regular multiplication:</p>
<ul>
<li>scalar multiplication: <span class="math inline">\((c\vec{u})\times\vec{v} = c(\vec{u}\times\vec{v})\)</span></li>
<li>distributive over addition: <span class="math inline">\(\vec{u} \times (\vec{v} + \vec{w}) = \vec{u}\times\vec{v} + \vec{u}\times\vec{w}\)</span>.</li>
<li><em>anti</em>-commutative: <span class="math inline">\(\vec{u} \times \vec{v} = - \vec{v} \times \vec{u}\)</span></li>
<li><em>not</em> associative: that is there is no guarantee that <span class="math inline">\((\vec{u}\times\vec{v})\times\vec{w}\)</span> will be equivalent to <span class="math inline">\(\vec{u}\times(\vec{v}\times\vec{w})\)</span>.</li>
<li>The triple cross product <span class="math inline">\((\vec{u}\times\vec{v}) \times \vec{w}\)</span> must be orthogonal to <span class="math inline">\(\vec{u}\times\vec{v}\)</span> so lies in a plane with this as a normal vector. But, <span class="math inline">\(\vec{u}\)</span> and <span class="math inline">\(\vec{v}\)</span> will generate this plane, so it should be possible to express this triple product in terms of a sum involving <span class="math inline">\(\vec{u}\)</span> and <span class="math inline">\(\vec{v}\)</span> and indeed:</li>
</ul>
<p><span class="math display">\[
(\vec{u}\times\vec{v})\times\vec{w} = (\vec{u}\cdot\vec{w})\vec{v} - (\vec{v}\cdot\vec{w})\vec{u}.
\]</span></p>
<hr>
<p>The following shows the algebraic properties stated above hold for symbolic vectors. First the linearity of the dot product:</p>
<div class="cell" data-execution_count="60">
<div class="sourceCode cell-code" id="cb100"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb100-1"><a href="#cb100-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> s₄ t₄ u₄[<span class="fl">1</span><span class="op">:</span><span class="fl">3</span>]<span class="op">::</span><span class="dt">real </span>v₄[<span class="fl">1</span><span class="op">:</span><span class="fl">3</span>]<span class="op">::</span><span class="dt">real </span>w₄[<span class="fl">1</span><span class="op">:</span><span class="fl">3</span>]<span class="op">::</span><span class="dt">real</span></span>
<span id="cb100-2"><a href="#cb100-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb100-3"><a href="#cb100-3" aria-hidden="true" tabindex="-1"></a>u₄ <span class="op"></span> (s₄ <span class="op">*</span> v₄ <span class="op">+</span> t₄ <span class="op">*</span> w₄) <span class="op">-</span> (s₄ <span class="op">*</span> (u₄ <span class="op"></span> v₄) <span class="op">+</span> t₄ <span class="op">*</span> (u₄ <span class="op"></span> w₄)) <span class="op">|&gt;</span> simplify</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="61">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
0
\]
</span>
</div>
</div>
<p>This shows the dot product is commutative:</p>
<div class="cell" data-execution_count="61">
<div class="sourceCode cell-code" id="cb101"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb101-1"><a href="#cb101-1" aria-hidden="true" tabindex="-1"></a>(u₄ <span class="op"></span> v₄) <span class="op">-</span> (v₄ <span class="op"></span> u₄) <span class="op">|&gt;</span> simplify</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">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
0
\]
</span>
</div>
</div>
<p>This shows the linearity of the cross product over scalar multiplication and vector addition:</p>
<div class="cell" data-execution_count="62">
<div class="sourceCode cell-code" id="cb102"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb102-1"><a href="#cb102-1" aria-hidden="true" tabindex="-1"></a>u₄ <span class="op">×</span> (s₄<span class="op">*</span> v₄ <span class="op">+</span> t₄ <span class="op">*</span> w₄) <span class="op">-</span> (s₄ <span class="op">*</span> (u₄ <span class="op">×</span> v₄) <span class="op">+</span> t₄ <span class="op">*</span> (u₄ <span class="op">×</span> w₄)) <span class="op">.|&gt;</span> simplify</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="63">
<pre><code>3-element Vector{Sym}:
0
0
0</code></pre>
</div>
</div>
<p>(We use <code>.|&gt;</code> to broadcast <code>simplify</code> over each component.)</p>
<p>The cross product is anti-commutative:</p>
<div class="cell" data-execution_count="63">
<div class="sourceCode cell-code" id="cb104"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb104-1"><a href="#cb104-1" aria-hidden="true" tabindex="-1"></a>u₄ <span class="op">×</span> v₄ <span class="op">+</span> v₄ <span class="op">×</span> u₄ <span class="op">.|&gt;</span> simplify</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="64">
<pre><code>3-element Vector{Sym}:
0
0
0</code></pre>
</div>
</div>
<p>but not associative:</p>
<div class="cell" data-execution_count="64">
<div class="sourceCode cell-code" id="cb106"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb106-1"><a href="#cb106-1" aria-hidden="true" tabindex="-1"></a>u₄ <span class="op">×</span> (v₄ <span class="op">×</span> w₄) <span class="op">-</span> (u₄ <span class="op">×</span> v₄) <span class="op">×</span> w₄ <span class="op">.|&gt;</span> simplify</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="65">
<pre><code>3-element Vector{Sym}:
u₄₁⋅v₄₂⋅w₄₂ + u₄₁⋅v₄₃⋅w₄₃ - u₄₂⋅v₄₂⋅w₄₁ - u₄₃⋅v₄₃⋅w₄₁
-u₄₁⋅v₄₁⋅w₄₂ + u₄₂⋅v₄₁⋅w₄₁ + u₄₂⋅v₄₃⋅w₄₃ - u₄₃⋅v₄₃⋅w₄₂
-u₄₁⋅v₄₁⋅w₄₃ - u₄₂⋅v₄₂⋅w₄₃ + u₄₃⋅v₄₁⋅w₄₁ + u₄₃⋅v₄₂⋅w₄₂</code></pre>
</div>
</div>
<p>Finally we verify the decomposition of the triple cross product:</p>
<div class="cell" data-execution_count="65">
<div class="sourceCode cell-code" id="cb108"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb108-1"><a href="#cb108-1" aria-hidden="true" tabindex="-1"></a>(u₄ <span class="op">×</span> v₄) <span class="op">×</span> w₄ <span class="op">-</span> ( (u₄ <span class="op"></span> w₄) <span class="op">*</span> v₄ <span class="op">-</span> (v₄ <span class="op"></span> w₄) <span class="op">*</span> u₄) <span class="op">.|&gt;</span> simplify</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="66">
<pre><code>3-element Vector{Sym}:
0
0
0</code></pre>
</div>
</div>
<hr>
<p>This table shows common usages of the symbols for various multiplication types: <code>*</code>, <span class="math inline">\(\cdot\)</span>, and <span class="math inline">\(\times\)</span>:</p>
<table class="table">
<thead>
<tr class="header">
<th style="text-align: center;">Symbol</th>
<th style="text-align: left;">inputs</th>
<th style="text-align: left;">output</th>
<th style="text-align: left;">type</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center;"><code>*</code></td>
<td style="text-align: left;">scalar, scalar</td>
<td style="text-align: left;">scalar</td>
<td style="text-align: left;">regular multiplication</td>
</tr>
<tr class="even">
<td style="text-align: center;"><code>*</code></td>
<td style="text-align: left;">scalar, vector</td>
<td style="text-align: left;">vector</td>
<td style="text-align: left;">scalar multiplication</td>
</tr>
<tr class="odd">
<td style="text-align: center;"><code>*</code></td>
<td style="text-align: left;">vector, vector</td>
<td style="text-align: left;"><em>undefined</em></td>
<td style="text-align: left;"></td>
</tr>
<tr class="even">
<td style="text-align: center;"><span class="math inline">\(\cdot\)</span></td>
<td style="text-align: left;">scalar, scalar</td>
<td style="text-align: left;">scalar</td>
<td style="text-align: left;">regular multiplication</td>
</tr>
<tr class="odd">
<td style="text-align: center;"><span class="math inline">\(\cdot\)</span></td>
<td style="text-align: left;">scalar, vector</td>
<td style="text-align: left;">vector</td>
<td style="text-align: left;">scalar multiplication</td>
</tr>
<tr class="even">
<td style="text-align: center;"><span class="math inline">\(\cdot\)</span></td>
<td style="text-align: left;">vector, vector</td>
<td style="text-align: left;">scalar</td>
<td style="text-align: left;">dot product</td>
</tr>
<tr class="odd">
<td style="text-align: center;"><span class="math inline">\(\times\)</span></td>
<td style="text-align: left;">scalar, scalar</td>
<td style="text-align: left;">scalar</td>
<td style="text-align: left;">regular multiplication</td>
</tr>
<tr class="even">
<td style="text-align: center;"><span class="math inline">\(\times\)</span></td>
<td style="text-align: left;">scalar, vector</td>
<td style="text-align: left;">undefined</td>
<td style="text-align: left;"></td>
</tr>
<tr class="odd">
<td style="text-align: center;"><span class="math inline">\(\times\)</span></td>
<td style="text-align: left;">vector, vector</td>
<td style="text-align: left;">vector</td>
<td style="text-align: left;">cross product (<span class="math inline">\(3\)</span>D)</td>
</tr>
</tbody>
</table>
<section id="example-lines-and-planes" class="level5">
<h5 class="anchored" data-anchor-id="example-lines-and-planes">Example: lines and planes</h5>
<p>A line in two dimensions satisfies the equation <span class="math inline">\(ax + by = c\)</span>. Suppose <span class="math inline">\(a\)</span> and <span class="math inline">\(b\)</span> are non-zero. This can be represented in vector form, as the collection of all points associated to the vectors: <span class="math inline">\(p + t \vec{v}\)</span> where <span class="math inline">\(p\)</span> is a point on the line, say <span class="math inline">\((0,c/b)\)</span>, and v is the vector <span class="math inline">\(\langle b, -a \rangle\)</span>. We can verify, this for values of <code>t</code> as follows:</p>
<div class="cell" data-hold="true" data-execution_count="66">
<div class="sourceCode cell-code" id="cb110"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb110-1"><a href="#cb110-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> a b c x y t</span>
<span id="cb110-2"><a href="#cb110-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb110-3"><a href="#cb110-3" aria-hidden="true" tabindex="-1"></a>eq <span class="op">=</span> c <span class="op">-</span> (a<span class="op">*</span>x <span class="op">+</span> b<span class="op">*</span>y)</span>
<span id="cb110-4"><a href="#cb110-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb110-5"><a href="#cb110-5" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> [<span class="fl">0</span>, c<span class="op">/</span>b]</span>
<span id="cb110-6"><a href="#cb110-6" aria-hidden="true" tabindex="-1"></a>v <span class="op">=</span> [<span class="op">-</span>b, a]</span>
<span id="cb110-7"><a href="#cb110-7" aria-hidden="true" tabindex="-1"></a>li <span class="op">=</span> p <span class="op">+</span> t <span class="op">*</span> v</span>
<span id="cb110-8"><a href="#cb110-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb110-9"><a href="#cb110-9" aria-hidden="true" tabindex="-1"></a><span class="fu">eq</span>(x<span class="op">=&gt;</span>li[<span class="fl">1</span>], y<span class="op">=&gt;</span>li[<span class="fl">2</span>]) <span class="op">|&gt;</span> simplify</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="67">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
0
\]
</span>
</div>
</div>
<p>Let <span class="math inline">\(\vec{n} = \langle a , b \rangle\)</span>, taken from the coefficients in the equation. We can see directly that <span class="math inline">\(\vec{n}\)</span> is orthogonal to <span class="math inline">\(\vec{v}\)</span>. The line may then be seen as the collection of all vectors that are orthogonal to <span class="math inline">\(\vec{n}\)</span> that have their tail at the point <span class="math inline">\(p\)</span>.</p>
<p>In three dimensions, the equation of a plane is <span class="math inline">\(ax + by + cz = d\)</span>. Suppose, <span class="math inline">\(a\)</span>, <span class="math inline">\(b\)</span>, and <span class="math inline">\(c\)</span> are non-zero, for simplicity. Setting <span class="math inline">\(\vec{n} = \langle a,b,c\rangle\)</span> by comparison, it can be seen that plane is identified with the set of all vectors orthogonal to <span class="math inline">\(\vec{n}\)</span> that are anchored at <span class="math inline">\(p\)</span>.</p>
<p>First, let <span class="math inline">\(p = (0, 0, d/c)\)</span> be a point on the plane. We find two vectors <span class="math inline">\(u = \langle -b, a, 0 \rangle\)</span> and <span class="math inline">\(v = \langle 0, c, -b \rangle\)</span>. Then any point on the plane may be identified with the vector <span class="math inline">\(p + s\vec{u} + t\vec{v}\)</span>. We can verify this algebraically through:</p>
<div class="cell" data-hold="true" data-execution_count="67">
<div class="sourceCode cell-code" id="cb111"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb111-1"><a href="#cb111-1" aria-hidden="true" tabindex="-1"></a><span class="pp">@syms</span> a b c d x y z s t</span>
<span id="cb111-2"><a href="#cb111-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb111-3"><a href="#cb111-3" aria-hidden="true" tabindex="-1"></a>eq <span class="op">=</span> d <span class="op">-</span> (a<span class="op">*</span>x <span class="op">+</span> b<span class="op">*</span>y <span class="op">+</span> c <span class="op">*</span> z)</span>
<span id="cb111-4"><a href="#cb111-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb111-5"><a href="#cb111-5" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> [<span class="fl">0</span>, <span class="fl">0</span>, d<span class="op">/</span>c]</span>
<span id="cb111-6"><a href="#cb111-6" aria-hidden="true" tabindex="-1"></a>u, v <span class="op">=</span> [<span class="op">-</span>b, a, <span class="fl">0</span>], [<span class="fl">0</span>, c, <span class="op">-</span>b]</span>
<span id="cb111-7"><a href="#cb111-7" aria-hidden="true" tabindex="-1"></a>pl <span class="op">=</span> p <span class="op">+</span> t <span class="op">*</span> u <span class="op">+</span> s <span class="op">*</span> v</span>
<span id="cb111-8"><a href="#cb111-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb111-9"><a href="#cb111-9" aria-hidden="true" tabindex="-1"></a><span class="fu">subs</span>(eq, x<span class="op">=&gt;</span>pl[<span class="fl">1</span>], y<span class="op">=&gt;</span>pl[<span class="fl">2</span>], z<span class="op">=&gt;</span>pl[<span class="fl">3</span>]) <span class="op">|&gt;</span> simplify</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="68">
<span class="math-left-align" style="padding-left: 4px; width:0; float:left;">
\[
0
\]
</span>
</div>
</div>
<p>The above viewpoint can be reversed:</p>
<blockquote class="blockquote">
<p>a plane is determined by two (non-parallel) vectors and a point.</p>
</blockquote>
<p>The parameterized version of the plane would be <span class="math inline">\(p + t \vec{u} + s \vec{v}\)</span>, as used above.</p>
<p>The equation of the plane can be given from <span class="math inline">\(\vec{u}\)</span> and <span class="math inline">\(\vec{v}\)</span>. Let <span class="math inline">\(\vec{n} = \vec{u} \times \vec{v}\)</span>. Then <span class="math inline">\(\vec{n} \cdot \vec{u} = \vec{n} \cdot \vec{v} = 0\)</span>, from the properties of the cross product. As such, <span class="math inline">\(\vec{n} \cdot (s \vec{u} + t \vec{v}) = 0\)</span>. That is, the cross product is orthogonal to any <em>linear</em> combination of the two vectors. This figure shows one such linear combination:</p>
<div class="cell" data-hold="true" data-execution_count="68">
<div class="sourceCode cell-code" id="cb112"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb112-1"><a href="#cb112-1" aria-hidden="true" tabindex="-1"></a>u <span class="op">=</span> [<span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">3</span>]</span>
<span id="cb112-2"><a href="#cb112-2" aria-hidden="true" tabindex="-1"></a>v <span class="op">=</span> [<span class="fl">2</span>,<span class="fl">3</span>,<span class="fl">1</span>]</span>
<span id="cb112-3"><a href="#cb112-3" aria-hidden="true" tabindex="-1"></a>n <span class="op">=</span> u <span class="op">×</span> v</span>
<span id="cb112-4"><a href="#cb112-4" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> [<span class="fl">0</span>,<span class="fl">0</span>,<span class="fl">1</span>]</span>
<span id="cb112-5"><a href="#cb112-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb112-6"><a href="#cb112-6" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(legend<span class="op">=</span><span class="cn">false</span>)</span>
<span id="cb112-7"><a href="#cb112-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb112-8"><a href="#cb112-8" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(p, u)</span>
<span id="cb112-9"><a href="#cb112-9" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(p, v)</span>
<span id="cb112-10"><a href="#cb112-10" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(p <span class="op">+</span> u, v)</span>
<span id="cb112-11"><a href="#cb112-11" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(p <span class="op">+</span> v, u)</span>
<span id="cb112-12"><a href="#cb112-12" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(p, n)</span>
<span id="cb112-13"><a href="#cb112-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb112-14"><a href="#cb112-14" aria-hidden="true" tabindex="-1"></a>s, t <span class="op">=</span> <span class="fl">1</span><span class="op">/</span><span class="fl">2</span>, <span class="fl">1</span><span class="op">/</span><span class="fl">4</span></span>
<span id="cb112-15"><a href="#cb112-15" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(p, s<span class="op">*</span>u <span class="op">+</span> t<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="69">
<p><img src="vectors_files/figure-html/cell-69-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>So if <span class="math inline">\(\vec{n} \cdot p = d\)</span> (identifying the point <span class="math inline">\(p\)</span> with a vector so the dot product is defined), we will have for any vector <span class="math inline">\(\vec{v} = \langle x, y, z \rangle = s \vec{u} + t \vec{v}\)</span> that</p>
<p><span class="math display">\[
\vec{n} \cdot (p + s\vec{u} + t \vec{v}) = \vec{n} \cdot p + \vec{n} \cdot (s \vec{u} + t \vec{v}) = d + 0 = d,
\]</span></p>
<p>But if <span class="math inline">\(\vec{n} = \langle a, b, c \rangle\)</span>, then this says <span class="math inline">\(d = ax + by + cz\)</span>, so from <span class="math inline">\(\vec{n}\)</span> and <span class="math inline">\(p\)</span> the equation of the plane is given.</p>
<p>In summary:</p>
<table class="table">
<thead>
<tr class="header">
<th style="text-align: left;">Object</th>
<th style="text-align: center;">Equation</th>
<th style="text-align: left;">vector equation</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Line</td>
<td style="text-align: center;"><span class="math inline">\(ax + by = c\)</span></td>
<td style="text-align: left;">line: <span class="math inline">\(p + t\vec{u}\)</span></td>
</tr>
<tr class="even">
<td style="text-align: left;">Plane</td>
<td style="text-align: center;"><span class="math inline">\(ax + by + cz = d\)</span></td>
<td style="text-align: left;">plane: <span class="math inline">\(p + s\vec{u} + t\vec{v}\)</span></td>
</tr>
</tbody>
</table>
<hr>
</section>
<section id="example-2" class="level5">
<h5 class="anchored" data-anchor-id="example-2">Example</h5>
<p>You are given that the vectors <span class="math inline">\(\vec{u} =\langle 6, 3, 1 \rangle\)</span> and <span class="math inline">\(\vec{v} = \langle 3, 2, 1 \rangle\)</span> describe a plane through the point <span class="math inline">\(p=[1,1,2]\)</span>. Find the equation of the plane.</p>
<p>The key is to find the normal vector to the plane, <span class="math inline">\(\vec{n} = \vec{u} \times \vec{v}\)</span>:</p>
<div class="cell" data-hold="true" data-execution_count="69">
<div class="sourceCode cell-code" id="cb113"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb113-1"><a href="#cb113-1" aria-hidden="true" tabindex="-1"></a>u, v, p <span class="op">=</span> [<span class="fl">6</span>,<span class="fl">3</span>,<span class="fl">1</span>], [<span class="fl">3</span>,<span class="fl">2</span>,<span class="fl">1</span>], [<span class="fl">1</span>,<span class="fl">1</span>,<span class="fl">2</span>]</span>
<span id="cb113-2"><a href="#cb113-2" aria-hidden="true" tabindex="-1"></a>n <span class="op">=</span> u <span class="op">×</span> v</span>
<span id="cb113-3"><a href="#cb113-3" aria-hidden="true" tabindex="-1"></a>a, b, c <span class="op">=</span> n</span>
<span id="cb113-4"><a href="#cb113-4" aria-hidden="true" tabindex="-1"></a>d <span class="op">=</span> n <span class="op"></span> p</span>
<span id="cb113-5"><a href="#cb113-5" aria-hidden="true" tabindex="-1"></a><span class="st">"equation of plane: </span><span class="sc">$</span>a<span class="st"> x + </span><span class="sc">$</span>b<span class="st"> y + </span><span class="sc">$</span>c<span class="st"> z = </span><span class="sc">$</span>d<span class="st">"</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="70">
<pre><code>"equation of plane: 1 x + -3 y + 3 z = 4"</code></pre>
</div>
</div>
</section>
</section>
</section>
<section id="questions" class="level2" data-number="53.8">
<h2 data-number="53.8" class="anchored" data-anchor-id="questions"><span class="header-section-number">53.8</span> Questions</h2>
<section id="question" class="level6">
<h6 class="anchored" data-anchor-id="question">Question</h6>
<p>Let <code>u=[1,2,3]</code>, <code>v=[4,3,2]</code>, and <code>w=[5,2,1]</code>.</p>
<p>Find <code>u ⋅ v</code>:</p>
<div class="cell" data-hold="true" data-execution_count="70">
<div class="cell-output cell-output-display" data-execution_count="71">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="11678585338844146208" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_11678585338844146208">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="11678585338844146208" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="11678585338844146208_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("11678585338844146208").addEventListener("change", function() {
var correct = (Math.abs(this.value - 16) <= 0);
var msgBox = document.getElementById('11678585338844146208_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_11678585338844146208")
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_11678585338844146208")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>Are <code>v</code> and <code>w</code> orthogonal?</p>
<div class="cell" data-hold="true" data-execution_count="71">
<div class="cell-output cell-output-display" data-execution_count="72">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="9123085646676828767" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_9123085646676828767">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_9123085646676828767_1">
<input class="form-check-input" type="radio" name="radio_9123085646676828767" id="radio_9123085646676828767_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_9123085646676828767_2">
<input class="form-check-input" type="radio" name="radio_9123085646676828767" id="radio_9123085646676828767_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="9123085646676828767_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_9123085646676828767"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('9123085646676828767_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_9123085646676828767")
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_9123085646676828767")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Find the angle between <code>u</code> and <code>w</code>:</p>
<div class="cell" data-hold="true" data-execution_count="72">
<div class="cell-output cell-output-display" data-execution_count="73">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12842406114543917611" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_12842406114543917611">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="12842406114543917611" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="12842406114543917611_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("12842406114543917611").addEventListener("change", function() {
var correct = (Math.abs(this.value - 0.945250237728822) <= 0.001);
var msgBox = document.getElementById('12842406114543917611_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_12842406114543917611")
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_12842406114543917611")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>Find <code>u × v</code>:</p>
<div class="cell" data-hold="true" data-execution_count="73">
<div class="cell-output cell-output-display" data-execution_count="74">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="7975132883257415009" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_7975132883257415009">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_7975132883257415009_1">
<input class="form-check-input" type="radio" name="radio_7975132883257415009" id="radio_7975132883257415009_1" value="1">
<span class="label-body px-1">
<code>[-1, 6, -7]</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7975132883257415009_2">
<input class="form-check-input" type="radio" name="radio_7975132883257415009" id="radio_7975132883257415009_2" value="2">
<span class="label-body px-1">
<code>[-4, 14, -8]</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7975132883257415009_3">
<input class="form-check-input" type="radio" name="radio_7975132883257415009" id="radio_7975132883257415009_3" value="3">
<span class="label-body px-1">
<code>[-5, 10, -5]</code>
</span>
</label>
</div>
</div>
</div>
<div id="7975132883257415009_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_7975132883257415009"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('7975132883257415009_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_7975132883257415009")
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_7975132883257415009")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>Find the area of the parallelogram formed by <code>v</code> and <code>w</code></p>
<div class="cell" data-hold="true" data-execution_count="74">
<div class="cell-output cell-output-display" data-execution_count="75">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="4787511497459768316" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_4787511497459768316">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="4787511497459768316" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="4787511497459768316_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("4787511497459768316").addEventListener("change", function() {
var correct = (Math.abs(this.value - 9.273618495495704) <= 0.001);
var msgBox = document.getElementById('4787511497459768316_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_4787511497459768316")
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_4787511497459768316")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
<p>Find the volume of the parallelepiped formed by <code>u</code>, <code>v</code>, and <code>w</code>:</p>
<div class="cell" data-hold="true" data-execution_count="75">
<div class="cell-output cell-output-display" data-execution_count="76">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15520550711994138943" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_15520550711994138943">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="15520550711994138943" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="15520550711994138943_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("15520550711994138943").addEventListener("change", function() {
var correct = (Math.abs(this.value - 10) <= 0);
var msgBox = document.getElementById('15520550711994138943_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_15520550711994138943")
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_15520550711994138943")
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>The dot product of two vectors may be described in words: pair off the corresponding values, multiply them, then add. In <code>Julia</code> the <code>zip</code> command will pair off two iterable objects, like vectors, so it seems like this command: <code>sum(prod.(zip(u,v)))</code> will find a dot product. Investigate if it is does or doesnt by testing the following command and comparing to the dot product:</p>
<div class="sourceCode cell-code" id="cb115"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb115-1"><a href="#cb115-1" aria-hidden="true" tabindex="-1"></a>u,v <span class="op">=</span> [<span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">3</span>], [<span class="fl">5</span>,<span class="fl">4</span>,<span class="fl">2</span>]</span>
<span id="cb115-2"><a href="#cb115-2" aria-hidden="true" tabindex="-1"></a><span class="fu">sum</span>(<span class="fu">prod</span>.(<span class="fu">zip</span>(u,v)))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>Does this return the same answer:</p>
<div class="cell" data-hold="true" data-execution_count="77">
<div class="cell-output cell-output-display" data-execution_count="77">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="5493312185544633791" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_5493312185544633791">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_5493312185544633791_1">
<input class="form-check-input" type="radio" name="radio_5493312185544633791" id="radio_5493312185544633791_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5493312185544633791_2">
<input class="form-check-input" type="radio" name="radio_5493312185544633791" id="radio_5493312185544633791_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="5493312185544633791_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_5493312185544633791"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('5493312185544633791_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_5493312185544633791")
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_5493312185544633791")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>What does command <code>zip(u,v)</code> return?</p>
<div class="cell" data-hold="true" data-execution_count="78">
<div class="cell-output cell-output-display" data-execution_count="78">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="3852136201398245501" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_3852136201398245501">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_3852136201398245501_1">
<input class="form-check-input" type="radio" name="radio_3852136201398245501" id="radio_3852136201398245501_1" value="1">
<span class="label-body px-1">
A vector of values <code>[(1, 5), (2, 4), (3, 2)]</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_3852136201398245501_2">
<input class="form-check-input" type="radio" name="radio_3852136201398245501" id="radio_3852136201398245501_2" value="2">
<span class="label-body px-1">
An object of type <code>Base.Iterators.Zip</code> that is only realized when used
</span>
</label>
</div>
</div>
</div>
<div id="3852136201398245501_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_3852136201398245501"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('3852136201398245501_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_3852136201398245501")
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_3852136201398245501")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>What does <code>prod.(zip(u,v))</code> return?</p>
<div class="cell" data-hold="true" data-execution_count="79">
<div class="cell-output cell-output-display" data-execution_count="79">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="4564776488539405931" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_4564776488539405931">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_4564776488539405931_1">
<input class="form-check-input" type="radio" name="radio_4564776488539405931" id="radio_4564776488539405931_1" value="1">
<span class="label-body px-1">
A vector of values <code>[5, 8, 6]</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4564776488539405931_2">
<input class="form-check-input" type="radio" name="radio_4564776488539405931" id="radio_4564776488539405931_2" value="2">
<span class="label-body px-1">
An object of type <code>Base.Iterators.Zip</code> that when realized will produce a vector of values
</span>
</label>
</div>
</div>
</div>
<div id="4564776488539405931_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_4564776488539405931"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('4564776488539405931_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_4564776488539405931")
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_4564776488539405931")
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>Let <span class="math inline">\(\vec{u}\)</span> and <span class="math inline">\(\vec{v}\)</span> be 3-dimensional <strong>unit</strong> vectors. What is the value of</p>
<p><span class="math display">\[
(\vec{u} \times \vec{v}) \cdot (\vec{u} \times \vec{v}) + (\vec{u} \cdot \vec{v})^2?
\]</span></p>
<div class="cell" data-hold="true" data-execution_count="80">
<div class="cell-output cell-output-display" data-execution_count="80">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="2582152223107048840" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_2582152223107048840">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_2582152223107048840_1">
<input class="form-check-input" type="radio" name="radio_2582152223107048840" id="radio_2582152223107048840_1" value="1">
<span class="label-body px-1">
\(0\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2582152223107048840_2">
<input class="form-check-input" type="radio" name="radio_2582152223107048840" id="radio_2582152223107048840_2" value="2">
<span class="label-body px-1">
Can't say in general
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2582152223107048840_3">
<input class="form-check-input" type="radio" name="radio_2582152223107048840" id="radio_2582152223107048840_3" value="3">
<span class="label-body px-1">
\(1\)
</span>
</label>
</div>
</div>
</div>
<div id="2582152223107048840_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_2582152223107048840"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('2582152223107048840_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_2582152223107048840")
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_2582152223107048840")
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>Consider the projection of <span class="math inline">\(\langle 1, 2, 3\rangle\)</span> on <span class="math inline">\(\langle 3, 2, 1\rangle\)</span>. What is its length?</p>
<div class="cell" data-hold="true" data-execution_count="81">
<div class="cell-output cell-output-display" data-execution_count="81">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="6716589518734423052" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_6716589518734423052">
<div style="padding-top: 5px">
<br>
<div class="input-group">
<input id="6716589518734423052" type="number" class="form-control" placeholder="Numeric answer">
</div>
</div>
</div>
<div id="6716589518734423052_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.getElementById("6716589518734423052").addEventListener("change", function() {
var correct = (Math.abs(this.value - 2.6726124191242437) <= 0.001);
var msgBox = document.getElementById('6716589518734423052_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_6716589518734423052")
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_6716589518734423052")
if (explanation != null) {
explanation.style.display = "block";
}
}
});
</script>
</div>
</div>
</section>
<section id="question-4" class="level6">
<h6 class="anchored" data-anchor-id="question-4">Question</h6>
<p>Let <span class="math inline">\(\vec{u} = \langle 1, 2, 3 \rangle\)</span> and <span class="math inline">\(\vec{v} = \langle 3, 2, 1 \rangle\)</span>. Describe the plane created by these two non-parallel vectors going through the origin.</p>
<div class="cell" data-hold="true" data-execution_count="82">
<div class="cell-output cell-output-display" data-execution_count="82">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="2918900355827853541" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_2918900355827853541">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_2918900355827853541_1">
<input class="form-check-input" type="radio" name="radio_2918900355827853541" id="radio_2918900355827853541_1" value="1">
<span class="label-body px-1">
\(-4x + 8y - 4z = 0\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2918900355827853541_2">
<input class="form-check-input" type="radio" name="radio_2918900355827853541" id="radio_2918900355827853541_2" value="2">
<span class="label-body px-1">
\(x + 2y + 3z = 6\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2918900355827853541_3">
<input class="form-check-input" type="radio" name="radio_2918900355827853541" id="radio_2918900355827853541_3" value="3">
<span class="label-body px-1">
\(x + 2y + z = 0\)
</span>
</label>
</div>
</div>
</div>
<div id="2918900355827853541_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_2918900355827853541"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('2918900355827853541_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_2918900355827853541")
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_2918900355827853541")
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>A plane <span class="math inline">\(P_1\)</span> is <em>orthogonal</em> to <span class="math inline">\(\vec{n}_1\)</span>, a plane <span class="math inline">\(P_2\)</span> is <em>orthogonal</em> to <span class="math inline">\(\vec{n}_2\)</span>. Explain why vector <span class="math inline">\(\vec{v} = \vec{n}_1 \times \vec{n}_2\)</span> is parallel to the <em>intersection</em> of <span class="math inline">\(P_1\)</span> and <span class="math inline">\(P_2\)</span>.</p>
<div class="cell" data-hold="true" data-execution_count="83">
<div class="cell-output cell-output-display" data-execution_count="83">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="5871998077526870024" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_5871998077526870024">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_5871998077526870024_1">
<input class="form-check-input" type="radio" name="radio_5871998077526870024" id="radio_5871998077526870024_1" value="1">
<span class="label-body px-1">
\(\vec{v}\) is in plane \(P_1\), as it is orthogonal to \(\vec{n}_1\) and \(P_2\) as it is orthogonal to \(\vec{n}_2\), hence it is parallel to both planes.
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5871998077526870024_2">
<input class="form-check-input" type="radio" name="radio_5871998077526870024" id="radio_5871998077526870024_2" value="2">
<span class="label-body px-1">
\(\vec{n}_1\) and \(\vec{n_2}\) are unit vectors, so the cross product gives the projection, which must be orthogonal to each vector, hence in the intersection
</span>
</label>
</div>
</div>
</div>
<div id="5871998077526870024_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_5871998077526870024"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('5871998077526870024_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_5871998077526870024")
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_5871998077526870024")
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>(From Strang). For an (analog) clock draw vectors from the center out to each of the 12 hours marked on the clock. What is the vector sum of these 12 vectors?</p>
<div class="cell" data-hold="true" data-execution_count="84">
<div class="cell-output cell-output-display" data-execution_count="84">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15918587280836716849" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_15918587280836716849">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_15918587280836716849_1">
<input class="form-check-input" type="radio" name="radio_15918587280836716849" id="radio_15918587280836716849_1" value="1">
<span class="label-body px-1">
\(12 \langle 1, 0 \rangle\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_15918587280836716849_2">
<input class="form-check-input" type="radio" name="radio_15918587280836716849" id="radio_15918587280836716849_2" value="2">
<span class="label-body px-1">
\(\vec{0}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_15918587280836716849_3">
<input class="form-check-input" type="radio" name="radio_15918587280836716849" id="radio_15918587280836716849_3" value="3">
<span class="label-body px-1">
\(\langle 12, 12 \rangle\)
</span>
</label>
</div>
</div>
</div>
<div id="15918587280836716849_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_15918587280836716849"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('15918587280836716849_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_15918587280836716849")
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_15918587280836716849")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>If the vector to 3 oclock is removed, (call this <span class="math inline">\(\langle 1, 0 \rangle\)</span>) what expresses the sum of <em>all</em> the remaining vectors?</p>
<div class="cell" data-hold="true" data-execution_count="85">
<div class="cell-output cell-output-display" data-execution_count="85">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="2886620043201040266" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_2886620043201040266">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_2886620043201040266_1">
<input class="form-check-input" type="radio" name="radio_2886620043201040266" id="radio_2886620043201040266_1" value="1">
<span class="label-body px-1">
\(\langle 1, 0 \rangle\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2886620043201040266_2">
<input class="form-check-input" type="radio" name="radio_2886620043201040266" id="radio_2886620043201040266_2" value="2">
<span class="label-body px-1">
\(\langle -1, 0 \rangle\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_2886620043201040266_3">
<input class="form-check-input" type="radio" name="radio_2886620043201040266" id="radio_2886620043201040266_3" value="3">
<span class="label-body px-1">
\(\langle 11, 11 \rangle\)
</span>
</label>
</div>
</div>
</div>
<div id="2886620043201040266_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_2886620043201040266"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('2886620043201040266_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_2886620043201040266")
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_2886620043201040266")
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>Let <span class="math inline">\(\vec{u}\)</span> and <span class="math inline">\(\vec{v}\)</span> be unit vectors. Let <span class="math inline">\(\vec{w} = \vec{u} + \vec{v}\)</span>. Then <span class="math inline">\(\vec{u} \cdot \vec{w} = \vec{v} \cdot \vec{w}\)</span>. What is the value?</p>
<div class="cell" data-hold="true" data-execution_count="86">
<div class="cell-output cell-output-display" data-execution_count="86">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="622044205562332414" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_622044205562332414">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_622044205562332414_1">
<input class="form-check-input" type="radio" name="radio_622044205562332414" id="radio_622044205562332414_1" value="1">
<span class="label-body px-1">
\(\vec{u}\cdot\vec{v} + \vec{v}\cdot \vec{v}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_622044205562332414_2">
<input class="form-check-input" type="radio" name="radio_622044205562332414" id="radio_622044205562332414_2" value="2">
<span class="label-body px-1">
\(1 + \vec{u}\cdot\vec{v}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_622044205562332414_3">
<input class="form-check-input" type="radio" name="radio_622044205562332414" id="radio_622044205562332414_3" value="3">
<span class="label-body px-1">
\(\vec{u} + \vec{v}\)
</span>
</label>
</div>
</div>
</div>
<div id="622044205562332414_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_622044205562332414"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('622044205562332414_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_622044205562332414")
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_622044205562332414")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>As the two are equal, which interpretation is true?</p>
<div class="cell" data-hold="true" data-execution_count="87">
<div class="cell-output cell-output-display" data-execution_count="87">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="17591290420303386940" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_17591290420303386940">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_17591290420303386940_1">
<input class="form-check-input" type="radio" name="radio_17591290420303386940" id="radio_17591290420303386940_1" value="1">
<span class="label-body px-1">
The vector \(\vec{w}\) must also be a unit vector
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_17591290420303386940_2">
<input class="form-check-input" type="radio" name="radio_17591290420303386940" id="radio_17591290420303386940_2" value="2">
<span class="label-body px-1">
the two are orthogonal
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_17591290420303386940_3">
<input class="form-check-input" type="radio" name="radio_17591290420303386940" id="radio_17591290420303386940_3" value="3">
<span class="label-body px-1">
The angle they make with \(\vec{w}\) is the same
</span>
</label>
</div>
</div>
</div>
<div id="17591290420303386940_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_17591290420303386940"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('17591290420303386940_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_17591290420303386940")
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_17591290420303386940")
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>Suppose <span class="math inline">\(\| \vec{u} + \vec{v} \|^2 = \|\vec{u}\|^2 + \|\vec{v}\|^2\)</span>. What is <span class="math inline">\(\vec{u}\cdot\vec{v}\)</span>?</p>
<p>We have <span class="math inline">\((\vec{u} + \vec{v})\cdot(\vec{u} + \vec{v}) = \vec{u}\cdot \vec{u} + 2 \vec{u}\cdot\vec{v} + \vec{v}\cdot\vec{v}\)</span>. From this, we can infer that:</p>
<div class="cell" data-hold="true" data-execution_count="88">
<div class="cell-output cell-output-display" data-execution_count="88">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="10032830895287811729" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_10032830895287811729">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_10032830895287811729_1">
<input class="form-check-input" type="radio" name="radio_10032830895287811729" id="radio_10032830895287811729_1" value="1">
<span class="label-body px-1">
\(\vec{u}\cdot\vec{v} = 0\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_10032830895287811729_2">
<input class="form-check-input" type="radio" name="radio_10032830895287811729" id="radio_10032830895287811729_2" value="2">
<span class="label-body px-1">
\(\vec{u}\cdot\vec{v} = -(\vec{u}\cdot\vec{u} \vec{v}\cdot\vec{v})\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_10032830895287811729_3">
<input class="form-check-input" type="radio" name="radio_10032830895287811729" id="radio_10032830895287811729_3" value="3">
<span class="label-body px-1">
\(\vec{u}\cdot\vec{v} = 2\)
</span>
</label>
</div>
</div>
</div>
<div id="10032830895287811729_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_10032830895287811729"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('10032830895287811729_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_10032830895287811729")
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_10032830895287811729")
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>Give a geometric reason for this identity:</p>
<p><span class="math display">\[
\vec{u} \cdot (\vec{v} \times \vec{w}) =
\vec{v} \cdot (\vec{w} \times \vec{u}) =
\vec{w} \cdot (\vec{u} \times \vec{v})
\]</span></p>
<div class="cell" data-hold="true" data-execution_count="89">
<div class="cell-output cell-output-display" data-execution_count="89">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="7680399133592224385" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_7680399133592224385">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_7680399133592224385_1">
<input class="form-check-input" type="radio" name="radio_7680399133592224385" id="radio_7680399133592224385_1" value="1">
<span class="label-body px-1">
The triple product describes a volume up to sign, this combination preserves the sign
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7680399133592224385_2">
<input class="form-check-input" type="radio" name="radio_7680399133592224385" id="radio_7680399133592224385_2" value="2">
<span class="label-body px-1">
The vectors are <em>orthogonal</em>, so these are all zero
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7680399133592224385_3">
<input class="form-check-input" type="radio" name="radio_7680399133592224385" id="radio_7680399133592224385_3" value="3">
<span class="label-body px-1">
The vectors are all unit lengths, so these are all 1
</span>
</label>
</div>
</div>
</div>
<div id="7680399133592224385_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_7680399133592224385"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('7680399133592224385_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_7680399133592224385")
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_7680399133592224385")
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>Snells law in planar form is <span class="math inline">\(n_1\sin(\theta_1) = n_2\sin(\theta_2)\)</span> where <span class="math inline">\(n_i\)</span> is a constant depending on the medium.</p>
<div class="cell" data-hold="true" data-execution_count="90">
<div class="cell-output cell-output-display" data-execution_count="90">
<p><img src="vectors_files/figure-html/cell-91-output-1.svg" class="img-fluid"></p>
</div>
</div>
<p>In vector form, we can express it using <em>unit</em> vectors through:</p>
<div class="cell" data-hold="true" data-execution_count="91">
<div class="cell-output cell-output-display" data-execution_count="91">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12300663587044402246" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_12300663587044402246">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_12300663587044402246_1">
<input class="form-check-input" type="radio" name="radio_12300663587044402246" id="radio_12300663587044402246_1" value="1">
<span class="label-body px-1">
\(n_1 (\hat{v_1}\times\hat{N}) = -n_2 (\hat{v_2}\times\hat{N})\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12300663587044402246_2">
<input class="form-check-input" type="radio" name="radio_12300663587044402246" id="radio_12300663587044402246_2" value="2">
<span class="label-body px-1">
\(n_1 (\hat{v_1}\times\hat{N}) = n_2 (\hat{v_2}\times\hat{N})\)
</span>
</label>
</div>
</div>
</div>
<div id="12300663587044402246_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_12300663587044402246"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('12300663587044402246_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_12300663587044402246")
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_12300663587044402246")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-11" class="level6">
<h6 class="anchored" data-anchor-id="question-11">Question</h6>
<p>The Jacobi relationship show that for <em>any</em> <span class="math inline">\(3\)</span> randomly chosen vectors:</p>
<p><span class="math display">\[
\vec{a}\times(\vec{b}\times\vec{c})+
\vec{b}\times(\vec{c}\times\vec{a})+
\vec{c}\times(\vec{a}\times\vec{b})
\]</span></p>
<p>simplifies. To what? (Use <code>SymPy</code> or randomly generated vectors to see.)</p>
<div class="cell" data-hold="true" data-execution_count="92">
<div class="cell-output cell-output-display" data-execution_count="92">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="7338351434865871856" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_7338351434865871856">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_7338351434865871856_1">
<input class="form-check-input" type="radio" name="radio_7338351434865871856" id="radio_7338351434865871856_1" value="1">
<span class="label-body px-1">
\(\vec{a}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7338351434865871856_2">
<input class="form-check-input" type="radio" name="radio_7338351434865871856" id="radio_7338351434865871856_2" value="2">
<span class="label-body px-1">
\(\vec{0}\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_7338351434865871856_3">
<input class="form-check-input" type="radio" name="radio_7338351434865871856" id="radio_7338351434865871856_3" value="3">
<span class="label-body px-1">
\(\vec{a} + \vec{b} + \vec{c}\)
</span>
</label>
</div>
</div>
</div>
<div id="7338351434865871856_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_7338351434865871856"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('7338351434865871856_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_7338351434865871856")
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_7338351434865871856")
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="../differentiable_vector_calculus/polar_coordinates.html" class="pagination-link">
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">52</span>&nbsp; <span class="chapter-title">Polar Coordinates and Curves</span></span>
</a>
</div>
<div class="nav-page nav-page-next">
<a href="../differentiable_vector_calculus/vector_valued_functions.html" class="pagination-link">
<span class="nav-page-text"><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></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>