{
"nbformat_minor": 2,
"nbformat": 4,
"cells": [
{
"source": [
"$$\n",
"\\def\\CC{\\bf C}\n",
"\\def\\QQ{\\bf Q}\n",
"\\def\\RR{\\bf R}\n",
"\\def\\ZZ{\\bf Z}\n",
"\\def\\NN{\\bf N}\n",
"$$\n",
"# Draw Polynomial Roots\n",
"\n",
"Authors \n",
"- Thierry Monteil\n",
"\n",
"License \n",
"CC BY-SA 3.0\n",
"\n",
"## Questions\n",
"\n",
"Plot the complex roots of all polynomials of degree 13 with coefficients in $\\{-1, 1\\}$.\n",
"\n",
"Play around this idea: change the allowed coefficients, change the degree, make animations, supperpose pictures, add colors, ...\n",
"\n",
"## Hints\n",
"\n",
"### Polynomials\n",
"\n",
"To be fast, we will represent the complex numbers as floating-point numbers, so we will use `CDF`. To create the polynomial ring with complex coefficients and with indeterminate `x`, namely $\\mathbb{C}[x]$, we can do:"
],
"cell_type": "markdown",
"metadata": {}
},
{
"execution_count": null,
"cell_type": "code",
"source": [
"R = PolynomialRing(CDF, 'x') ; R"
],
"outputs": [],
"metadata": {}
},
{
"source": [
"Or more in a more compact way (but it is equivalent):"
],
"cell_type": "markdown",
"metadata": {}
},
{
"execution_count": null,
"cell_type": "code",
"source": [
"R = CDF['x']"
],
"outputs": [],
"metadata": {}
},
{
"source": [
"If `L` is a list and `R` a polynomial ring, you can use its entries as the coefficients of an element of `R` by calling `R(L)` :"
],
"cell_type": "markdown",
"metadata": {}
},
{
"execution_count": null,
"cell_type": "code",
"source": [
"L = [1, 2, 3, 4]\n",
"P = R(L)\n",
"P"
],
"outputs": [],
"metadata": {}
},
{
"source": [
"You can get the list of its roots (without multiplicities) as follows:"
],
"cell_type": "markdown",
"metadata": {}
},
{
"execution_count": null,
"cell_type": "code",
"source": [
"P.roots(multiplicities=False)"
],
"outputs": [],
"metadata": {}
},
{
"source": [
"### Products of iterables\n",
"\n",
"To make the product of an iterable `L` (typically a tuple, a list or a set) with itself `k` times, you can do:"
],
"cell_type": "markdown",
"metadata": {}
},
{
"execution_count": null,
"cell_type": "code",
"source": [
"from itertools import product\n",
"L = ['a', 'b']\n",
"k = 3\n",
"product(L, repeat=k)"
],
"outputs": [],
"metadata": {}
},
{
"execution_count": null,
"cell_type": "code",
"source": [
"list(_)"
],
"outputs": [],
"metadata": {}
},
{
"source": [
"### Plot and animate\n",
"\n",
"To plot a list of points, you can use the `points()` function. If you want each point to be a single pixel (not a larger ball), you can use the `size=1` option. You can have a look at the doc for further options.\n",
"\n",
"To learn more about plotting, you can have a look at ([sagenb live](/doc/live/prep/Advanced-2DPlotting.html) / [jupyter live](/kernelspecs/sagemath/doc/prep/Advanced-2DPlotting.html))\n",
"\n",
"To get some animation examples, you can look at the doc and the source code of the `sage.plot.animate` module. Please note that animations do not work yet on jupyter notebook.\n",
"\n",
"Note that the `plot` objects can be added with eachother, leadind to a superposition of the plots."
],
"cell_type": "markdown",
"metadata": {}
},
{
"execution_count": null,
"cell_type": "code",
"source": [
"# edit here"
],
"outputs": [],
"metadata": {}
}
],
"metadata": {
"kernelspec": {
"display_name": "sagemath",
"name": "sagemath"
}
}
}