Created
December 14, 2024 18:23
-
-
Save MacaylaMarvelous81/77d80d6ae5fcdd3fda1b5e2f729514b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import marimo | |
__generated_with = "0.10.1" | |
app = marimo.App(width="medium") | |
@app.cell(hide_code=True) | |
def _(): | |
import marimo as mo | |
import numpy as np | |
import matplotlib.pyplot as plt | |
return mo, np, plt | |
@app.cell(hide_code=True) | |
def _(mo): | |
mo.md( | |
r""" | |
### Rational Zeroes Theorem | |
The rational zeroes theorem can be used to find _rational_ numbers that could be roots of the polynomial. Methods like synthetic | |
substitution can be used to find out which ones are actually roots. | |
#### Example | |
Consider the polynomial $6x^3+11x^2-3x-2$, graphed below. | |
""" | |
) | |
return | |
@app.cell | |
def _(np, plt): | |
_fig, _ax = plt.subplots() | |
_x = np.linspace(-3, 2, 400) | |
_y = 6*_x**3 + 11*_x**2 - 3*_x - 2 | |
_ax.plot(_x, _y) | |
_ax.set_ylim(_y.min(), _y.max()) | |
_ax.spines['left'].set_position('zero') | |
_ax.spines['bottom'].set_position('zero') | |
_ax.spines['right'].set_color('none') | |
_ax.spines['top'].set_color('none') | |
_ax | |
return | |
@app.cell(hide_code=True) | |
def _(mo): | |
mo.md( | |
r""" | |
1. Find the factors of the leading coefficient ($6$ from $6x^3$) and the constant ($-2$). | |
In this example, the factors of $6$ are $\pm\{1,2,3,6\}$. The factors of $-2$ are $\pm\{1,2\}$. | |
2. The factors of the constant over the factors of the leading coefficient are the possible rational zeoes. | |
The possible rational zeroes of this polynomial are $\pm\{1,2,\frac{1}{2},\frac{1}{3},\frac{2}{3},\frac{1}{6}\}$. | |
3. Test the possible rational zeroes to find which ones really factor. Synthetic substitution is a quick way to do this. | |
""" | |
) | |
return | |
@app.cell(hide_code=True) | |
def _(mo): | |
mo.accordion({ | |
"Synthetic substitution": ( | |
r""" | |
| | 6 | 11 | -3 | -2 | | |
| -- | - | -- | -- | -- | | |
| 1 | 6 | 16 | 13 | 11 | | |
| 2 | 6 | 23 | 43 | 84 | | |
| -1 | 6 | 5 | -8 | 6 | | |
| -2 | 6 | -1 | -1 | 0 | | |
Any numbers which have a remainder of 0 (the last column) are roots. In the example not all of the possible zeroes were tested; | |
testing was stopped after finding -2 as a root. You could continue testing zeroes to find more roots. | |
""" | |
) | |
}) | |
return | |
@app.cell(hide_code=True) | |
def _(mo): | |
mo.md( | |
r""" | |
4. Once you know a root, you can factor it out of the polynomial to find out the rest of the roots, real or not. | |
The root -2 factored out of the cubic looks like $(x+2)(6x^2-x-1)$. $6x^2-x-1$ is a quadratic with the roots $\frac{1}{2}$ and $-\frac{1}{3}$. The roots of the polynomial are $-2$, $-\frac{1}{3}$, and $\frac{1}{2}$. | |
""" | |
) | |
return | |
@app.cell(hide_code=True) | |
def _(mo): | |
mo.md( | |
r""" | |
Since the roots of this polynomial are all real, all of the roots were part of the possible rational zeroes and could be found with | |
synthetic substitution. Factoring roots out of the polynomial could help find roots which are imaginary. | |
""" | |
).callout() | |
return | |
@app.cell(hide_code=True) | |
def _(mo): | |
mo.md( | |
r""" | |
#### Practice | |
Determine the roots of $6x^3-23x^2-33x-10$ real or otherwise. | |
""" | |
) | |
return | |
@app.cell(hide_code=True) | |
def _(mo): | |
mo.accordion( | |
{ | |
"Step 1": r""" | |
Find the factors of the constant and the leading coefficient. | |
The factors of $-10$ are $\pm\{1,2,5,10\}$. The factors of $6$ are $\pm\{1,2,3,6\}$. | |
""", | |
"Step 2": r""" | |
Determine the possible rational zeroes by putting the factors of the constant over the factors of the leading coefficient. | |
The possible rational zeroes are $\pm\{1,2,5,10,\frac{1}{2},\frac{5}{2},\frac{1}{3},\frac{2}{3},\frac{5}{3},\frac{10}{3},\frac{1}{6},\frac{5}{6}\}$. | |
""", | |
"Step 3": r""" | |
Find a root by testing the possible rational zeroes. A quick way of doing this is synthetic substitution. | |
| | 6 | -23 | -33 | -10 | | |
| -------------- | - | --- | --- | --- | | |
| 1 | 6 | -17 | -50 | -60 | | |
| -1 | 6 | -29 | -4 | -6 | | |
| -2 | 6 | -35 | 70 | | | |
| $-\frac{1}{2}$ | 6 | -26 | -20 | 0 | | |
In this example $-\frac{1}{2}$ was found as a root. Some of the other possible rational zeroes are roots, however, so you may | |
get a different number depending on what you try. | |
""", | |
"Step 4": r""" | |
Factor out the root that was found. Since $-\frac{1}{2}$ was found in the example, it would look like this when factored out: | |
$$(6x^2-26x-20)(x+\frac{1}{2})$$ | |
Then continue factoring: | |
$$(6x+4)(x-5)(x+\frac{1}{2})$$ | |
""", | |
"Solution": r""" | |
Solve the factors for $x$ to get the roots. | |
The roots are $-\frac{2}{3}$, $5$, and $-\frac{1}{2}$. | |
""" | |
} | |
) | |
return | |
@app.cell | |
def _(mo): | |
mo.md( | |
r""" | |
### Polynomial Attributes | |
Just by looking at the equation, what can you tell about the polynomial $3x^3-18x^2-2x+12$? | |
1. The amplitude (leading coefficient) is positive, so the right side of the polynomial will go up. In other words, as $x\to\infin$, | |
$f(x)\to\infin$. | |
2. The polynomial is to the 3rd degree, which is an odd degree. This means the polynomial will go off in opposite directions, so as $x\to-\infin$ $f(x)\to-\infin$. | |
3. The polynomial is to the 3rd degree, so it will have 3 'segments'. | |
""" | |
) | |
return | |
@app.cell | |
def _(mo): | |
showgraph1 = mo.ui.switch(label='show graph') | |
showgraph1 | |
return (showgraph1,) | |
@app.cell | |
def _(np, plt, showgraph1): | |
_fig, _ax = plt.subplots() | |
_x = np.linspace(-5, 8, 400) | |
_y = 3*_x**3 - 18*_x**2 - 2*_x + 12 | |
_ax.plot(_x, _y) | |
_ax.set_ylim(_y.min(), _y.max()) | |
_ax.spines['left'].set_position('zero') | |
_ax.spines['bottom'].set_position('zero') | |
_ax.spines['right'].set_color('none') | |
_ax.spines['top'].set_color('none') | |
#_ax.fill_between(_x[_x < -(np.sqrt(2/3))], _y.min(), _y.max(), alpha=0.5) | |
#_ax.fill_between(_x[(_x > -(np.sqrt(2/3))) & (_x < np.sqrt(2/3))], _y.min(), _y.max(), alpha=0.5) | |
#_ax.fill_between(np.where(-(np.sqrt(2/3)) < _x < np.sqrt(2/3), _x, np.sqrt(2/3)), _y.min(), _y.max(), alpha=0.5, color='r') | |
_ax if showgraph1.value else None | |
return | |
@app.cell | |
def _(mo): | |
mo.md( | |
r""" | |
Given a polynomial with roots at $2-i$, $2$, and $-3$, with $-3$ having a multiplicity of 2, we can tell: | |
1. The polynomial also has a root at $2+i$, because it is the complex conjugate of $2-i$. | |
2. The polynomial has 2 x-intercepts, because 2 of the roots are real ($2$ and $-3$) | |
3. The polynomial cuts through $(2, 0)$ because 2 is a root with an odd multiplicity (1). | |
4. The polynomial bounces from $(-3, 0)$ because -3 is a root with an even multiplicity (2). | |
With the roots we know, we know that the polynomial must have the factors: | |
- $(x-(2-i))$, for the root $2-i$ | |
- $(x-(2+i))$, for the root $2+i$ | |
- $(x-2)$, for the root $2$ | |
- $(x+3)$, for the root $-3$ | |
- $(x+3)$ again, because the root $-3$ has a multiplicity of 2. | |
Since we know the polynomial must have at least these 5 factors, we know the polynomial must be at least a 5th degree polynomial, | |
though it is possible for the polynomial to be a higher degree polynomial. We can write a polynomial of least degree by writing these | |
factors to be in factored form. | |
$$f(x)=(x-(2-i))(x-(2+i))(x-2)(x+3)(x+3)$$ | |
When expanded, we get the equation $x^5-14x^3+14x^2+57x-90$. | |
""" | |
) | |
return | |
@app.cell | |
def _(mo): | |
showgraph2 = mo.ui.switch(label='show graphs') | |
showgraph2 | |
return (showgraph2,) | |
@app.cell | |
def _(np, plt, showgraph2): | |
_fig, _ax = plt.subplots() | |
_x = np.linspace(-4, 3, 400) | |
_y = _x**5-14*_x**3+14*_x**2+57*_x-90 | |
_ax.plot(_x, _y) | |
_ax.set_ylim(_y.min(), _y.max()) | |
_ax.spines['left'].set_position('zero') | |
_ax.spines['bottom'].set_position('zero') | |
_ax.spines['right'].set_color('none') | |
_ax.spines['top'].set_color('none') | |
_ax.set_title('$x^5-14x^3+14x^2+57x-90$') | |
_ax if showgraph2.value else None | |
return | |
@app.cell | |
def _(mo, showgraph2): | |
mo.md(r"""This is not the only polynomial that contains these roots. For example, this is a similar polynomial that has an amplitude of -3.""") if showgraph2.value else None | |
return | |
@app.cell | |
def _(np, plt, showgraph2): | |
_fig, _ax = plt.subplots() | |
_x = np.linspace(-4, 3, 400) | |
_y = -3*_x**5+42*_x**3-42*_x**2-171*_x+270 | |
_ax.plot(_x, _y) | |
_ax.set_ylim(_y.min(), _y.max()) | |
_ax.spines['left'].set_position('zero') | |
_ax.spines['bottom'].set_position('zero') | |
_ax.spines['right'].set_color('none') | |
_ax.spines['top'].set_color('none') | |
_ax.set_title(r'$-3x^5+42x^3-42x^2-171x+270$') | |
_ax if showgraph2.value else None | |
return | |
@app.cell | |
def _(mo): | |
mo.md( | |
r""" | |
### Binomial Expansion by Pascal's Triangle | |
Binomials raised to a constant power can be expanded with the help of Pascal's Triangle. The triangle can be constructed by starting at | |
1 and then adding the two numbers above and to the left and right for subsequent layers. | |
""" | |
) | |
return | |
@app.cell | |
def _(mo): | |
mo.image('/app/notebooks/img/pascals-triangle.png') | |
return | |
@app.cell | |
def _(mo): | |
mo.md( | |
r""" | |
First, get the layer of the triangle corresponding to the power the binomial is raised to. The number of the exponent should be the | |
second number of the player. For example, when expanding $(3-2b)^5$, look for the layer with `1 5 10 10 5 1` because the binomial is | |
being raised to the 5th power. | |
""" | |
) | |
return | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment