1962 lines
113 KiB
HTML
1962 lines
113 KiB
HTML
|
<!DOCTYPE html>
|
|||
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
|
|||
|
|
|||
|
<meta charset="utf-8">
|
|||
|
<meta name="generator" content="quarto-1.0.32">
|
|||
|
|
|||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
|
|||
|
|
|||
|
|
|||
|
<title>Calculus with Julia - 13 The Polynomials package</title>
|
|||
|
<style>
|
|||
|
code{white-space: pre-wrap;}
|
|||
|
span.smallcaps{font-variant: small-caps;}
|
|||
|
span.underline{text-decoration: underline;}
|
|||
|
div.column{display: inline-block; vertical-align: top; width: 50%;}
|
|||
|
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
|
|||
|
ul.task-list{list-style: none;}
|
|||
|
pre > code.sourceCode { white-space: pre; position: relative; }
|
|||
|
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
|
|||
|
pre > code.sourceCode > span:empty { height: 1.2em; }
|
|||
|
.sourceCode { overflow: visible; }
|
|||
|
code.sourceCode > span { color: inherit; text-decoration: inherit; }
|
|||
|
div.sourceCode { margin: 1em 0; }
|
|||
|
pre.sourceCode { margin: 0; }
|
|||
|
@media screen {
|
|||
|
div.sourceCode { overflow: auto; }
|
|||
|
}
|
|||
|
@media print {
|
|||
|
pre > code.sourceCode { white-space: pre-wrap; }
|
|||
|
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
|
|||
|
}
|
|||
|
pre.numberSource code
|
|||
|
{ counter-reset: source-line 0; }
|
|||
|
pre.numberSource code > span
|
|||
|
{ position: relative; left: -4em; counter-increment: source-line; }
|
|||
|
pre.numberSource code > span > a:first-child::before
|
|||
|
{ content: counter(source-line);
|
|||
|
position: relative; left: -1em; text-align: right; vertical-align: baseline;
|
|||
|
border: none; display: inline-block;
|
|||
|
-webkit-touch-callout: none; -webkit-user-select: none;
|
|||
|
-khtml-user-select: none; -moz-user-select: none;
|
|||
|
-ms-user-select: none; user-select: none;
|
|||
|
padding: 0 4px; width: 4em;
|
|||
|
color: #aaaaaa;
|
|||
|
}
|
|||
|
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
|
|||
|
div.sourceCode
|
|||
|
{ }
|
|||
|
@media screen {
|
|||
|
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
|
|||
|
}
|
|||
|
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
|
|||
|
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
|
|||
|
code span.at { color: #7d9029; } /* Attribute */
|
|||
|
code span.bn { color: #40a070; } /* BaseN */
|
|||
|
code span.bu { } /* BuiltIn */
|
|||
|
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
|
|||
|
code span.ch { color: #4070a0; } /* Char */
|
|||
|
code span.cn { color: #880000; } /* Constant */
|
|||
|
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
|
|||
|
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
|
|||
|
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
|
|||
|
code span.dt { color: #902000; } /* DataType */
|
|||
|
code span.dv { color: #40a070; } /* DecVal */
|
|||
|
code span.er { color: #ff0000; font-weight: bold; } /* Error */
|
|||
|
code span.ex { } /* Extension */
|
|||
|
code span.fl { color: #40a070; } /* Float */
|
|||
|
code span.fu { color: #06287e; } /* Function */
|
|||
|
code span.im { } /* Import */
|
|||
|
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
|
|||
|
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
|
|||
|
code span.op { color: #666666; } /* Operator */
|
|||
|
code span.ot { color: #007020; } /* Other */
|
|||
|
code span.pp { color: #bc7a00; } /* Preprocessor */
|
|||
|
code span.sc { color: #4070a0; } /* SpecialChar */
|
|||
|
code span.ss { color: #bb6688; } /* SpecialString */
|
|||
|
code span.st { color: #4070a0; } /* String */
|
|||
|
code span.va { color: #19177c; } /* Variable */
|
|||
|
code span.vs { color: #4070a0; } /* VerbatimString */
|
|||
|
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
|
|||
|
</style>
|
|||
|
|
|||
|
|
|||
|
<script src="../site_libs/quarto-nav/quarto-nav.js"></script>
|
|||
|
<script src="../site_libs/quarto-nav/headroom.min.js"></script>
|
|||
|
<script src="../site_libs/clipboard/clipboard.min.js"></script>
|
|||
|
<script src="../site_libs/quarto-search/autocomplete.umd.js"></script>
|
|||
|
<script src="../site_libs/quarto-search/fuse.min.js"></script>
|
|||
|
<script src="../site_libs/quarto-search/quarto-search.js"></script>
|
|||
|
<meta name="quarto:offset" content="../">
|
|||
|
<link href="../precalc/rational_functions.html" rel="next">
|
|||
|
<link href="../precalc/polynomial_roots.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">13</span> <span class="chapter-title">The Polynomials package</span></h1>
|
|||
|
<button type="button" class="quarto-btn-toggle btn" aria-label="Show secondary navigation">
|
|||
|
<i class="bi bi-chevron-right"></i>
|
|||
|
</button>
|
|||
|
</div>
|
|||
|
</nav>
|
|||
|
</header>
|
|||
|
<!-- content -->
|
|||
|
<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar">
|
|||
|
<!-- sidebar -->
|
|||
|
<nav id="quarto-sidebar" class="sidebar collapse sidebar-navigation floating overflow-auto">
|
|||
|
<div class="mt-2 flex-shrink-0 align-items-center">
|
|||
|
<div class="sidebar-search">
|
|||
|
<div id="quarto-search" class="" title="Search"></div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="sidebar-menu-container">
|
|||
|
<ul class="list-unstyled mt-1">
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../index.html" class="sidebar-item-text sidebar-link">Preface</a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item sidebar-item-section">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="true">Precalculus Concepts</a>
|
|||
|
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="true">
|
|||
|
<i class="bi bi-chevron-right ms-2"></i>
|
|||
|
</a>
|
|||
|
</div>
|
|||
|
<ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 show">
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../precalc/calculator.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">1</span> <span class="chapter-title">From calculator to computer</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../precalc/variables.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">2</span> <span class="chapter-title">Variables</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../precalc/numbers_types.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">3</span> <span class="chapter-title">Number systems</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../precalc/logical_expressions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">4</span> <span class="chapter-title">Inequalities, Logical expressions</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../precalc/vectors.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">5</span> <span class="chapter-title">Vectors</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../precalc/ranges.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">6</span> <span class="chapter-title">Ranges and Sets</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../precalc/functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">7</span> <span class="chapter-title">Functions</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../precalc/plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">8</span> <span class="chapter-title">The Graph of a Function</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../precalc/transformations.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">9</span> <span class="chapter-title">Function manipulations</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../precalc/inversefunctions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">10</span> <span class="chapter-title">The Inverse of a Function</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../precalc/polynomial.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">11</span> <span class="chapter-title">Polynomials</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../precalc/polynomial_roots.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">12</span> <span class="chapter-title">Roots of a polynomial</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../precalc/polynomials_package.html" class="sidebar-item-text sidebar-link active"><span class="chapter-number">13</span> <span class="chapter-title">The Polynomials package</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../precalc/rational_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">14</span> <span class="chapter-title">Rational functions</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../precalc/exp_log_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">15</span> <span class="chapter-title">Exponential and logarithmic functions</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../precalc/trig_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">16</span> <span class="chapter-title">Trigonometric functions</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../precalc/julia_overview.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">17</span> <span class="chapter-title">Overview of Julia commands</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item sidebar-item-section">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" aria-expanded="false">Limits</a>
|
|||
|
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" aria-expanded="false">
|
|||
|
<i class="bi bi-chevron-right ms-2"></i>
|
|||
|
</a>
|
|||
|
</div>
|
|||
|
<ul id="quarto-sidebar-section-2" class="collapse list-unstyled sidebar-section depth1 ">
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../limits/limits.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">18</span> <span class="chapter-title">Limits</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../limits/limits_extensions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">19</span> <span class="chapter-title">Limits, issues, extensions of the concept</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../limits/continuity.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">20</span> <span class="chapter-title">Continuity</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../limits/intermediate_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">21</span> <span class="chapter-title">Implications of continuity</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item sidebar-item-section">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="false">Derivatives</a>
|
|||
|
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="false">
|
|||
|
<i class="bi bi-chevron-right ms-2"></i>
|
|||
|
</a>
|
|||
|
</div>
|
|||
|
<ul id="quarto-sidebar-section-3" class="collapse list-unstyled sidebar-section depth1 ">
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../derivatives/derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">22</span> <span class="chapter-title">Derivatives</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../derivatives/numeric_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">23</span> <span class="chapter-title">Numeric derivatives</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../derivatives/symbolic_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">24</span> <span class="chapter-title">Symbolic derivatives</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../derivatives/mean_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">25</span> <span class="chapter-title">The mean value theorem for differentiable functions.</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../derivatives/optimization.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">26</span> <span class="chapter-title">Optimization</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../derivatives/first_second_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">27</span> <span class="chapter-title">The first and second derivatives</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../derivatives/curve_sketching.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">28</span> <span class="chapter-title">Curve Sketching</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../derivatives/linearization.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">29</span> <span class="chapter-title">Linearization</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../derivatives/newtons_method.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">30</span> <span class="chapter-title">Newton’s method</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../derivatives/more_zeros.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">31</span> <span class="chapter-title">Derivative-free alternatives to Newton’s method</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../derivatives/lhospitals_rule.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">32</span> <span class="chapter-title">L’Hospital’s Rule</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../derivatives/implicit_differentiation.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">33</span> <span class="chapter-title">Implicit Differentiation</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../derivatives/related_rates.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">34</span> <span class="chapter-title">Related rates</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../derivatives/taylor_series_polynomials.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">35</span> <span class="chapter-title">Taylor Polynomials and other Approximating Polynomials</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item sidebar-item-section">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-4" aria-expanded="false">Integrals</a>
|
|||
|
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-4" aria-expanded="false">
|
|||
|
<i class="bi bi-chevron-right ms-2"></i>
|
|||
|
</a>
|
|||
|
</div>
|
|||
|
<ul id="quarto-sidebar-section-4" class="collapse list-unstyled sidebar-section depth1 ">
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../integrals/area.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">36</span> <span class="chapter-title">Area under a curve</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../integrals/ftc.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">37</span> <span class="chapter-title">Fundamental Theorem or Calculus</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../integrals/substitution.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">38</span> <span class="chapter-title">Substitution</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../integrals/integration_by_parts.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">39</span> <span class="chapter-title">Integration By Parts</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../integrals/partial_fractions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">40</span> <span class="chapter-title">Partial Fractions</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../integrals/improper_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">41</span> <span class="chapter-title">Improper Integrals</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../integrals/mean_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">42</span> <span class="chapter-title">Mean value theorem for integrals</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../integrals/area_between_curves.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">43</span> <span class="chapter-title">Area between two curves</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../integrals/center_of_mass.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">44</span> <span class="chapter-title">Center of Mass</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../integrals/volumes_slice.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">45</span> <span class="chapter-title">Volumes by slicing</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../integrals/arc_length.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">46</span> <span class="chapter-title">Arc length</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../integrals/surface_area.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">47</span> <span class="chapter-title">Surface Area</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item sidebar-item-section">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-5" aria-expanded="false">ODEs</a>
|
|||
|
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-5" aria-expanded="false">
|
|||
|
<i class="bi bi-chevron-right ms-2"></i>
|
|||
|
</a>
|
|||
|
</div>
|
|||
|
<ul id="quarto-sidebar-section-5" class="collapse list-unstyled sidebar-section depth1 ">
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../ODEs/odes.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">48</span> <span class="chapter-title">ODEs</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../ODEs/euler.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">49</span> <span class="chapter-title">Euler’s method</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../ODEs/solve.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">50</span> <span class="chapter-title">The problem-algorithm-solve interface</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../ODEs/differential_equations.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">51</span> <span class="chapter-title">The <code>DifferentialEquations</code> suite</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item sidebar-item-section">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-6" aria-expanded="false">Differential vector calculus</a>
|
|||
|
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-6" aria-expanded="false">
|
|||
|
<i class="bi bi-chevron-right ms-2"></i>
|
|||
|
</a>
|
|||
|
</div>
|
|||
|
<ul id="quarto-sidebar-section-6" class="collapse list-unstyled sidebar-section depth1 ">
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../differentiable_vector_calculus/polar_coordinates.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">52</span> <span class="chapter-title">Polar Coordinates and Curves</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../differentiable_vector_calculus/vectors.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">53</span> <span class="chapter-title">Vectors and matrices</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../differentiable_vector_calculus/vector_valued_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">54</span> <span class="chapter-title">Vector-valued functions, <span class="math inline">\(f:R \rightarrow R^n\)</span></span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../differentiable_vector_calculus/scalar_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">55</span> <span class="chapter-title">Scalar functions</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../differentiable_vector_calculus/scalar_functions_applications.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">56</span> <span class="chapter-title">Applications with scalar functions</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../differentiable_vector_calculus/vector_fields.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">57</span> <span class="chapter-title">Functions <span class="math inline">\(R^n \rightarrow R^m\)</span></span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../differentiable_vector_calculus/plots_plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">58</span> <span class="chapter-title">2D and 3D plots in Julia with Plots</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item sidebar-item-section">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-7" aria-expanded="false">Integral vector calculus</a>
|
|||
|
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-7" aria-expanded="false">
|
|||
|
<i class="bi bi-chevron-right ms-2"></i>
|
|||
|
</a>
|
|||
|
</div>
|
|||
|
<ul id="quarto-sidebar-section-7" class="collapse list-unstyled sidebar-section depth1 ">
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../integral_vector_calculus/double_triple_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">59</span> <span class="chapter-title">Multi-dimensional integrals</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../integral_vector_calculus/line_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">60</span> <span class="chapter-title">Line and Surface Integrals</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../integral_vector_calculus/div_grad_curl.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">61</span> <span class="chapter-title">The Gradient, Divergence, and Curl</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../integral_vector_calculus/stokes_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">62</span> <span class="chapter-title">Green’s Theorem, Stokes’ Theorem, and the Divergence Theorem</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../integral_vector_calculus/review.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">63</span> <span class="chapter-title">Quick Review of Vector Calculus</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item sidebar-item-section">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-8" aria-expanded="false">Alternatives</a>
|
|||
|
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-8" aria-expanded="false">
|
|||
|
<i class="bi bi-chevron-right ms-2"></i>
|
|||
|
</a>
|
|||
|
</div>
|
|||
|
<ul id="quarto-sidebar-section-8" class="collapse list-unstyled sidebar-section depth1 ">
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../alternatives/plotly_plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">64</span> <span class="chapter-title">JavaScript based plotting libraries</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../alternatives/makie_plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">65</span> <span class="chapter-title">Calculus plots with Makie</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item sidebar-item-section">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-9" aria-expanded="false">Appendices</a>
|
|||
|
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-9" aria-expanded="false">
|
|||
|
<i class="bi bi-chevron-right ms-2"></i>
|
|||
|
</a>
|
|||
|
</div>
|
|||
|
<ul id="quarto-sidebar-section-9" class="collapse list-unstyled sidebar-section depth1 ">
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../misc/getting_started_with_julia.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">66</span> <span class="chapter-title">Getting started with Julia</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../misc/julia_interfaces.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">67</span> <span class="chapter-title">Julia interfaces</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../misc/calculus_with_julia.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">68</span> <span class="chapter-title">The <code>CalculusWithJulia</code> package</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../misc/unicode.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">69</span> <span class="chapter-title">Usages of Unicode symbols</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../misc/quick_notes.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">70</span> <span class="chapter-title">Quick introduction to Calculus with Julia</span></a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li class="sidebar-item">
|
|||
|
<div class="sidebar-item-container">
|
|||
|
<a href="../references.html" class="sidebar-item-text sidebar-link">References</a>
|
|||
|
</div>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
</nav>
|
|||
|
<!-- margin-sidebar -->
|
|||
|
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
|
|||
|
<nav id="TOC" role="doc-toc">
|
|||
|
<h2 id="toc-title">Table of contents</h2>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li><a href="#construction" id="toc-construction" class="nav-link active" data-scroll-target="#construction"> <span class="header-section-number">13.1</span> Construction</a></li>
|
|||
|
<li><a href="#graphs" id="toc-graphs" class="nav-link" data-scroll-target="#graphs"> <span class="header-section-number">13.2</span> Graphs</a></li>
|
|||
|
<li><a href="#roots" id="toc-roots" class="nav-link" data-scroll-target="#roots"> <span class="header-section-number">13.3</span> Roots</a></li>
|
|||
|
<li><a href="#fitting-a-polynomial-to-data" id="toc-fitting-a-polynomial-to-data" class="nav-link" data-scroll-target="#fitting-a-polynomial-to-data"> <span class="header-section-number">13.4</span> Fitting a polynomial to data</a></li>
|
|||
|
<li><a href="#questions" id="toc-questions" class="nav-link" data-scroll-target="#questions"> <span class="header-section-number">13.5</span> Questions</a></li>
|
|||
|
</ul>
|
|||
|
<div class="toc-actions"><div><i class="bi bi-github"></i></div><div class="action-links"><p><a href="https://github.com/jverzani/CalculusWithJuliaNotes.jl/edit/main/quarto/precalc/polynomials_package.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">13</span> <span class="chapter-title">The Polynomials package</span></h1>
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<div class="quarto-title-meta">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</header>
|
|||
|
|
|||
|
<p>This section will use the following add-on packages:</p>
|
|||
|
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</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">Polynomials</span></span>
|
|||
|
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">RealPolynomialRoots</span></span>
|
|||
|
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> <span class="bu">SymPy </span><span class="co"># imported only: some functions, e.g. degree, need qualification</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
|||
|
<hr>
|
|||
|
<p>While <code>SymPy</code> can be used to represent polynomials, there are also native <code>Julia</code> packages available for this and related tasks. These packages include <code>Polynomials</code>, <code>MultivariatePolynomials</code>, and <code>AbstractAlgebra</code>, among many others. (A search on <a href="juliahub.com">juliahub.com</a> found over <span class="math inline">\(50\)</span> packages matching “polynomial”.) We will look at the <code>Polynomials</code> package in the following, as it is straightforward to use and provides the features we are looking at for univariate polynomials.</p>
|
|||
|
<section id="construction" class="level2" data-number="13.1">
|
|||
|
<h2 data-number="13.1" class="anchored" data-anchor-id="construction"><span class="header-section-number">13.1</span> Construction</h2>
|
|||
|
<p>The polynomial expression <span class="math inline">\(p = a_0 + a_1\cdot x + a_2\cdot x^2 + \cdots + a_n\cdot x^n\)</span> can be viewed mathematically as a vector of numbers with respect to some “basis”, which for standard polynomials, as above, is just the set of monomials, <span class="math inline">\(1, x, x^2, \dots, x^n\)</span>. With this viewpoint, the polynomial <span class="math inline">\(p\)</span> can be identified with the vector <code>[a0, a1, a2, ..., an]</code>. The <code>Polynomials</code> package provides a wrapper for such an identification through the <code>Polynomial</code> constructor. We have previously loaded this add-on package.</p>
|
|||
|
<p>To illustrate, the polynomial <span class="math inline">\(p = 3 + 4x + 5x^2\)</span> is constructed with</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>p <span class="op">=</span> <span class="fu">Polynomial</span>([<span class="fl">3</span>,<span class="fl">4</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="5">
|
|||
|
3 + 4∙x + 5∙x<sup>2</sup>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>where the vector <code>[3,4,5]</code> represents the coefficients. The polynomial <span class="math inline">\(q = 3 + 5x^2 + 7x^4\)</span> has some coefficients that are <span class="math inline">\(0\)</span>, these too must be indicated on construction, so we would have:</p>
|
|||
|
<div class="cell" data-execution_count="5">
|
|||
|
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>q <span class="op">=</span> <span class="fu">Polynomial</span>([<span class="fl">3</span>,<span class="fl">0</span>,<span class="fl">5</span>,<span class="fl">0</span>,<span class="fl">7</span>])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="6">
|
|||
|
3 + 5∙x<sup>2</sup> + 7∙x<sup>4</sup>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>The <code>coeffs</code> function undoes <code>Polynomial</code>, returning the coefficients from a <code>Polynomial</code> object.</p>
|
|||
|
<div class="cell" data-execution_count="6">
|
|||
|
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="fu">coeffs</span>(q)</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>5-element Vector{Int64}:
|
|||
|
3
|
|||
|
0
|
|||
|
5
|
|||
|
0
|
|||
|
7</code></pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>Once defined, the usual arithmetic operations for polynomials follow:</p>
|
|||
|
<div class="cell" data-execution_count="7">
|
|||
|
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>p <span class="op">+</span> q</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">
|
|||
|
6 + 4∙x + 10∙x<sup>2</sup> + 7∙x<sup>4</sup>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell" data-execution_count="8">
|
|||
|
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>p<span class="op">*</span>q <span class="op">+</span> p<span class="op">^</span><span class="fl">2</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="9">
|
|||
|
18 + 36∙x + 76∙x<sup>2</sup> + 60∙x<sup>3</sup> + 71∙x<sup>4</sup> + 28∙x<sup>5</sup> + 35∙x<sup>6</sup>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>A polynomial has several familiar methods, such as <code>degree</code>:</p>
|
|||
|
<div class="cell" data-execution_count="9">
|
|||
|
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">degree</span>(p), <span class="fu">degree</span>(q)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="10">
|
|||
|
<pre><code>(2, 4)</code></pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>The zero polynomial has degree <code>-1</code>, by convention.</p>
|
|||
|
<p>Polynomials may be evaluated using function notation, that is:</p>
|
|||
|
<div class="cell" data-execution_count="10">
|
|||
|
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="fu">p</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="11">
|
|||
|
<pre><code>12</code></pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>This blurs the distinction between a polynomial expression – a formal object consisting of an indeterminate, coefficients, and the operations of addition, subtraction, multiplication, and non-negative integer powers – and a polynomial function.</p>
|
|||
|
<p>The polynomial variable, in this case <code>1x</code>, can be returned by <code>variable</code>:</p>
|
|||
|
<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>x <span class="op">=</span> <span class="fu">variable</span>(p)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="12">
|
|||
|
x
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>This variable is a <code>Polynomial</code> object, so can be manipulated as a polynomial; we can then construct polynomials through expressions like:</p>
|
|||
|
<div class="cell" data-execution_count="12">
|
|||
|
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>r <span class="op">=</span> (x<span class="op">-</span><span class="fl">2</span>)<span class="op">^</span><span class="fl">3</span> <span class="op">*</span> (x<span class="op">-</span><span class="fl">1</span>) <span class="op">*</span> (x<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="13">
|
|||
|
8 - 12∙x - 2∙x<sup>2</sup> + 11∙x<sup>3</sup> - 6∙x<sup>4</sup> + x<sup>5</sup>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>The product is expanded for storage by <code>Polynomials</code>, which may not be desirable for some uses. A new variable can produced by calling <code>variable()</code>; so we could have constructed <code>p</code> by:</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="13">
|
|||
|
<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>x <span class="op">=</span> <span class="fu">variable</span>()</span>
|
|||
|
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a><span class="fl">3</span> <span class="op">+</span> <span class="fl">4</span>x <span class="op">+</span> <span class="fl">5</span>x<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="14">
|
|||
|
3 + 4∙x + 5∙x<sup>2</sup>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>A polynomial in factored form, as <code>r</code> above is, can be constructed from its roots. Above, <code>r</code> has roots <span class="math inline">\(2\)</span> (twice), <span class="math inline">\(1\)</span>, and <span class="math inline">\(-1\)</span>. Passing these as a vector to <code>fromroots</code> re-produces <code>r</code>:</p>
|
|||
|
<div class="cell" data-execution_count="14">
|
|||
|
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="fu">fromroots</span>([<span class="fl">2</span>,<span class="fl">2</span>,<span class="fl">1</span>,<span class="op">-</span><span class="fl">1</span>])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="15">
|
|||
|
-4 + 4∙x + 3∙x<sup>2</sup> - 4∙x<sup>3</sup> + x<sup>4</sup>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>The <code>fromroots</code> function is basically the <a href="https://en.wikipedia.org/wiki/Factor_theorem">factor thereom</a> which links the factored form of the polynomial with the roots of the polynomial: <span class="math inline">\((x-k)\)</span> is a factor of <span class="math inline">\(p\)</span> if and only if <span class="math inline">\(k\)</span> is a root of <span class="math inline">\(p\)</span>. By combining a factor of the type <span class="math inline">\((x-k)\)</span> for each specified root, the polynomial can be constructed by multiplying its factors. For example, using <code>prod</code> and a generarator, we would have:</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="15">
|
|||
|
<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>x <span class="op">=</span> <span class="fu">variable</span>()</span>
|
|||
|
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a><span class="fu">prod</span>(x <span class="op">-</span> k <span class="cf">for</span> k <span class="kw">in</span> [<span class="fl">2</span>,<span class="fl">2</span>,<span class="fl">1</span>,<span class="op">-</span><span class="fl">1</span>])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="16">
|
|||
|
-4 + 4∙x + 3∙x<sup>2</sup> - 4∙x<sup>3</sup> + x<sup>4</sup>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>The <code>Polynomials</code> package has different ways to represent polynomials, and a factored form can also be used. For example, the <code>fromroots</code> function constructs polynomials from the specified roots and <code>FactoredPolynomial</code> leaves these in a factored form:</p>
|
|||
|
<div class="cell" data-execution_count="16">
|
|||
|
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="fu">fromroots</span>(FactoredPolynomial, [<span class="fl">2</span>, <span class="fl">2</span>, <span class="fl">1</span>, <span class="op">-</span><span class="fl">1</span>])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="17">
|
|||
|
(x - 2)² * (x + 1) * (x - 1)
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>This form is helpful for some operations, for example polynomial multiplication and positive integer exponentiation, but not others such as addition of polynomials, where such polynomials must first be converted to the standard basis to add and are then converted back into a factored form.</p>
|
|||
|
<hr>
|
|||
|
<p>The indeterminate, or polynomial symbol is a related, but different concept to <code>variable</code>. Polynomials are stored as a collection of coefficients, an implicit basis, <em>and</em> a symbol, in the above this symbol is <code>:x</code>. A polynomial’s symbol is checked to ensure that polynomials with different symbols are not algebraically combined, except for the special case of constant polynomials. The symbol is specified through a second argument on construction:</p>
|
|||
|
<div class="cell" data-execution_count="17">
|
|||
|
<div class="sourceCode cell-code" id="cb18"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>s <span class="op">=</span> <span class="fu">Polynomial</span>([<span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">3</span>], <span class="st">"t"</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">
|
|||
|
1 + 2∙t + 3∙t<sup>2</sup>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>As <code>r</code> uses “<code>x</code>”, and <code>s</code> a “<code>t</code>” the two can not be added, say:</p>
|
|||
|
<div class="cell" data-execution_count="18">
|
|||
|
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a>r <span class="op">+</span> s</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
|||
|
<div class="cell-output cell-output-error">
|
|||
|
<pre><code>LoadError: ArgumentError: Polynomials have different indeterminates</code></pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</section>
|
|||
|
<section id="graphs" class="level2" data-number="13.2">
|
|||
|
<h2 data-number="13.2" class="anchored" data-anchor-id="graphs"><span class="header-section-number">13.2</span> Graphs</h2>
|
|||
|
<p>Polynomial objects have a plot recipe defined – plotting from the <code>Plots</code> package should be as easy as calling <code>plot</code>:</p>
|
|||
|
<div class="cell" data-execution_count="19">
|
|||
|
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(r, legend<span class="op">=</span><span class="cn">false</span>) <span class="co"># suppress the legend</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="20">
|
|||
|
<p><img src="polynomials_package_files/figure-html/cell-20-output-1.svg" class="img-fluid"></p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>The choice of domain is heuristically identified; it and can be manually adjusted, as with:</p>
|
|||
|
<div class="cell" data-execution_count="20">
|
|||
|
<div class="sourceCode cell-code" id="cb22"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(r, <span class="fl">1.5</span>, <span class="fl">2.5</span>, legend<span class="op">=</span><span class="cn">false</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="21">
|
|||
|
<p><img src="polynomials_package_files/figure-html/cell-21-output-1.svg" class="img-fluid"></p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</section>
|
|||
|
<section id="roots" class="level2" data-number="13.3">
|
|||
|
<h2 data-number="13.3" class="anchored" data-anchor-id="roots"><span class="header-section-number">13.3</span> Roots</h2>
|
|||
|
<p>The default <code>plot</code> recipe checks to ensure the real roots of the polynomial are included in the domain of the plot. To do this, it must identify the roots. This is done <em>numerically</em> by the <code>roots</code> function, as in this example:</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="21">
|
|||
|
<div class="sourceCode cell-code" id="cb23"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a>x <span class="op">=</span> <span class="fu">variable</span>()</span>
|
|||
|
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> x<span class="op">^</span><span class="fl">5</span> <span class="op">-</span> x <span class="op">-</span> <span class="fl">1</span></span>
|
|||
|
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a><span class="fu">roots</span>(p)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="22">
|
|||
|
<pre><code>5-element Vector{ComplexF64}:
|
|||
|
-0.7648844336005849 - 0.35247154603172626im
|
|||
|
-0.7648844336005849 + 0.35247154603172626im
|
|||
|
0.18123244446987605 - 1.0839541013177107im
|
|||
|
0.18123244446987605 + 1.0839541013177107im
|
|||
|
1.1673039782614187 + 0.0im</code></pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>A consequence of the fundamental theorem of algebra and the factor theorem is that any fifth degree polynomial with integer coefficients has <span class="math inline">\(5\)</span> roots, where possibly some are complex. For real coefficients, these complex values must come in conjugate pairs, which can be observed from the output. The lone real root is approximately <code>1.1673039782614187</code>. This value being a numeric approximation to the irrational root.</p>
|
|||
|
<div class="callout-note callout callout-style-default callout-captioned">
|
|||
|
<div class="callout-header d-flex align-content-center">
|
|||
|
<div class="callout-icon-container">
|
|||
|
<i class="callout-icon"></i>
|
|||
|
</div>
|
|||
|
<div class="callout-caption-container flex-fill">
|
|||
|
Note
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="callout-body-container callout-body">
|
|||
|
<p><code>SymPy</code> also has a <code>roots</code> function. If both <code>Polynomials</code> and <code>SymPy</code> are used together, calling <code>roots</code> must be qualified, as with <code>Polynomials.roots(...)</code>. Similarly, <code>degree</code> is provided in both, so it too must be qualified.</p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>The <code>roots</code> function numerically identifies roots. As such, it is susceptible to floating point issues. For example, the following polynomial has one root with multiplicity <span class="math inline">\(5\)</span>, but <span class="math inline">\(5\)</span> distinct roots are numerically identified:</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="22">
|
|||
|
<div class="sourceCode cell-code" id="cb25"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a>x <span class="op">=</span> <span class="fu">variable</span>()</span>
|
|||
|
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> (x<span class="op">-</span><span class="fl">1</span>)<span class="op">^</span><span class="fl">5</span></span>
|
|||
|
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a><span class="fu">roots</span>(p)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="23">
|
|||
|
<pre><code>5-element Vector{ComplexF64}:
|
|||
|
0.9990471550471702 + 0.0im
|
|||
|
0.9997060762685409 - 0.0009060415877147721im
|
|||
|
0.9997060762685409 + 0.0009060415877147721im
|
|||
|
1.000770346207878 - 0.0005593476807788428im
|
|||
|
1.000770346207878 + 0.0005593476807788428im</code></pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>The <code>Polynomials</code> package has the <code>multroot</code> function to identify roots of polynomials when there are multiplicities expected. This function is not exported, so is called through:</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="23">
|
|||
|
<div class="sourceCode cell-code" id="cb27"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a>x <span class="op">=</span> <span class="fu">variable</span>()</span>
|
|||
|
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> (x<span class="op">-</span><span class="fl">1</span>)<span class="op">^</span><span class="fl">5</span></span>
|
|||
|
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true" tabindex="-1"></a>Polynomials.Multroot.<span class="fu">multroot</span>(p)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="24">
|
|||
|
<pre><code>(values = [1.0], multiplicities = [5], κ = 0.1348399724926484, ϵ = 0.0)</code></pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>Floating point error can also prevent the finding of real roots. For example, this polynomial has <span class="math inline">\(3\)</span> real roots, but <code>roots</code> finds but <span class="math inline">\(1\)</span>, as the two nearby ones are identified as complex:</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="24">
|
|||
|
<div class="sourceCode cell-code" id="cb29"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a>x <span class="op">=</span> <span class="fu">variable</span>()</span>
|
|||
|
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> <span class="op">-</span><span class="fl">1</span> <span class="op">+</span> <span class="fl">254</span>x <span class="op">-</span> <span class="fl">16129</span>x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> x<span class="op">^</span><span class="fl">9</span></span>
|
|||
|
<span id="cb29-3"><a href="#cb29-3" aria-hidden="true" tabindex="-1"></a><span class="fu">roots</span>(p)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="25">
|
|||
|
<pre><code>9-element Vector{ComplexF64}:
|
|||
|
-3.5980557124631396 - 1.7316513703738028im
|
|||
|
-3.5980557124631396 + 1.7316513703738028im
|
|||
|
-0.8903404519370821 - 3.8909853177372544im
|
|||
|
-0.8903404519370821 + 3.8909853177372544im
|
|||
|
0.007874015748031492 - 2.1956827901729616e-10im
|
|||
|
0.007874015748031492 + 2.1956827901729616e-10im
|
|||
|
2.486125235439536 - 3.1203279635732852im
|
|||
|
2.486125235439536 + 3.1203279635732852im
|
|||
|
3.9887938264253098 + 0.0im</code></pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>The <code>RealPolynomialRoots</code> package, loaded at the top of this section, can assist in the case of identifying real roots of square-free polynomials (no multiple roots). For example:</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="25">
|
|||
|
<div class="sourceCode cell-code" id="cb31"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a>ps <span class="op">=</span> <span class="fu">coeffs</span>(<span class="op">-</span><span class="fl">1</span> <span class="op">+</span> <span class="fl">254</span>x <span class="op">-</span> <span class="fl">16129</span>x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> x<span class="op">^</span><span class="fl">9</span>)</span>
|
|||
|
<span id="cb31-2"><a href="#cb31-2" aria-hidden="true" tabindex="-1"></a>st <span class="op">=</span> <span class="fu">ANewDsc</span>(ps)</span>
|
|||
|
<span id="cb31-3"><a href="#cb31-3" aria-hidden="true" tabindex="-1"></a><span class="fu">refine_roots</span>(st)</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{BigFloat}:
|
|||
|
3.988793826425306473641427181104981832147640952968369063329423338980976674467138
|
|||
|
0.007874015750717319072560781468357231530618080530596497294257518612423955993846073
|
|||
|
0.007874015745345658111832733197085506951679614123256514007974427831118237687743416</code></pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</section>
|
|||
|
<section id="fitting-a-polynomial-to-data" class="level2" data-number="13.4">
|
|||
|
<h2 data-number="13.4" class="anchored" data-anchor-id="fitting-a-polynomial-to-data"><span class="header-section-number">13.4</span> Fitting a polynomial to data</h2>
|
|||
|
<p>The fact that two distinct points determine a line is well known. Deriving the line is easy. Say we have two points <span class="math inline">\((x_0, y_0)\)</span> and <span class="math inline">\((x_1, y_1)\)</span>. The <em>slope</em> is then</p>
|
|||
|
<p><span class="math display">\[
|
|||
|
m = \frac{y_1 - y_0}{x_1 - x_0}, \quad x_1 \neq x_0
|
|||
|
\]</span></p>
|
|||
|
<p>The line is then given from the <em>point-slope</em> form by, say, <span class="math inline">\(y= y_0 + m\cdot (x-x_0)\)</span>. This all assumes, <span class="math inline">\(x_1 \neq x_0\)</span>, as were that the case the slope would be infinite (though the vertical line <span class="math inline">\(x=x_0\)</span> would still be determined).</p>
|
|||
|
<p>A line, <span class="math inline">\(y=mx+b\)</span> can be a linear polynomial or a constant depending on <span class="math inline">\(m\)</span>, so we could say <span class="math inline">\(2\)</span> points determine a polynomial of degree <span class="math inline">\(1\)</span> or less. Similarly, <span class="math inline">\(3\)</span> distinct points determine a degree <span class="math inline">\(2\)</span> polynomial or less, <span class="math inline">\(\dots\)</span>, <span class="math inline">\(n+1\)</span> distinct points determine a degree <span class="math inline">\(n\)</span> or less polynomial. Finding a polynomial, <span class="math inline">\(p\)</span> that goes through <span class="math inline">\(n+1\)</span> points (i.e., <span class="math inline">\(p(x_i)=y_i\)</span> for each <span class="math inline">\(i\)</span>) is called <a href="https://en.wikipedia.org/wiki/Polynomial_interpolation">polynomial interpolation</a>. The main theorem is:</p>
|
|||
|
<blockquote class="blockquote">
|
|||
|
<p><em>Polynomial interpolation theorem</em>: There exists a unique polynomial of degree <span class="math inline">\(n\)</span> or less that interpolates the points <span class="math inline">\((x_0,y_0), (x_1,y_1), \dots, (x_n, y_n)\)</span> when the <span class="math inline">\(x_i\)</span> are distinct.</p>
|
|||
|
</blockquote>
|
|||
|
<p>(Uniqueness follows as suppose <span class="math inline">\(p\)</span> and <span class="math inline">\(q\)</span> satisfy the above, then <span class="math inline">\((p-q)(x) = 0\)</span> at each of the <span class="math inline">\(x_i\)</span> and is of degree <span class="math inline">\(n\)</span> or less, so must be the <span class="math inline">\(0\)</span> polynomial. Existence comes by construction. See the Lagrange basis in the questions.)</p>
|
|||
|
<p>Knowing we can succeed, we approach the problem of <span class="math inline">\(3\)</span> points, say <span class="math inline">\((x_0, y_0)\)</span>, <span class="math inline">\((x_1,y_1)\)</span>, and <span class="math inline">\((x_2, y_2)\)</span>. There is a polynomial <span class="math inline">\(p = a\cdot x^2 + b\cdot x + c\)</span> with <span class="math inline">\(p(x_i) = y_i\)</span>. This gives <span class="math inline">\(3\)</span> equations for the <span class="math inline">\(3\)</span> unknown values <span class="math inline">\(a\)</span>, <span class="math inline">\(b\)</span>, and <span class="math inline">\(c\)</span>:</p>
|
|||
|
<p><span class="math display">\[
|
|||
|
\begin{align*}
|
|||
|
a\cdot x_0^2 + b\cdot x_0 + c &= y_0\\
|
|||
|
a\cdot x_1^2 + b\cdot x_1 + c &= y_1\\
|
|||
|
a\cdot x_2^2 + b\cdot x_2 + c &= y_2\\
|
|||
|
\end{align*}
|
|||
|
\]</span></p>
|
|||
|
<p>Solving this with <code>SymPy</code> is tractable. A comprehension is used below to create the <span class="math inline">\(3\)</span> equations; the <code>zip</code> function is a simple means to iterate over <span class="math inline">\(2\)</span> or more iterables simultaneously:</p>
|
|||
|
<div class="cell" data-execution_count="26">
|
|||
|
<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>SymPy.<span class="pp">@syms</span> a b c xs[<span class="fl">0</span><span class="op">:</span><span class="fl">2</span>] ys[<span class="fl">0</span><span class="op">:</span><span class="fl">2</span>]</span>
|
|||
|
<span id="cb33-2"><a href="#cb33-2" aria-hidden="true" tabindex="-1"></a>eqs <span class="op">=</span> [a<span class="op">*</span>xi<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> b<span class="op">*</span>xi <span class="op">+</span> c <span class="op">~</span> yi for (xi,yi) <span class="kw">in</span> <span class="fu">zip</span>(xs, ys)]</span>
|
|||
|
<span id="cb33-3"><a href="#cb33-3" aria-hidden="true" tabindex="-1"></a>abc <span class="op">=</span> SymPy.<span class="fu">solve</span>(eqs, [a,b,c])</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>Dict{Any, Any} with 3 entries:
|
|||
|
a => (-xs₀*ys₁ + xs₀*ys₂ + xs₁*ys₀ - xs₁*ys₂ - xs₂*ys₀ + xs₂*ys₁)/(xs₀^2*xs₁ …
|
|||
|
c => (xs₀^2*xs₁*ys₂ - xs₀^2*xs₂*ys₁ - xs₀*xs₁^2*ys₂ + xs₀*xs₂^2*ys₁ + xs₁^2*x…
|
|||
|
b => (xs₀^2*ys₁ - xs₀^2*ys₂ - xs₁^2*ys₀ + xs₁^2*ys₂ + xs₂^2*ys₀ - xs₂^2*ys₁)/…</code></pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>As can be seen, the terms do get quite unwieldy when treated symbolically. Numerically, the <code>fit</code> function from the <code>Polynomials</code> package will return the interpolating polynomial. To compare,</p>
|
|||
|
<div class="cell" data-execution_count="27">
|
|||
|
<div class="sourceCode cell-code" id="cb35"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a><span class="fu">fit</span>(Polynomial, [<span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">3</span>], [<span class="fl">3</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="28">
|
|||
|
8.0 - 6.5∙x + 1.5∙x<sup>2</sup>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>and we can compare that the two give the same answer with, for example:</p>
|
|||
|
<div class="cell" data-execution_count="28">
|
|||
|
<div class="sourceCode cell-code" id="cb36"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a>abc[b]((xs <span class="op">.=></span> [<span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">3</span>])<span class="op">...</span>, (ys <span class="op">.=></span> [<span class="fl">3</span>,<span class="fl">1</span>,<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="29">
|
|||
|
<pre><code>-13/2</code></pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>(Ignore the tricky way of substituting in each value of <code>xs</code> and <code>ys</code> for the symbolic values in <code>x</code> and <code>y</code>.)</p>
|
|||
|
<section id="example-inverse-quadratic-interpolation" class="level5">
|
|||
|
<h5 class="anchored" data-anchor-id="example-inverse-quadratic-interpolation">Example Inverse quadratic interpolation</h5>
|
|||
|
<p>A related problem, that will arise when finding iterative means to solve for zeros of functions, is <em>inverse</em> quadratic interpolation. That is finding <span class="math inline">\(q\)</span> that goes through the points <span class="math inline">\((x_0,y_0), (x_1, y_1), \dots, (x_n, y_n)\)</span> satisfying <span class="math inline">\(q(y_i) = x_i\)</span>. (That is <span class="math inline">\(x\)</span> and <span class="math inline">\(y\)</span> are reversed, as with inverse functions.) For the envisioned task, where the inverse quadratic function intersects the <span class="math inline">\(x\)</span> axis is of interest, which is at the constant term of the polynomial (as it is like the <span class="math inline">\(y\)</span> intercept of typical polynomial). Let’s see what that is in general by replicating the above steps (though now the assumption is the <span class="math inline">\(y\)</span> values are distinct):</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="29">
|
|||
|
<div class="sourceCode cell-code" id="cb38"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb38-1"><a href="#cb38-1" aria-hidden="true" tabindex="-1"></a>SymPy.<span class="pp">@syms</span> a b c xs[<span class="fl">0</span><span class="op">:</span><span class="fl">2</span>] ys[<span class="fl">0</span><span class="op">:</span><span class="fl">2</span>]</span>
|
|||
|
<span id="cb38-2"><a href="#cb38-2" aria-hidden="true" tabindex="-1"></a>eqs <span class="op">=</span> [a<span class="op">*</span>yi<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> b<span class="op">*</span>yi <span class="op">+</span> c <span class="op">~</span> xi for (xi, yi) <span class="kw">in</span> <span class="fu">zip</span>(xs,ys)]</span>
|
|||
|
<span id="cb38-3"><a href="#cb38-3" aria-hidden="true" tabindex="-1"></a>abc <span class="op">=</span> SymPy.<span class="fu">solve</span>(eqs, [a,b,c])</span>
|
|||
|
<span id="cb38-4"><a href="#cb38-4" aria-hidden="true" tabindex="-1"></a>abc[c]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="30">
|
|||
|
<pre><code> 2 2 2 2 2
|
|||
|
xs₀⋅ys₁ ⋅ys₂ - xs₀⋅ys₁⋅ys₂ - xs₁⋅ys₀ ⋅ys₂ + xs₁⋅ys₀⋅ys₂ + xs₂⋅ys₀ ⋅ys₁ - xs₂
|
|||
|
──────────────────────────────────────────────────────────────────────────────
|
|||
|
2 2 2 2 2 2
|
|||
|
ys₀ ⋅ys₁ - ys₀ ⋅ys₂ - ys₀⋅ys₁ + ys₀⋅ys₂ + ys₁ ⋅ys₂ - ys₁⋅ys₂
|
|||
|
|
|||
|
2
|
|||
|
⋅ys₀⋅ys₁
|
|||
|
─────────
|
|||
|
|
|||
|
</code></pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>We can graphically see the result for the specific values of <code>xs</code> and <code>ys</code> as follows:</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="30">
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="31">
|
|||
|
<p><img src="polynomials_package_files/figure-html/cell-31-output-1.svg" class="img-fluid"></p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</section>
|
|||
|
</section>
|
|||
|
<section id="questions" class="level2" data-number="13.5">
|
|||
|
<h2 data-number="13.5" class="anchored" data-anchor-id="questions"><span class="header-section-number">13.5</span> Questions</h2>
|
|||
|
<section id="question" class="level6">
|
|||
|
<h6 class="anchored" data-anchor-id="question">Question</h6>
|
|||
|
<p>Do the polynomials <span class="math inline">\(p = x^4\)</span> and <span class="math inline">\(q = x^2 - 2\)</span> intersect?</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="31">
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="32">
|
|||
|
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="4097296116917583197" data-controltype="">
|
|||
|
<div class="form-group ">
|
|||
|
<div class="controls">
|
|||
|
<div class="form" id="controls_4097296116917583197">
|
|||
|
<div style="padding-top: 5px">
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_4097296116917583197_1">
|
|||
|
<input class="form-check-input" type="radio" name="radio_4097296116917583197" id="radio_4097296116917583197_1" value="1">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
Yes
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_4097296116917583197_2">
|
|||
|
<input class="form-check-input" type="radio" name="radio_4097296116917583197" id="radio_4097296116917583197_2" value="2">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
No
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div id="4097296116917583197_message" style="padding-bottom: 15px"></div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</form>
|
|||
|
|
|||
|
<script text="text/javascript">
|
|||
|
document.querySelectorAll('input[name="radio_4097296116917583197"]').forEach(function(rb) {
|
|||
|
rb.addEventListener("change", function() {
|
|||
|
var correct = rb.value == 2;
|
|||
|
var msgBox = document.getElementById('4097296116917583197_message');
|
|||
|
if(correct) {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_4097296116917583197")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "none";
|
|||
|
}
|
|||
|
} else {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_4097296116917583197")
|
|||
|
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>Do the polynomials <span class="math inline">\(p = x^4-4\)</span> and <span class="math inline">\(q = x^2 - 2\)</span> intersect?</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="32">
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="33">
|
|||
|
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12533354764205883248" data-controltype="">
|
|||
|
<div class="form-group ">
|
|||
|
<div class="controls">
|
|||
|
<div class="form" id="controls_12533354764205883248">
|
|||
|
<div style="padding-top: 5px">
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_12533354764205883248_1">
|
|||
|
<input class="form-check-input" type="radio" name="radio_12533354764205883248" id="radio_12533354764205883248_1" value="1">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
Yes
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_12533354764205883248_2">
|
|||
|
<input class="form-check-input" type="radio" name="radio_12533354764205883248" id="radio_12533354764205883248_2" value="2">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
No
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div id="12533354764205883248_message" style="padding-bottom: 15px"></div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</form>
|
|||
|
|
|||
|
<script text="text/javascript">
|
|||
|
document.querySelectorAll('input[name="radio_12533354764205883248"]').forEach(function(rb) {
|
|||
|
rb.addEventListener("change", function() {
|
|||
|
var correct = rb.value == 1;
|
|||
|
var msgBox = document.getElementById('12533354764205883248_message');
|
|||
|
if(correct) {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_12533354764205883248")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "none";
|
|||
|
}
|
|||
|
} else {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_12533354764205883248")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "block";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
})});
|
|||
|
|
|||
|
</script>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</section>
|
|||
|
<section id="question-2" class="level6">
|
|||
|
<h6 class="anchored" data-anchor-id="question-2">Question</h6>
|
|||
|
<p>How many real roots does <span class="math inline">\(p = 1 + x + x^2 + x^3 + x^4 + x^5\)</span> have?</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="33">
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="34">
|
|||
|
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="13022392878996149725" data-controltype="">
|
|||
|
<div class="form-group ">
|
|||
|
<div class="controls">
|
|||
|
<div class="form" id="controls_13022392878996149725">
|
|||
|
<div style="padding-top: 5px">
|
|||
|
<br>
|
|||
|
<div class="input-group">
|
|||
|
<input id="13022392878996149725" type="number" class="form-control" placeholder="Numeric answer">
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div id="13022392878996149725_message" style="padding-bottom: 15px"></div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</form>
|
|||
|
|
|||
|
<script text="text/javascript">
|
|||
|
document.getElementById("13022392878996149725").addEventListener("change", function() {
|
|||
|
var correct = (Math.abs(this.value - 1) <= 0);
|
|||
|
var msgBox = document.getElementById('13022392878996149725_message');
|
|||
|
if(correct) {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_13022392878996149725")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "none";
|
|||
|
}
|
|||
|
} else {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_13022392878996149725")
|
|||
|
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>Mathematically we say the <span class="math inline">\(0\)</span> polynomial has no degree. What convention does <code>Polynomials</code> use? (Look at <code>degree(zero(Polynomial))</code>.)</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="34">
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="35">
|
|||
|
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="5919373500149881922" data-controltype="">
|
|||
|
<div class="form-group ">
|
|||
|
<div class="controls">
|
|||
|
<div class="form" id="controls_5919373500149881922">
|
|||
|
<div style="padding-top: 5px">
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_5919373500149881922_1">
|
|||
|
<input class="form-check-input" type="radio" name="radio_5919373500149881922" id="radio_5919373500149881922_1" value="1">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
<code>nothing</code>
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_5919373500149881922_2">
|
|||
|
<input class="form-check-input" type="radio" name="radio_5919373500149881922" id="radio_5919373500149881922_2" value="2">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
<code>-1</code>
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_5919373500149881922_3">
|
|||
|
<input class="form-check-input" type="radio" name="radio_5919373500149881922" id="radio_5919373500149881922_3" value="3">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
<code>0</code>
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_5919373500149881922_4">
|
|||
|
<input class="form-check-input" type="radio" name="radio_5919373500149881922" id="radio_5919373500149881922_4" value="4">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
<code>Inf</code>
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_5919373500149881922_5">
|
|||
|
<input class="form-check-input" type="radio" name="radio_5919373500149881922" id="radio_5919373500149881922_5" value="5">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
<code>-Inf</code>
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div id="5919373500149881922_message" style="padding-bottom: 15px"></div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</form>
|
|||
|
|
|||
|
<script text="text/javascript">
|
|||
|
document.querySelectorAll('input[name="radio_5919373500149881922"]').forEach(function(rb) {
|
|||
|
rb.addEventListener("change", function() {
|
|||
|
var correct = rb.value == 2;
|
|||
|
var msgBox = document.getElementById('5919373500149881922_message');
|
|||
|
if(correct) {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_5919373500149881922")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "none";
|
|||
|
}
|
|||
|
} else {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_5919373500149881922")
|
|||
|
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>Consider the polynomial <span class="math inline">\(p(x) = a_1 x - a_3 x^3 + a_5 x^5\)</span> where</p>
|
|||
|
<p><span class="math display">\[
|
|||
|
\begin{align*}
|
|||
|
a_1 &= 4(\frac{3}{\pi} - \frac{9}{16}) \\
|
|||
|
a_3 &= 2a_1 -\frac{5}{2}\\
|
|||
|
a_5 &= a_1 - \frac{3}{2}.
|
|||
|
\end{align*}
|
|||
|
\]</span></p>
|
|||
|
<ul>
|
|||
|
<li>Form the polynomial <code>p</code> by first computing the <span class="math inline">\(a\)</span>s and forming <code>p=Polynomial([0,a1,0,-a3,0,a5])</code></li>
|
|||
|
<li>Form the polynomial <code>q</code> by these commands <code>x=variable(); q=p(2x/pi)</code></li>
|
|||
|
</ul>
|
|||
|
<p>The polynomial <code>q</code>, a <span class="math inline">\(5\)</span>th-degree polynomial, is a good approximation of for the <a href="http://www.coranac.com/2009/07/sines/">sine</a> function.</p>
|
|||
|
<p>Make graphs of both <code>q</code> and <code>sin</code>. Over which interval is the approximation (visually) a good one?</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="35">
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="36">
|
|||
|
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12847769603474659595" data-controltype="">
|
|||
|
<div class="form-group ">
|
|||
|
<div class="controls">
|
|||
|
<div class="form" id="controls_12847769603474659595">
|
|||
|
<div style="padding-top: 5px">
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_12847769603474659595_1">
|
|||
|
<input class="form-check-input" type="radio" name="radio_12847769603474659595" id="radio_12847769603474659595_1" value="1">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
\([0,1]\)
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_12847769603474659595_2">
|
|||
|
<input class="form-check-input" type="radio" name="radio_12847769603474659595" id="radio_12847769603474659595_2" value="2">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
\([0,\pi]\)
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_12847769603474659595_3">
|
|||
|
<input class="form-check-input" type="radio" name="radio_12847769603474659595" id="radio_12847769603474659595_3" value="3">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
\([0,2\pi]\)
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div id="12847769603474659595_message" style="padding-bottom: 15px"></div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</form>
|
|||
|
|
|||
|
<script text="text/javascript">
|
|||
|
document.querySelectorAll('input[name="radio_12847769603474659595"]').forEach(function(rb) {
|
|||
|
rb.addEventListener("change", function() {
|
|||
|
var correct = rb.value == 1;
|
|||
|
var msgBox = document.getElementById('12847769603474659595_message');
|
|||
|
if(correct) {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_12847769603474659595")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "none";
|
|||
|
}
|
|||
|
} else {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_12847769603474659595")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "block";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
})});
|
|||
|
|
|||
|
</script>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>(This <a href="https://www.nullhardware.com/blog/fixed-point-sine-and-cosine-for-embedded-systems/">blog post</a> shows how this approximation is valuable under some specific circumstances.)</p>
|
|||
|
</section>
|
|||
|
<section id="question-5" class="level6">
|
|||
|
<h6 class="anchored" data-anchor-id="question-5">Question</h6>
|
|||
|
<p>The polynomial</p>
|
|||
|
<div class="cell" data-execution_count="36">
|
|||
|
<div class="sourceCode cell-code" id="cb40"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb40-1"><a href="#cb40-1" aria-hidden="true" tabindex="-1"></a><span class="fu">fromroots</span>([<span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">3</span>,<span class="fl">3</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="37">
|
|||
|
-90 + 213∙x - 184∙x<sup>2</sup> + 74∙x<sup>3</sup> - 14∙x<sup>4</sup> + x<sup>5</sup>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>has <span class="math inline">\(5\)</span> sign changes and <span class="math inline">\(5\)</span> real roots. For <code>x = variable()</code> use <code>div(p, x-3)</code> to find the result of dividing <span class="math inline">\(p\)</span> by <span class="math inline">\(x-3\)</span>. How many sign changes are there in the new polynomial?</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="37">
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="38">
|
|||
|
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="13981049973965617249" data-controltype="">
|
|||
|
<div class="form-group ">
|
|||
|
<div class="controls">
|
|||
|
<div class="form" id="controls_13981049973965617249">
|
|||
|
<div style="padding-top: 5px">
|
|||
|
<br>
|
|||
|
<div class="input-group">
|
|||
|
<input id="13981049973965617249" type="number" class="form-control" placeholder="Numeric answer">
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div id="13981049973965617249_message" style="padding-bottom: 15px"></div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</form>
|
|||
|
|
|||
|
<script text="text/javascript">
|
|||
|
document.getElementById("13981049973965617249").addEventListener("change", function() {
|
|||
|
var correct = (Math.abs(this.value - 4) <= 0);
|
|||
|
var msgBox = document.getElementById('13981049973965617249_message');
|
|||
|
if(correct) {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_13981049973965617249")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "none";
|
|||
|
}
|
|||
|
} else {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_13981049973965617249")
|
|||
|
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>The identification of a collection of coefficients with a polynomial depends on an understood <strong>basis</strong>. A basis for the polynomials of degree <span class="math inline">\(n\)</span> or less, consists of a minimal collection of polynomials for which all the polynomials of degree <span class="math inline">\(n\)</span> or less can be expressed through a combination of sums of terms, each of which is just a coefficient times a basis member. The typical basis is the <span class="math inline">\(n+\)</span> polynomials <span class="math inline">\(1`, `x`, `x^2, \dots, x^n\)</span>. However, though every basis must have <span class="math inline">\(n+1\)</span> members, they need not be these.</p>
|
|||
|
<p>A basis used by <a href="https://en.wikipedia.org/wiki/Lagrange_polynomial">Lagrange</a> is the following. Let there be <span class="math inline">\(n+1\)</span> points distinct points <span class="math inline">\(x_0, x_1, \dots, x_n\)</span>. For each <span class="math inline">\(i\)</span> in <span class="math inline">\(0\)</span> to <span class="math inline">\(n\)</span> define</p>
|
|||
|
<p><span class="math display">\[
|
|||
|
l_i(x) = \prod_{0 \leq j \leq n; j \ne i} \frac{x-x_j}{x_i - x_j} =
|
|||
|
\frac{(x-x_1)\cdot(x-x_2)\cdot \cdots \cdot (x-x_{j-1}) \cdot (x-x_{j+1}) \cdot \cdots \cdot (x-x_n)}{(x_i-x_1)\cdot(x_i-x_2)\cdot \cdots \cdot (x_i-x_{j-1}) \cdot (x_i-x_{j+1}) \cdot \cdots \cdot (x_i-x_n)}.
|
|||
|
\]</span></p>
|
|||
|
<p>That is <span class="math inline">\(l_i(x)\)</span> is a product of terms like <span class="math inline">\((x-x_j)/(x_i-x_j)\)</span> <em>except</em> when <span class="math inline">\(j=i\)</span>.</p>
|
|||
|
<p>What is is the value of <span class="math inline">\(l_0(x_0)\)</span>?</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="38">
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="39">
|
|||
|
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="13670772177198330103" data-controltype="">
|
|||
|
<div class="form-group ">
|
|||
|
<div class="controls">
|
|||
|
<div class="form" id="controls_13670772177198330103">
|
|||
|
<div style="padding-top: 5px">
|
|||
|
<br>
|
|||
|
<div class="input-group">
|
|||
|
<input id="13670772177198330103" type="number" class="form-control" placeholder="Numeric answer">
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div id="13670772177198330103_message" style="padding-bottom: 15px"></div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</form>
|
|||
|
|
|||
|
<script text="text/javascript">
|
|||
|
document.getElementById("13670772177198330103").addEventListener("change", function() {
|
|||
|
var correct = (Math.abs(this.value - 1) <= 0);
|
|||
|
var msgBox = document.getElementById('13670772177198330103_message');
|
|||
|
if(correct) {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_13670772177198330103")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "none";
|
|||
|
}
|
|||
|
} else {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_13670772177198330103")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "block";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
});
|
|||
|
|
|||
|
</script>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>Why?</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="39">
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="40">
|
|||
|
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="10488258305547777757" data-controltype="">
|
|||
|
<div class="form-group ">
|
|||
|
<div class="controls">
|
|||
|
<div class="form" id="controls_10488258305547777757">
|
|||
|
<div style="padding-top: 5px">
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_10488258305547777757_1">
|
|||
|
<input class="form-check-input" type="radio" name="radio_10488258305547777757" id="radio_10488258305547777757_1" value="1">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
All terms like \((x-x_j)/(x_0 - x_j)\) will be \(1\) when \(x=x_0\) and these are all the terms in the product defining \(l_0\).
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_10488258305547777757_2">
|
|||
|
<input class="form-check-input" type="radio" name="radio_10488258305547777757" id="radio_10488258305547777757_2" value="2">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
The term \((x_0-x_0)\) will be \(0\), so the product will be zero
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div id="10488258305547777757_message" style="padding-bottom: 15px"></div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</form>
|
|||
|
|
|||
|
<script text="text/javascript">
|
|||
|
document.querySelectorAll('input[name="radio_10488258305547777757"]').forEach(function(rb) {
|
|||
|
rb.addEventListener("change", function() {
|
|||
|
var correct = rb.value == 1;
|
|||
|
var msgBox = document.getElementById('10488258305547777757_message');
|
|||
|
if(correct) {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_10488258305547777757")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "none";
|
|||
|
}
|
|||
|
} else {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_10488258305547777757")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "block";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
})});
|
|||
|
|
|||
|
</script>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>What is the value of <span class="math inline">\(l_i(x_i)\)</span>?</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="40">
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="41">
|
|||
|
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="465391815469923932" data-controltype="">
|
|||
|
<div class="form-group ">
|
|||
|
<div class="controls">
|
|||
|
<div class="form" id="controls_465391815469923932">
|
|||
|
<div style="padding-top: 5px">
|
|||
|
<br>
|
|||
|
<div class="input-group">
|
|||
|
<input id="465391815469923932" type="number" class="form-control" placeholder="Numeric answer">
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div id="465391815469923932_message" style="padding-bottom: 15px"></div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</form>
|
|||
|
|
|||
|
<script text="text/javascript">
|
|||
|
document.getElementById("465391815469923932").addEventListener("change", function() {
|
|||
|
var correct = (Math.abs(this.value - 1) <= 0);
|
|||
|
var msgBox = document.getElementById('465391815469923932_message');
|
|||
|
if(correct) {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_465391815469923932")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "none";
|
|||
|
}
|
|||
|
} else {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_465391815469923932")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "block";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
});
|
|||
|
|
|||
|
</script>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>What is the value of <span class="math inline">\(l_0(x_1)\)</span>?</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="41">
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="42">
|
|||
|
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="16146351592704184351" data-controltype="">
|
|||
|
<div class="form-group ">
|
|||
|
<div class="controls">
|
|||
|
<div class="form" id="controls_16146351592704184351">
|
|||
|
<div style="padding-top: 5px">
|
|||
|
<br>
|
|||
|
<div class="input-group">
|
|||
|
<input id="16146351592704184351" type="number" class="form-control" placeholder="Numeric answer">
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div id="16146351592704184351_message" style="padding-bottom: 15px"></div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</form>
|
|||
|
|
|||
|
<script text="text/javascript">
|
|||
|
document.getElementById("16146351592704184351").addEventListener("change", function() {
|
|||
|
var correct = (Math.abs(this.value - 0) <= 0);
|
|||
|
var msgBox = document.getElementById('16146351592704184351_message');
|
|||
|
if(correct) {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_16146351592704184351")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "none";
|
|||
|
}
|
|||
|
} else {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_16146351592704184351")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "block";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
});
|
|||
|
|
|||
|
</script>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>Why?</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="42">
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="43">
|
|||
|
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="3728242699583194034" data-controltype="">
|
|||
|
<div class="form-group ">
|
|||
|
<div class="controls">
|
|||
|
<div class="form" id="controls_3728242699583194034">
|
|||
|
<div style="padding-top: 5px">
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_3728242699583194034_1">
|
|||
|
<input class="form-check-input" type="radio" name="radio_3728242699583194034" id="radio_3728242699583194034_1" value="1">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
The term \((x-x_1)/(x_0-x_1)\) is omitted from the product, so the answer is non-zero.
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_3728242699583194034_2">
|
|||
|
<input class="form-check-input" type="radio" name="radio_3728242699583194034" id="radio_3728242699583194034_2" value="2">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
The term like \((x-x_1)/(x_0 - x_1)\) will be \(0\) when \(x=x_1\) and so the product will be \(0\).
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div id="3728242699583194034_message" style="padding-bottom: 15px"></div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</form>
|
|||
|
|
|||
|
<script text="text/javascript">
|
|||
|
document.querySelectorAll('input[name="radio_3728242699583194034"]').forEach(function(rb) {
|
|||
|
rb.addEventListener("change", function() {
|
|||
|
var correct = rb.value == 2;
|
|||
|
var msgBox = document.getElementById('3728242699583194034_message');
|
|||
|
if(correct) {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_3728242699583194034")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "none";
|
|||
|
}
|
|||
|
} else {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_3728242699583194034")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "block";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
})});
|
|||
|
|
|||
|
</script>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>What is the value of <span class="math inline">\(l_i(x_j)\)</span> <em>if</em> <span class="math inline">\(i \ne j\)</span>?</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="43">
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="44">
|
|||
|
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="5404360744551166210" data-controltype="">
|
|||
|
<div class="form-group ">
|
|||
|
<div class="controls">
|
|||
|
<div class="form" id="controls_5404360744551166210">
|
|||
|
<div style="padding-top: 5px">
|
|||
|
<br>
|
|||
|
<div class="input-group">
|
|||
|
<input id="5404360744551166210" type="number" class="form-control" placeholder="Numeric answer">
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div id="5404360744551166210_message" style="padding-bottom: 15px"></div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</form>
|
|||
|
|
|||
|
<script text="text/javascript">
|
|||
|
document.getElementById("5404360744551166210").addEventListener("change", function() {
|
|||
|
var correct = (Math.abs(this.value - 0) <= 0);
|
|||
|
var msgBox = document.getElementById('5404360744551166210_message');
|
|||
|
if(correct) {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_5404360744551166210")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "none";
|
|||
|
}
|
|||
|
} else {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_5404360744551166210")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "block";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
});
|
|||
|
|
|||
|
</script>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>Suppose the <span class="math inline">\(x_0, x_1, \dots, x_n\)</span> are the <span class="math inline">\(x\)</span> coordinates of <span class="math inline">\(n\)</span> distinct points <span class="math inline">\((x_0,y_0)\)</span>, <span class="math inline">\((x_1, y_1), \dots, (x_n,y_n).\)</span> Form the polynomial with the above basis and coefficients being the <span class="math inline">\(y\)</span> values. That is consider:</p>
|
|||
|
<p><span class="math display">\[
|
|||
|
p(x) = \sum_{i=0}^n y_i l_i(x) = y_0l_0(x) + y_1l_1(x) + \dots + y_nl_n(x)
|
|||
|
\]</span></p>
|
|||
|
<p>What is the value of <span class="math inline">\(p(x_j)\)</span>?</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="44">
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="45">
|
|||
|
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12911860293389297308" data-controltype="">
|
|||
|
<div class="form-group ">
|
|||
|
<div class="controls">
|
|||
|
<div class="form" id="controls_12911860293389297308">
|
|||
|
<div style="padding-top: 5px">
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_12911860293389297308_1">
|
|||
|
<input class="form-check-input" type="radio" name="radio_12911860293389297308" id="radio_12911860293389297308_1" value="1">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
\(0\)
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_12911860293389297308_2">
|
|||
|
<input class="form-check-input" type="radio" name="radio_12911860293389297308" id="radio_12911860293389297308_2" value="2">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
\(1\)
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_12911860293389297308_3">
|
|||
|
<input class="form-check-input" type="radio" name="radio_12911860293389297308" id="radio_12911860293389297308_3" value="3">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
\(y_j\)
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div id="12911860293389297308_message" style="padding-bottom: 15px"></div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</form>
|
|||
|
|
|||
|
<script text="text/javascript">
|
|||
|
document.querySelectorAll('input[name="radio_12911860293389297308"]').forEach(function(rb) {
|
|||
|
rb.addEventListener("change", function() {
|
|||
|
var correct = rb.value == 3;
|
|||
|
var msgBox = document.getElementById('12911860293389297308_message');
|
|||
|
if(correct) {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_12911860293389297308")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "none";
|
|||
|
}
|
|||
|
} else {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_12911860293389297308")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "block";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
})});
|
|||
|
|
|||
|
</script>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<p>This last answer is why <span class="math inline">\(p\)</span> is called an <em>interpolating</em> polynomial and this question shows an alternative way to identify interpolating polynomials from solving a system of linear equations.</p>
|
|||
|
</section>
|
|||
|
<section id="question-7" class="level6">
|
|||
|
<h6 class="anchored" data-anchor-id="question-7">Question</h6>
|
|||
|
<p>The Chebyshev (<span class="math inline">\(T\)</span>) polynomials are polynomials which use a different basis from the standard basis. Denote the basis elements <span class="math inline">\(T_0\)</span>, <span class="math inline">\(T_1\)</span>, … where we have <span class="math inline">\(T_0(x) = 1\)</span>, <span class="math inline">\(T_1(x) = x\)</span>, and for bigger indices <span class="math inline">\(T_{i+1}(x) = 2xT_i(x) - T_{i-1}(x)\)</span>. The first others are then:</p>
|
|||
|
<p><span class="math display">\[
|
|||
|
\begin{align*}
|
|||
|
T_2(x) &= 2xT_1(x) - T_0(x) = 2x^2 - 1\\
|
|||
|
T_3(x) &= 2xT_2(x) - T_1(x) = 2x(2x^2-1) - x = 4x^3 - 3x\\
|
|||
|
T_4(x) &= 2xT_3(x) - T_2(x) = 2x(4x^3-3x) - (2x^2-1) = 8x^4 - 8x^2 + 1
|
|||
|
\end{align*}
|
|||
|
\]</span></p>
|
|||
|
<p>With these definitions what is the polynomial associated to the coefficients <span class="math inline">\([0,1,2,3]\)</span> with this basis?</p>
|
|||
|
<div class="cell" data-hold="true" data-execution_count="45">
|
|||
|
<div class="cell-output cell-output-display" data-execution_count="46">
|
|||
|
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="2912488806934549104" data-controltype="">
|
|||
|
<div class="form-group ">
|
|||
|
<div class="controls">
|
|||
|
<div class="form" id="controls_2912488806934549104">
|
|||
|
<div style="padding-top: 5px">
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_2912488806934549104_1">
|
|||
|
<input class="form-check-input" type="radio" name="radio_2912488806934549104" id="radio_2912488806934549104_1" value="1">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
It is \(0\cdot 1 + 1 \cdot x + 2 \cdots x^2 + 3\cdot x^3 = x + 2x^2 + 3x^3\)
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_2912488806934549104_2">
|
|||
|
<input class="form-check-input" type="radio" name="radio_2912488806934549104" id="radio_2912488806934549104_2" value="2">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
It is \(0\cdot T_1(x) + 1\cdot T_1(x) + 2\cdot T_2(x) + 3\cdot T_3(x) = -2 - 8\cdot x + 4\cdot x^2 + 12\cdot x^3\)`
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
<div class="form-check">
|
|||
|
<label class="form-check-label" for="radio_2912488806934549104_3">
|
|||
|
<input class="form-check-input" type="radio" name="radio_2912488806934549104" id="radio_2912488806934549104_3" value="3">
|
|||
|
|
|||
|
<span class="label-body px-1">
|
|||
|
It is \(0\cdot T_1(x) + 1\cdot T_1(x) + 2\cdot T_2(x) + 3\cdot T_3(x) = 0\)
|
|||
|
</span>
|
|||
|
</label>
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div id="2912488806934549104_message" style="padding-bottom: 15px"></div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</form>
|
|||
|
|
|||
|
<script text="text/javascript">
|
|||
|
document.querySelectorAll('input[name="radio_2912488806934549104"]').forEach(function(rb) {
|
|||
|
rb.addEventListener("change", function() {
|
|||
|
var correct = rb.value == 2;
|
|||
|
var msgBox = document.getElementById('2912488806934549104_message');
|
|||
|
if(correct) {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_2912488806934549104")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "none";
|
|||
|
}
|
|||
|
} else {
|
|||
|
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>";
|
|||
|
var explanation = document.getElementById("explanation_2912488806934549104")
|
|||
|
if (explanation != null) {
|
|||
|
explanation.style.display = "block";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
})});
|
|||
|
|
|||
|
</script>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="callout-note callout callout-style-default callout-captioned">
|
|||
|
<div class="callout-header d-flex align-content-center">
|
|||
|
<div class="callout-icon-container">
|
|||
|
<i class="callout-icon"></i>
|
|||
|
</div>
|
|||
|
<div class="callout-caption-container flex-fill">
|
|||
|
Note
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="callout-body-container callout-body">
|
|||
|
<p>The <code>Polynomials</code> package has an implementation, so you can check your answer through <code>convert(Polynomial, ChebyshevT([0,1,2,3]))</code>. Similarly, the <code>SpecialPolynomials</code> package has these and many other polynomial bases represented.</p>
|
|||
|
<p>The <code>ApproxFun</code> package is built on top of polynomials expressed in this basis, as the Chebyshev polynomials have special properties which make them very suitable when approximating functions with polynomials. The <code>ApproxFun</code> package uses easier-to-manipulate polynomials to approximate functions very accurately, thereby being useful for investigating properties of non-linear functions leveraging properties for polynomials.</p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</section>
|
|||
|
</section>
|
|||
|
|
|||
|
</main> <!-- /main -->
|
|||
|
<script id="quarto-html-after-body" type="application/javascript">
|
|||
|
window.document.addEventListener("DOMContentLoaded", function (event) {
|
|||
|
const toggleBodyColorMode = (bsSheetEl) => {
|
|||
|
const mode = bsSheetEl.getAttribute("data-mode");
|
|||
|
const bodyEl = window.document.querySelector("body");
|
|||
|
if (mode === "dark") {
|
|||
|
bodyEl.classList.add("quarto-dark");
|
|||
|
bodyEl.classList.remove("quarto-light");
|
|||
|
} else {
|
|||
|
bodyEl.classList.add("quarto-light");
|
|||
|
bodyEl.classList.remove("quarto-dark");
|
|||
|
}
|
|||
|
}
|
|||
|
const toggleBodyColorPrimary = () => {
|
|||
|
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
|
|||
|
if (bsSheetEl) {
|
|||
|
toggleBodyColorMode(bsSheetEl);
|
|||
|
}
|
|||
|
}
|
|||
|
toggleBodyColorPrimary();
|
|||
|
const icon = "";
|
|||
|
const anchorJS = new window.AnchorJS();
|
|||
|
anchorJS.options = {
|
|||
|
placement: 'right',
|
|||
|
icon: icon
|
|||
|
};
|
|||
|
anchorJS.add('.anchored');
|
|||
|
const clipboard = new window.ClipboardJS('.code-copy-button', {
|
|||
|
target: function(trigger) {
|
|||
|
return trigger.previousElementSibling;
|
|||
|
}
|
|||
|
});
|
|||
|
clipboard.on('success', function(e) {
|
|||
|
// button target
|
|||
|
const button = e.trigger;
|
|||
|
// don't keep focus
|
|||
|
button.blur();
|
|||
|
// flash "checked"
|
|||
|
button.classList.add('code-copy-button-checked');
|
|||
|
var currentTitle = button.getAttribute("title");
|
|||
|
button.setAttribute("title", "Copied!");
|
|||
|
setTimeout(function() {
|
|||
|
button.setAttribute("title", currentTitle);
|
|||
|
button.classList.remove('code-copy-button-checked');
|
|||
|
}, 1000);
|
|||
|
// clear code selection
|
|||
|
e.clearSelection();
|
|||
|
});
|
|||
|
function tippyHover(el, contentFn) {
|
|||
|
const config = {
|
|||
|
allowHTML: true,
|
|||
|
content: contentFn,
|
|||
|
maxWidth: 500,
|
|||
|
delay: 100,
|
|||
|
arrow: false,
|
|||
|
appendTo: function(el) {
|
|||
|
return el.parentElement;
|
|||
|
},
|
|||
|
interactive: true,
|
|||
|
interactiveBorder: 10,
|
|||
|
theme: 'quarto',
|
|||
|
placement: 'bottom-start'
|
|||
|
};
|
|||
|
window.tippy(el, config);
|
|||
|
}
|
|||
|
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
|
|||
|
for (var i=0; i<noterefs.length; i++) {
|
|||
|
const ref = noterefs[i];
|
|||
|
tippyHover(ref, function() {
|
|||
|
let href = ref.getAttribute('href');
|
|||
|
try { href = new URL(href).hash; } catch {}
|
|||
|
const id = href.replace(/^#\/?/, "");
|
|||
|
const note = window.document.getElementById(id);
|
|||
|
return note.innerHTML;
|
|||
|
});
|
|||
|
}
|
|||
|
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
|
|||
|
for (var i=0; i<bibliorefs.length; i++) {
|
|||
|
const ref = bibliorefs[i];
|
|||
|
const cites = ref.parentNode.getAttribute('data-cites').split(' ');
|
|||
|
tippyHover(ref, function() {
|
|||
|
var popup = window.document.createElement('div');
|
|||
|
cites.forEach(function(cite) {
|
|||
|
var citeDiv = window.document.createElement('div');
|
|||
|
citeDiv.classList.add('hanging-indent');
|
|||
|
citeDiv.classList.add('csl-entry');
|
|||
|
var biblioDiv = window.document.getElementById('ref-' + cite);
|
|||
|
if (biblioDiv) {
|
|||
|
citeDiv.innerHTML = biblioDiv.innerHTML;
|
|||
|
}
|
|||
|
popup.appendChild(citeDiv);
|
|||
|
});
|
|||
|
return popup.innerHTML;
|
|||
|
});
|
|||
|
}
|
|||
|
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
|
|||
|
var filterRegex = new RegExp('/' + window.location.host + '/');
|
|||
|
var isInternal = (href) => {
|
|||
|
return filterRegex.test(href) || localhostRegex.test(href);
|
|||
|
}
|
|||
|
// Inspect non-navigation links and adorn them if external
|
|||
|
var links = window.document.querySelectorAll('a:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external)');
|
|||
|
for (var i=0; i<links.length; i++) {
|
|||
|
const link = links[i];
|
|||
|
if (!isInternal(link.href)) {
|
|||
|
// target, if specified
|
|||
|
link.setAttribute("target", "_blank");
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
</script>
|
|||
|
<nav class="page-navigation">
|
|||
|
<div class="nav-page nav-page-previous">
|
|||
|
<a href="../precalc/polynomial_roots.html" class="pagination-link">
|
|||
|
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">12</span> <span class="chapter-title">Roots of a polynomial</span></span>
|
|||
|
</a>
|
|||
|
</div>
|
|||
|
<div class="nav-page nav-page-next">
|
|||
|
<a href="../precalc/rational_functions.html" class="pagination-link">
|
|||
|
<span class="nav-page-text"><span class="chapter-number">14</span> <span class="chapter-title">Rational functions</span></span> <i class="bi bi-arrow-right-short"></i>
|
|||
|
</a>
|
|||
|
</div>
|
|||
|
</nav>
|
|||
|
</div> <!-- /content -->
|
|||
|
<footer class="footer">
|
|||
|
<div class="nav-footer">
|
|||
|
<div class="nav-footer-center">Copyright 2022, John Verzani</div>
|
|||
|
</div>
|
|||
|
</footer>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</body></html>
|