15 lines
54 KiB
JSON
15 lines
54 KiB
JSON
{
|
||
"hash": "af0f0f158354f694e7d529a75ca08c78",
|
||
"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 + 4∙x + 5∙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 + 5∙x<sup>2</sup> + 7∙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 + 4∙x + 10∙x<sup>2</sup> + 7∙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 + 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>\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 - 12∙x - 2∙x<sup>2</sup> + 11∙x<sup>3</sup> - 6∙x<sup>4</sup> + 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 + 4∙x + 5∙x<sup>2</sup>\n```\n:::\n:::\n\n\nA polynomial in factored form, as `r` above is, can be constructed from its roots. Above, `r` has roots $2$ (twice), $1$, and $-1$. Passing these as a vector to `fromroots` re-produces `r`:\n\n::: {.cell execution_count=14}\n``` {.julia .cell-code}\nfromroots([2,2,1,-1])\n```\n\n::: {.cell-output .cell-output-display execution_count=15}\n```{=html}\n-4 + 4∙x + 3∙x<sup>2</sup> - 4∙x<sup>3</sup> + x<sup>4</sup>\n```\n:::\n:::\n\n\nThe `fromroots` function is basically the [factor thereom](https://en.wikipedia.org/wiki/Factor_theorem) which links the factored form of the polynomial with the roots of the polynomial: $(x-k)$ is a factor of $p$ if and only if $k$ is a root of $p$. By combining a factor of the type $(x-k)$ for each specified root, the polynomial can be constructed by multiplying its factors. For example, using `prod` and a generarator, we would have:\n\n::: {.cell hold='true' execution_count=15}\n``` {.julia .cell-code}\nx = variable()\nprod(x - k for k in [2,2,1,-1])\n```\n\n::: {.cell-output .cell-output-display execution_count=16}\n```{=html}\n-4 + 4∙x + 3∙x<sup>2</sup> - 4∙x<sup>3</sup> + x<sup>4</sup>\n```\n:::\n:::\n\n\nThe `Polynomials` package has different ways to represent polynomials, and a factored form can also be used. For example, the `fromroots` function constructs polynomials from the specified roots and `FactoredPolynomial` leaves these in a factored form:\n\n::: {.cell execution_count=16}\n``` {.julia .cell-code}\nfromroots(FactoredPolynomial, [2, 2, 1, -1])\n```\n\n::: {.cell-output .cell-output-display execution_count=17}\n```{=html}\n(x - 2)² * (x + 1) * (x - 1)\n```\n:::\n:::\n\n\nThis 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.\n\n\n---\n\nThe indeterminate, or polynomial symbol is a related, but different concept to `variable`. Polynomials are stored as a collection of coefficients, an implicit basis, *and* a symbol, in the above this symbol is `:x`. 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:\n\n::: {.cell execution_count=17}\n``` {.julia .cell-code}\ns = Polynomial([1,2,3], \"t\")\n```\n\n::: {.cell-output .cell-output-display execution_count=18}\n```{=html}\n1 + 2∙t + 3∙t<sup>2</sup>\n```\n:::\n:::\n\n\nAs `r` uses \"`x`\", and `s` a \"`t`\" the two can not be added, say:\n\n::: {.cell execution_count=18}\n``` {.julia .cell-code}\nr + s\n```\n\n::: {.cell-output .cell-output-error}\n```\nLoadError: ArgumentError: Polynomials have different indeterminates\n```\n:::\n:::\n\n\n## Graphs\n\n\nPolynomial objects have a plot recipe defined – plotting from the `Plots` package should be as easy as calling `plot`:\n\n::: {.cell execution_count=19}\n``` {.julia .cell-code}\nplot(r, legend=false) # suppress the legend\n```\n\n::: {.cell-output .cell-output-display execution_count=20}\n{}\n:::\n:::\n\n\nThe choice of domain is heuristically identified; it and can be manually adjusted, as with:\n\n::: {.cell execution_count=20}\n``` {.julia .cell-code}\nplot(r, 1.5, 2.5, legend=false)\n```\n\n::: {.cell-output .cell-output-display execution_count=21}\n{}\n:::\n:::\n\n\n## Roots\n\n\nThe default `plot` 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 *numerically* by the `roots` function, as in this example:\n\n::: {.cell hold='true' execution_count=21}\n``` {.julia .cell-code}\nx = variable()\np = x^5 - x - 1\nroots(p)\n```\n\n::: {.cell-output .cell-output-display execution_count=22}\n```\n5-element Vector{ComplexF64}:\n -0.7648844336005849 - 0.35247154603172626im\n -0.7648844336005849 + 0.35247154603172626im\n 0.18123244446987605 - 1.0839541013177107im\n 0.18123244446987605 + 1.0839541013177107im\n 1.1673039782614187 + 0.0im\n```\n:::\n:::\n\n\nA consequence of the fundamental theorem of algebra and the factor theorem is that any fifth degree polynomial with integer coefficients has $5$ 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 `1.1673039782614187`. This value being a numeric approximation to the irrational root.\n\n\n:::{.callout-note}\n## Note\n`SymPy` also has a `roots` function. If both `Polynomials` and `SymPy` are used together, calling `roots` must be qualified, as with `Polynomials.roots(...)`. Similarly, `degree` is provided in both, so it too must be qualified.\n\n:::\n\nThe `roots` function numerically identifies roots. As such, it is susceptible to floating point issues. For example, the following polynomial has one root with multiplicity $5$, but $5$ distinct roots are numerically identified:\n\n::: {.cell hold='true' execution_count=22}\n``` {.julia .cell-code}\nx = variable()\np = (x-1)^5\nroots(p)\n```\n\n::: {.cell-output .cell-output-display execution_count=23}\n```\n5-element Vector{ComplexF64}:\n 0.9990471550471702 + 0.0im\n 0.9997060762685409 - 0.0009060415877147721im\n 0.9997060762685409 + 0.0009060415877147721im\n 1.000770346207878 - 0.0005593476807788428im\n 1.000770346207878 + 0.0005593476807788428im\n```\n:::\n:::\n\n\nThe `Polynomials` package has the `multroot` function to identify roots of polynomials when there are multiplicities expected. This function is not exported, so is called through:\n\n::: {.cell hold='true' execution_count=23}\n``` {.julia .cell-code}\nx = variable()\np = (x-1)^5\nPolynomials.Multroot.multroot(p)\n```\n\n::: {.cell-output .cell-output-display execution_count=24}\n```\n(values = [1.0], multiplicities = [5], κ = 0.1348399724926484, ϵ = 0.0)\n```\n:::\n:::\n\n\nFloating point error can also prevent the finding of real roots. For example, this polynomial has $3$ real roots, but `roots` finds but $1$, as the two nearby ones are identified as complex:\n\n::: {.cell hold='true' execution_count=24}\n``` {.julia .cell-code}\nx = variable()\np = -1 + 254x - 16129x^2 + x^9\nroots(p)\n```\n\n::: {.cell-output .cell-output-display execution_count=25}\n```\n9-element Vector{ComplexF64}:\n -3.5980557124631396 - 1.7316513703738028im\n -3.5980557124631396 + 1.7316513703738028im\n -0.8903404519370821 - 3.8909853177372544im\n -0.8903404519370821 + 3.8909853177372544im\n 0.007874015748031492 - 2.1956827901729616e-10im\n 0.007874015748031492 + 2.1956827901729616e-10im\n 2.486125235439536 - 3.1203279635732852im\n 2.486125235439536 + 3.1203279635732852im\n 3.9887938264253098 + 0.0im\n```\n:::\n:::\n\n\nThe `RealPolynomialRoots` 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:\n\n::: {.cell hold='true' execution_count=25}\n``` {.julia .cell-code}\nps = coeffs(-1 + 254x - 16129x^2 + x^9)\nst = ANewDsc(ps)\nrefine_roots(st)\n```\n\n::: {.cell-output .cell-output-display execution_count=26}\n```\n3-element Vector{BigFloat}:\n 3.988793826425306473641427181104981832147640952968369063329423338980976674467138\n 0.007874015750717319072560781468357231530618080530596497294257518612423955993846073\n 0.007874015745345658111832733197085506951679614123256514007974427831118237687743416\n```\n:::\n:::\n\n\n## Fitting a polynomial to data\n\n\nThe fact that two distinct points determine a line is well known. Deriving the line is easy. Say we have two points $(x_0, y_0)$ and $(x_1, y_1)$. The *slope* is then\n\n\n\n$$\nm = \\frac{y_1 - y_0}{x_1 - x_0}, \\quad x_1 \\neq x_0\n$$\n\n\nThe line is then given from the *point-slope* form by, say, $y= y_0 + m\\cdot (x-x_0)$. This all assumes, $x_1 \\neq x_0$, as were that the case the slope would be infinite (though the vertical line $x=x_0$ would still be determined).\n\n\nA line, $y=mx+b$ can be a linear polynomial or a constant depending on $m$, so we could say $2$ points determine a polynomial of degree $1$ or less. Similarly, $3$ distinct points determine a degree $2$ polynomial or less, $\\dots$, $n+1$ distinct points determine a degree $n$ or less polynomial. Finding a polynomial, $p$ that goes through $n+1$ points (i.e., $p(x_i)=y_i$ for each $i$) is called [polynomial interpolation](https://en.wikipedia.org/wiki/Polynomial_interpolation). The main theorem is:\n\n\n> *Polynomial interpolation theorem*: There exists a unique polynomial of degree $n$ or less that interpolates the points $(x_0,y_0), (x_1,y_1), \\dots, (x_n, y_n)$ when the $x_i$ are distinct.\n\n\n\n(Uniqueness follows as suppose $p$ and $q$ satisfy the above, then $(p-q)(x) = 0$ at each of the $x_i$ and is of degree $n$ or less, so must be the $0$ polynomial. Existence comes by construction. See the Lagrange basis in the questions.)\n\n\nKnowing we can succeed, we approach the problem of $3$ points, say $(x_0, y_0)$, $(x_1,y_1)$, and $(x_2, y_2)$. There is a polynomial $p = a\\cdot x^2 + b\\cdot x + c$ with $p(x_i) = y_i$. This gives $3$ equations for the $3$ unknown values $a$, $b$, and $c$:\n\n\n\n$$\n\\begin{align*}\na\\cdot x_0^2 + b\\cdot x_0 + c &= y_0\\\\\na\\cdot x_1^2 + b\\cdot x_1 + c &= y_1\\\\\na\\cdot x_2^2 + b\\cdot x_2 + c &= y_2\\\\\n\\end{align*}\n$$\n\n\nSolving this with `SymPy` is tractable. A comprehension is used below to create the $3$ equations; the `zip` function is a simple means to iterate over $2$ or more iterables simultaneously:\n\n::: {.cell execution_count=26}\n``` {.julia .cell-code}\nSymPy.@syms a b c xs[0:2] ys[0:2]\neqs = [a*xi^2 + b*xi + c ~ yi for (xi,yi) in zip(xs, ys)]\nabc = SymPy.solve(eqs, [a,b,c])\n```\n\n::: {.cell-output .cell-output-display execution_count=27}\n```\nDict{Any, Any} with 3 entries:\n a => (-xs₀*ys₁ + xs₀*ys₂ + xs₁*ys₀ - xs₁*ys₂ - xs₂*ys₀ + xs₂*ys₁)/(xs₀^2*xs₁ …\n c => (xs₀^2*xs₁*ys₂ - xs₀^2*xs₂*ys₁ - xs₀*xs₁^2*ys₂ + xs₀*xs₂^2*ys₁ + xs₁^2*x…\n b => (xs₀^2*ys₁ - xs₀^2*ys₂ - xs₁^2*ys₀ + xs₁^2*ys₂ + xs₂^2*ys₀ - xs₂^2*ys₁)/…\n```\n:::\n:::\n\n\nAs can be seen, the terms do get quite unwieldy when treated symbolically. Numerically, the `fit` function from the `Polynomials` package will return the interpolating polynomial. To compare,\n\n::: {.cell execution_count=27}\n``` {.julia .cell-code}\nfit(Polynomial, [1,2,3], [3,1,2])\n```\n\n::: {.cell-output .cell-output-display execution_count=28}\n```{=html}\n8.0 - 6.5∙x + 1.5∙x<sup>2</sup>\n```\n:::\n:::\n\n\nand we can compare that the two give the same answer with, for example:\n\n::: {.cell execution_count=28}\n``` {.julia .cell-code}\nabc[b]((xs .=> [1,2,3])..., (ys .=> [3,1,2])...)\n```\n\n::: {.cell-output .cell-output-display execution_count=29}\n```\n-13/2\n```\n:::\n:::\n\n\n(Ignore the tricky way of substituting in each value of `xs` and `ys` for the symbolic values in `x` and `y`.)\n\n\n##### Example Inverse quadratic interpolation\n\n\nA related problem, that will arise when finding iterative means to solve for zeros of functions, is *inverse* quadratic interpolation. That is finding $q$ that goes through the points $(x_0,y_0), (x_1, y_1), \\dots, (x_n, y_n)$ satisfying $q(y_i) = x_i$. (That is $x$ and $y$ are reversed, as with inverse functions.) For the envisioned task, where the inverse quadratic function intersects the $x$ axis is of interest, which is at the constant term of the polynomial (as it is like the $y$ intercept of typical polynomial). Let's see what that is in general by replicating the above steps (though now the assumption is the $y$ values are distinct):\n\n::: {.cell hold='true' execution_count=29}\n``` {.julia .cell-code}\nSymPy.@syms a b c xs[0:2] ys[0:2]\neqs = [a*yi^2 + b*yi + c ~ xi for (xi, yi) in zip(xs,ys)]\nabc = SymPy.solve(eqs, [a,b,c])\nabc[c]\n```\n\n::: {.cell-output .cell-output-display execution_count=30}\n```\n 2 2 2 2 2 \nxs₀⋅ys₁ ⋅ys₂ - xs₀⋅ys₁⋅ys₂ - xs₁⋅ys₀ ⋅ys₂ + xs₁⋅ys₀⋅ys₂ + xs₂⋅ys₀ ⋅ys₁ - xs₂\n──────────────────────────────────────────────────────────────────────────────\n 2 2 2 2 2 2 \n ys₀ ⋅ys₁ - ys₀ ⋅ys₂ - ys₀⋅ys₁ + ys₀⋅ys₂ + ys₁ ⋅ys₂ - ys₁⋅ys₂ \n\n 2\n⋅ys₀⋅ys₁ \n─────────\n \n \n```\n:::\n:::\n\n\nWe can graphically see the result for the specific values of `xs` and `ys` as follows:\n\n::: {.cell hold='true' execution_count=30}\n\n::: {.cell-output .cell-output-display execution_count=31}\n{}\n:::\n:::\n\n\n## Questions\n\n\n###### Question\n\n\nDo the polynomials $p = x^4$ and $q = x^2 - 2$ intersect?\n\n::: {.cell hold='true' execution_count=31}\n\n::: {.cell-output .cell-output-display execution_count=32}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='4097296116917583197' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_4097296116917583197\">\n <div style=\"padding-top: 5px\">\n <div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_4097296116917583197_1\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_4097296116917583197\"\n id=\"radio_4097296116917583197_1\" value=\"1\">\n </input>\n <span class=\"label-body px-1\">\n Yes\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_4097296116917583197_2\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_4097296116917583197\"\n id=\"radio_4097296116917583197_2\" value=\"2\">\n </input>\n <span class=\"label-body px-1\">\n No\n </span>\n </label>\n</div>\n\n \n </div>\n </div>\n <div id='4097296116917583197_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.querySelectorAll('input[name=\"radio_4097296116917583197\"]').forEach(function(rb) {\nrb.addEventListener(\"change\", function() {\n var correct = rb.value == 2;\n var msgBox = document.getElementById('4097296116917583197_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_4097296116917583197\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_4097296116917583197\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n})});\n\n</script>\n```\n:::\n:::\n\n\n###### Question\n\n\nDo the polynomials $p = x^4-4$ and $q = x^2 - 2$ intersect?\n\n::: {.cell hold='true' execution_count=32}\n\n::: {.cell-output .cell-output-display execution_count=33}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='12533354764205883248' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_12533354764205883248\">\n <div style=\"padding-top: 5px\">\n <div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_12533354764205883248_1\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_12533354764205883248\"\n id=\"radio_12533354764205883248_1\" value=\"1\">\n </input>\n <span class=\"label-body px-1\">\n Yes\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_12533354764205883248_2\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_12533354764205883248\"\n id=\"radio_12533354764205883248_2\" value=\"2\">\n </input>\n <span class=\"label-body px-1\">\n No\n </span>\n </label>\n</div>\n\n \n </div>\n </div>\n <div id='12533354764205883248_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.querySelectorAll('input[name=\"radio_12533354764205883248\"]').forEach(function(rb) {\nrb.addEventListener(\"change\", function() {\n var correct = rb.value == 1;\n var msgBox = document.getElementById('12533354764205883248_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_12533354764205883248\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_12533354764205883248\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n})});\n\n</script>\n```\n:::\n:::\n\n\n###### Question\n\n\nHow many real roots does $p = 1 + x + x^2 + x^3 + x^4 + x^5$ have?\n\n::: {.cell hold='true' execution_count=33}\n\n::: {.cell-output .cell-output-display execution_count=34}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='13022392878996149725' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_13022392878996149725\">\n <div style=\"padding-top: 5px\">\n </br>\n<div class=\"input-group\">\n <input id=\"13022392878996149725\" type=\"number\" class=\"form-control\" placeholder=\"Numeric answer\">\n</div>\n\n \n </div>\n </div>\n <div id='13022392878996149725_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.getElementById(\"13022392878996149725\").addEventListener(\"change\", function() {\n var correct = (Math.abs(this.value - 1) <= 0);\n var msgBox = document.getElementById('13022392878996149725_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_13022392878996149725\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_13022392878996149725\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n});\n\n</script>\n```\n:::\n:::\n\n\n###### Question\n\n\nMathematically we say the $0$ polynomial has no degree. What convention does `Polynomials` use? (Look at `degree(zero(Polynomial))`.)\n\n::: {.cell hold='true' execution_count=34}\n\n::: {.cell-output .cell-output-display execution_count=35}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='5919373500149881922' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_5919373500149881922\">\n <div style=\"padding-top: 5px\">\n <div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_5919373500149881922_1\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_5919373500149881922\"\n id=\"radio_5919373500149881922_1\" value=\"1\">\n </input>\n <span class=\"label-body px-1\">\n <code>nothing</code>\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_5919373500149881922_2\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_5919373500149881922\"\n id=\"radio_5919373500149881922_2\" value=\"2\">\n </input>\n <span class=\"label-body px-1\">\n <code>-1</code>\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_5919373500149881922_3\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_5919373500149881922\"\n id=\"radio_5919373500149881922_3\" value=\"3\">\n </input>\n <span class=\"label-body px-1\">\n <code>0</code>\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_5919373500149881922_4\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_5919373500149881922\"\n id=\"radio_5919373500149881922_4\" value=\"4\">\n </input>\n <span class=\"label-body px-1\">\n <code>Inf</code>\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_5919373500149881922_5\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_5919373500149881922\"\n id=\"radio_5919373500149881922_5\" value=\"5\">\n </input>\n <span class=\"label-body px-1\">\n <code>-Inf</code>\n </span>\n </label>\n</div>\n\n \n </div>\n </div>\n <div id='5919373500149881922_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.querySelectorAll('input[name=\"radio_5919373500149881922\"]').forEach(function(rb) {\nrb.addEventListener(\"change\", function() {\n var correct = rb.value == 2;\n var msgBox = document.getElementById('5919373500149881922_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_5919373500149881922\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_5919373500149881922\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n})});\n\n</script>\n```\n:::\n:::\n\n\n###### Question\n\n\nConsider the polynomial $p(x) = a_1 x - a_3 x^3 + a_5 x^5$ where\n\n\n\n$$\n\\begin{align*}\na_1 &= 4(\\frac{3}{\\pi} - \\frac{9}{16}) \\\\\na_3 &= 2a_1 -\\frac{5}{2}\\\\\na_5 &= a_1 - \\frac{3}{2}.\n\\end{align*}\n$$\n\n\n * Form the polynomial `p` by first computing the $a$s and forming `p=Polynomial([0,a1,0,-a3,0,a5])`\n * Form the polynomial `q` by these commands `x=variable(); q=p(2x/pi)`\n\n\nThe polynomial `q`, a $5$th-degree polynomial, is a good approximation of for the [sine](http://www.coranac.com/2009/07/sines/) function.\n\n\nMake graphs of both `q` and `sin`. Over which interval is the approximation (visually) a good one?\n\n::: {.cell hold='true' execution_count=35}\n\n::: {.cell-output .cell-output-display execution_count=36}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='12847769603474659595' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_12847769603474659595\">\n <div style=\"padding-top: 5px\">\n <div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_12847769603474659595_1\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_12847769603474659595\"\n id=\"radio_12847769603474659595_1\" value=\"1\">\n </input>\n <span class=\"label-body px-1\">\n \\([0,1]\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_12847769603474659595_2\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_12847769603474659595\"\n id=\"radio_12847769603474659595_2\" value=\"2\">\n </input>\n <span class=\"label-body px-1\">\n \\([0,\\pi]\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_12847769603474659595_3\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_12847769603474659595\"\n id=\"radio_12847769603474659595_3\" value=\"3\">\n </input>\n <span class=\"label-body px-1\">\n \\([0,2\\pi]\\)\n </span>\n </label>\n</div>\n\n \n </div>\n </div>\n <div id='12847769603474659595_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.querySelectorAll('input[name=\"radio_12847769603474659595\"]').forEach(function(rb) {\nrb.addEventListener(\"change\", function() {\n var correct = rb.value == 1;\n var msgBox = document.getElementById('12847769603474659595_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_12847769603474659595\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_12847769603474659595\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n})});\n\n</script>\n```\n:::\n:::\n\n\n(This [blog post](https://www.nullhardware.com/blog/fixed-point-sine-and-cosine-for-embedded-systems/) shows how this approximation is valuable under some specific circumstances.)\n\n\n###### Question\n\n\nThe polynomial\n\n::: {.cell execution_count=36}\n``` {.julia .cell-code}\nfromroots([1,2,3,3,5])\n```\n\n::: {.cell-output .cell-output-display execution_count=37}\n```{=html}\n-90 + 213∙x - 184∙x<sup>2</sup> + 74∙x<sup>3</sup> - 14∙x<sup>4</sup> + x<sup>5</sup>\n```\n:::\n:::\n\n\nhas $5$ sign changes and $5$ real roots. For `x = variable()` use `div(p, x-3)` to find the result of dividing $p$ by $x-3$. How many sign changes are there in the new polynomial?\n\n::: {.cell hold='true' execution_count=37}\n\n::: {.cell-output .cell-output-display execution_count=38}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='13981049973965617249' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_13981049973965617249\">\n <div style=\"padding-top: 5px\">\n </br>\n<div class=\"input-group\">\n <input id=\"13981049973965617249\" type=\"number\" class=\"form-control\" placeholder=\"Numeric answer\">\n</div>\n\n \n </div>\n </div>\n <div id='13981049973965617249_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.getElementById(\"13981049973965617249\").addEventListener(\"change\", function() {\n var correct = (Math.abs(this.value - 4) <= 0);\n var msgBox = document.getElementById('13981049973965617249_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_13981049973965617249\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_13981049973965617249\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n});\n\n</script>\n```\n:::\n:::\n\n\n###### Question\n\n\nThe identification of a collection of coefficients with a polynomial depends on an understood **basis**. A basis for the polynomials of degree $n$ or less, consists of a minimal collection of polynomials for which all the polynomials of degree $n$ 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 $n+$ polynomials $1`, `x`, `x^2, \\dots, x^n$. However, though every basis must have $n+1$ members, they need not be these.\n\n\nA basis used by [Lagrange](https://en.wikipedia.org/wiki/Lagrange_polynomial) is the following. Let there be $n+1$ points distinct points $x_0, x_1, \\dots, x_n$. For each $i$ in $0$ to $n$ define\n\n\n\n$$\nl_i(x) = \\prod_{0 \\leq j \\leq n; j \\ne i} \\frac{x-x_j}{x_i - x_j} =\n\\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)}.\n$$\n\n\nThat is $l_i(x)$ is a product of terms like $(x-x_j)/(x_i-x_j)$ *except* when $j=i$.\n\n\nWhat is is the value of $l_0(x_0)$?\n\n::: {.cell hold='true' execution_count=38}\n\n::: {.cell-output .cell-output-display execution_count=39}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='13670772177198330103' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_13670772177198330103\">\n <div style=\"padding-top: 5px\">\n </br>\n<div class=\"input-group\">\n <input id=\"13670772177198330103\" type=\"number\" class=\"form-control\" placeholder=\"Numeric answer\">\n</div>\n\n \n </div>\n </div>\n <div id='13670772177198330103_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.getElementById(\"13670772177198330103\").addEventListener(\"change\", function() {\n var correct = (Math.abs(this.value - 1) <= 0);\n var msgBox = document.getElementById('13670772177198330103_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_13670772177198330103\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_13670772177198330103\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n});\n\n</script>\n```\n:::\n:::\n\n\nWhy?\n\n::: {.cell hold='true' execution_count=39}\n\n::: {.cell-output .cell-output-display execution_count=40}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='10488258305547777757' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_10488258305547777757\">\n <div style=\"padding-top: 5px\">\n <div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_10488258305547777757_1\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_10488258305547777757\"\n id=\"radio_10488258305547777757_1\" value=\"1\">\n </input>\n <span class=\"label-body px-1\">\n 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\\).\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_10488258305547777757_2\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_10488258305547777757\"\n id=\"radio_10488258305547777757_2\" value=\"2\">\n </input>\n <span class=\"label-body px-1\">\n The term \\((x_0-x_0)\\) will be \\(0\\), so the product will be zero\n </span>\n </label>\n</div>\n\n \n </div>\n </div>\n <div id='10488258305547777757_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.querySelectorAll('input[name=\"radio_10488258305547777757\"]').forEach(function(rb) {\nrb.addEventListener(\"change\", function() {\n var correct = rb.value == 1;\n var msgBox = document.getElementById('10488258305547777757_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_10488258305547777757\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_10488258305547777757\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n})});\n\n</script>\n```\n:::\n:::\n\n\nWhat is the value of $l_i(x_i)$?\n\n::: {.cell hold='true' execution_count=40}\n\n::: {.cell-output .cell-output-display execution_count=41}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='465391815469923932' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_465391815469923932\">\n <div style=\"padding-top: 5px\">\n </br>\n<div class=\"input-group\">\n <input id=\"465391815469923932\" type=\"number\" class=\"form-control\" placeholder=\"Numeric answer\">\n</div>\n\n \n </div>\n </div>\n <div id='465391815469923932_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.getElementById(\"465391815469923932\").addEventListener(\"change\", function() {\n var correct = (Math.abs(this.value - 1) <= 0);\n var msgBox = document.getElementById('465391815469923932_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_465391815469923932\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_465391815469923932\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n});\n\n</script>\n```\n:::\n:::\n\n\nWhat is the value of $l_0(x_1)$?\n\n::: {.cell hold='true' execution_count=41}\n\n::: {.cell-output .cell-output-display execution_count=42}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='16146351592704184351' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_16146351592704184351\">\n <div style=\"padding-top: 5px\">\n </br>\n<div class=\"input-group\">\n <input id=\"16146351592704184351\" type=\"number\" class=\"form-control\" placeholder=\"Numeric answer\">\n</div>\n\n \n </div>\n </div>\n <div id='16146351592704184351_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.getElementById(\"16146351592704184351\").addEventListener(\"change\", function() {\n var correct = (Math.abs(this.value - 0) <= 0);\n var msgBox = document.getElementById('16146351592704184351_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_16146351592704184351\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_16146351592704184351\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n});\n\n</script>\n```\n:::\n:::\n\n\nWhy?\n\n::: {.cell hold='true' execution_count=42}\n\n::: {.cell-output .cell-output-display execution_count=43}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='3728242699583194034' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_3728242699583194034\">\n <div style=\"padding-top: 5px\">\n <div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_3728242699583194034_1\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_3728242699583194034\"\n id=\"radio_3728242699583194034_1\" value=\"1\">\n </input>\n <span class=\"label-body px-1\">\n The term \\((x-x_1)/(x_0-x_1)\\) is omitted from the product, so the answer is non-zero.\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_3728242699583194034_2\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_3728242699583194034\"\n id=\"radio_3728242699583194034_2\" value=\"2\">\n </input>\n <span class=\"label-body px-1\">\n The term like \\((x-x_1)/(x_0 - x_1)\\) will be \\(0\\) when \\(x=x_1\\) and so the product will be \\(0\\).\n </span>\n </label>\n</div>\n\n \n </div>\n </div>\n <div id='3728242699583194034_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.querySelectorAll('input[name=\"radio_3728242699583194034\"]').forEach(function(rb) {\nrb.addEventListener(\"change\", function() {\n var correct = rb.value == 2;\n var msgBox = document.getElementById('3728242699583194034_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_3728242699583194034\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_3728242699583194034\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n})});\n\n</script>\n```\n:::\n:::\n\n\nWhat is the value of $l_i(x_j)$ *if* $i \\ne j$?\n\n::: {.cell hold='true' execution_count=43}\n\n::: {.cell-output .cell-output-display execution_count=44}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='5404360744551166210' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_5404360744551166210\">\n <div style=\"padding-top: 5px\">\n </br>\n<div class=\"input-group\">\n <input id=\"5404360744551166210\" type=\"number\" class=\"form-control\" placeholder=\"Numeric answer\">\n</div>\n\n \n </div>\n </div>\n <div id='5404360744551166210_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.getElementById(\"5404360744551166210\").addEventListener(\"change\", function() {\n var correct = (Math.abs(this.value - 0) <= 0);\n var msgBox = document.getElementById('5404360744551166210_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_5404360744551166210\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_5404360744551166210\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n});\n\n</script>\n```\n:::\n:::\n\n\nSuppose the $x_0, x_1, \\dots, x_n$ are the $x$ coordinates of $n$ distinct points $(x_0,y_0)$, $(x_1, y_1), \\dots, (x_n,y_n).$ Form the polynomial with the above basis and coefficients being the $y$ values. That is consider:\n\n\n\n$$\np(x) = \\sum_{i=0}^n y_i l_i(x) = y_0l_0(x) + y_1l_1(x) + \\dots + y_nl_n(x)\n$$\n\n\nWhat is the value of $p(x_j)$?\n\n::: {.cell hold='true' execution_count=44}\n\n::: {.cell-output .cell-output-display execution_count=45}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='12911860293389297308' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_12911860293389297308\">\n <div style=\"padding-top: 5px\">\n <div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_12911860293389297308_1\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_12911860293389297308\"\n id=\"radio_12911860293389297308_1\" value=\"1\">\n </input>\n <span class=\"label-body px-1\">\n \\(0\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_12911860293389297308_2\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_12911860293389297308\"\n id=\"radio_12911860293389297308_2\" value=\"2\">\n </input>\n <span class=\"label-body px-1\">\n \\(1\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_12911860293389297308_3\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_12911860293389297308\"\n id=\"radio_12911860293389297308_3\" value=\"3\">\n </input>\n <span class=\"label-body px-1\">\n \\(y_j\\)\n </span>\n </label>\n</div>\n\n \n </div>\n </div>\n <div id='12911860293389297308_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.querySelectorAll('input[name=\"radio_12911860293389297308\"]').forEach(function(rb) {\nrb.addEventListener(\"change\", function() {\n var correct = rb.value == 3;\n var msgBox = document.getElementById('12911860293389297308_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_12911860293389297308\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_12911860293389297308\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n})});\n\n</script>\n```\n:::\n:::\n\n\nThis last answer is why $p$ is called an *interpolating* polynomial and this question shows an alternative way to identify interpolating polynomials from solving a system of linear equations.\n\n\n###### Question\n\n\nThe Chebyshev ($T$) polynomials are polynomials which use a different basis from the standard basis. Denote the basis elements $T_0$, $T_1$, ... where we have $T_0(x) = 1$, $T_1(x) = x$, and for bigger indices $T_{i+1}(x) = 2xT_i(x) - T_{i-1}(x)$. The first others are then:\n\n\n\n$$\n\\begin{align*}\nT_2(x) &= 2xT_1(x) - T_0(x) = 2x^2 - 1\\\\\nT_3(x) &= 2xT_2(x) - T_1(x) = 2x(2x^2-1) - x = 4x^3 - 3x\\\\\nT_4(x) &= 2xT_3(x) - T_2(x) = 2x(4x^3-3x) - (2x^2-1) = 8x^4 - 8x^2 + 1\n\\end{align*}\n$$\n\n\nWith these definitions what is the polynomial associated to the coefficients $[0,1,2,3]$ with this basis?\n\n::: {.cell hold='true' execution_count=45}\n\n::: {.cell-output .cell-output-display execution_count=46}\n```{=html}\n<form class=\"mx-2 my-3 mw-100\" name='WeaveQuestion' data-id='2912488806934549104' data-controltype=''>\n <div class='form-group '>\n <div class='controls'>\n <div class=\"form\" id=\"controls_2912488806934549104\">\n <div style=\"padding-top: 5px\">\n <div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_2912488806934549104_1\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_2912488806934549104\"\n id=\"radio_2912488806934549104_1\" value=\"1\">\n </input>\n <span class=\"label-body px-1\">\n It is \\(0\\cdot 1 + 1 \\cdot x + 2 \\cdots x^2 + 3\\cdot x^3 = x + 2x^2 + 3x^3\\)\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_2912488806934549104_2\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_2912488806934549104\"\n id=\"radio_2912488806934549104_2\" value=\"2\">\n </input>\n <span class=\"label-body px-1\">\n It is \\(0\\cdot T_1(x) +\t1\\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\\)`\n </span>\n </label>\n</div>\n<div class=\"form-check\">\n <label class=\"form-check-label\" for=\"radio_2912488806934549104_3\">\n <input class=\"form-check-input\" type=\"radio\" name=\"radio_2912488806934549104\"\n id=\"radio_2912488806934549104_3\" value=\"3\">\n </input>\n <span class=\"label-body px-1\">\n It is \\(0\\cdot T_1(x) +\t1\\cdot T_1(x) + 2\\cdot T_2(x) + 3\\cdot T_3(x) = 0\\)\n </span>\n </label>\n</div>\n\n \n </div>\n </div>\n <div id='2912488806934549104_message' style=\"padding-bottom: 15px\"></div>\n </div>\n </div>\n</form>\n\n<script text='text/javascript'>\ndocument.querySelectorAll('input[name=\"radio_2912488806934549104\"]').forEach(function(rb) {\nrb.addEventListener(\"change\", function() {\n var correct = rb.value == 2;\n var msgBox = document.getElementById('2912488806934549104_message');\n if(correct) {\n msgBox.innerHTML = \"<div class='pluto-output admonition note alert alert-success'><span> 👍 Correct </span></div>\";\n var explanation = document.getElementById(\"explanation_2912488806934549104\")\n if (explanation != null) {\n explanation.style.display = \"none\";\n }\n } else {\n msgBox.innerHTML = \"<div class='pluto-output admonition alert alert-danger'><span>👎 Incorrect </span></div>\";\n var explanation = document.getElementById(\"explanation_2912488806934549104\")\n if (explanation != null) {\n explanation.style.display = \"block\";\n }\n }\n\n})});\n\n</script>\n```\n:::\n:::\n\n\n:::{.callout-note}\n## Note\nThe `Polynomials` package has an implementation, so you can check your answer through `convert(Polynomial, ChebyshevT([0,1,2,3]))`. Similarly, the `SpecialPolynomials` package has these and many other polynomial bases represented.\n\nThe `ApproxFun` 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 `ApproxFun` 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.\n\n:::\n\n",
|
||
"supporting": [
|
||
"polynomials_package_files"
|
||
],
|
||
"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"
|
||
]
|
||
}
|
||
}
|
||
} |