use quarto, not Pluto to render pages

This commit is contained in:
jverzani committed 2022-07-24 16:38:24 -04:00
1 parent 93c993206a
commit 7b37ca828c
879 files changed
+793311 -2678

No files matched your search

@@ -0,0 +1,15 @@
{
"hash": "9a95a6a055e5a4271b3c57be63506e70",
"result": {
"markdown": "# The Polynomials package\n\n\n\nThis section will use the following add-on packages:\n\n``` {.julia .cell-code}\nimport CalculusWithJulia\nusing Plots\nusing Polynomials\nusing RealPolynomialRoots\nimport SymPy # imported only: some functions, e.g. degree, need qualification\n```\n\n\n\n\n---\n\n\nWhile `SymPy` can be used to represent polynomials, there are also native `Julia` packages available for this and related tasks. These packages include `Polynomials`, `MultivariatePolynomials`, and `AbstractAlgebra`, among many others. (A search on [juliahub.com](juliahub.com) found over $50$ packages matching \"polynomial\".) We will look at the `Polynomials` package in the following, as it is straightforward to use and provides the features we are looking at for univariate polynomials.\n\n\n## Construction\n\n\nThe polynomial expression $p = a_0 + a_1\\cdot x + a_2\\cdot x^2 + \\cdots + a_n\\cdot x^n$ 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, $1, x, x^2, \\dots, x^n$. With this viewpoint, the polynomial $p$ can be identified with the vector `[a0, a1, a2, ..., an]`. The `Polynomials` package provides a wrapper for such an identification through the `Polynomial` constructor. We have previously loaded this add-on package.\n\n\nTo illustrate, the polynomial $p = 3 + 4x + 5x^2$ is constructed with\n\n::: {.cell execution_count=4}\n``` {.julia .cell-code}\np = Polynomial([3,4,5])\n```\n\n::: {.cell-output .cell-output-display execution_count=5}\n```{=html}\n3 &#43; 4&#8729;x &#43; 5&#8729;x<sup>2</sup>\n```\n:::\n:::\n\n\nwhere the vector `[3,4,5]` represents the coefficients. The polynomial $q = 3 + 5x^2 + 7x^4$ has some coefficients that are $0$, these too must be indicated on construction, so we would have:\n\n::: {.cell execution_count=5}\n``` {.julia .cell-code}\nq = Polynomial([3,0,5,0,7])\n```\n\n::: {.cell-output .cell-output-display execution_count=6}\n```{=html}\n3 &#43; 5&#8729;x<sup>2</sup> &#43; 7&#8729;x<sup>4</sup>\n```\n:::\n:::\n\n\nThe `coeffs` function undoes `Polynomial`, returning the coefficients from a `Polynomial` object.\n\n::: {.cell execution_count=6}\n``` {.julia .cell-code}\ncoeffs(q)\n```\n\n::: {.cell-output .cell-output-display execution_count=7}\n```\n5-element Vector{Int64}:\n 3\n 0\n 5\n 0\n 7\n```\n:::\n:::\n\n\nOnce defined, the usual arithmetic operations for polynomials follow:\n\n::: {.cell execution_count=7}\n``` {.julia .cell-code}\np + q\n```\n\n::: {.cell-output .cell-output-display execution_count=8}\n```{=html}\n6 &#43; 4&#8729;x &#43; 10&#8729;x<sup>2</sup> &#43; 7&#8729;x<sup>4</sup>\n```\n:::\n:::\n\n\n::: {.cell execution_count=8}\n``` {.julia .cell-code}\np*q + p^2\n```\n\n::: {.cell-output .cell-output-display execution_count=9}\n```{=html}\n18 &#43; 36&#8729;x &#43; 76&#8729;x<sup>2</sup> &#43; 60&#8729;x<sup>3</sup> &#43; 71&#8729;x<sup>4</sup> &#43; 28&#8729;x<sup>5</sup> &#43; 35&#8729;x<sup>6</sup>\n```\n:::\n:::\n\n\nA polynomial has several familiar methods, such as `degree`:\n\n::: {.cell execution_count=9}\n``` {.julia .cell-code}\ndegree(p), degree(q)\n```\n\n::: {.cell-output .cell-output-display execution_count=10}\n```\n(2, 4)\n```\n:::\n:::\n\n\nThe zero polynomial has degree `-1`, by convention.\n\n\nPolynomials may be evaluated using function notation, that is:\n\n::: {.cell execution_count=10}\n``` {.julia .cell-code}\np(1)\n```\n\n::: {.cell-output .cell-output-display execution_count=11}\n```\n12\n```\n:::\n:::\n\n\nThis 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.\n\n\nThe polynomial variable, in this case `1x`, can be returned by `variable`:\n\n::: {.cell execution_count=11}\n``` {.julia .cell-code}\nx = variable(p)\n```\n\n::: {.cell-output .cell-output-display execution_count=12}\n```{=html}\nx\n```\n:::\n:::\n\n\nThis variable is a `Polynomial` object, so can be manipulated as a polynomial; we can then construct polynomials through expressions like:\n\n::: {.cell execution_count=12}\n``` {.julia .cell-code}\nr = (x-2)^3 * (x-1) * (x+1)\n```\n\n::: {.cell-output .cell-output-display execution_count=13}\n```{=html}\n8 &#45; 12&#8729;x &#45; 2&#8729;x<sup>2</sup> &#43; 11&#8729;x<sup>3</sup> &#45; 6&#8729;x<sup>4</sup> &#43; x<sup>5</sup>\n```\n:::\n:::\n\n\nThe product is expanded for storage by `Polynomials`, which may not be desirable for some uses. A new variable can produced by calling `variable()`; so we could have constructed `p` by:\n\n::: {.cell hold='true' execution_count=13}\n``` {.julia .cell-code}\nx = variable()\n3 + 4x + 5x^2\n```\n\n::: {.cell-output .cell-output-display execution_count=14}\n```{=html}\n3 &#43; 4&#8729;x &#43; 5&#8729;x<sup>2</sup>\n```\n:::\n:::\n\n\nA polynomial in factored form, as `r`Line truncated
"supporting": [
"polynomials_package_files/figure-html"
],
"filters": [],
"includes": {
"include-in-header": [
"<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>\n<script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js\" integrity=\"sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==\" crossorigin=\"anonymous\"></script>\n<script type=\"application/javascript\">define('jquery', [],function() {return window.jQuery;})</script>\n"
]
}
}
}