{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "376fcc96",
            "cell_type": "markdown",
            "source": "<div class='alert alert-warning'>\n\nSciPy's interactive examples with Jupyterlite are experimental and may not always work as expected. Execution of cells containing imports may result in large downloads (up to 60MB of content for the first import from SciPy). Load times when importing from SciPy may take roughly 10-20 seconds. If you notice any problems, feel free to open an [issue](https://github.com/scipy/scipy/issues/new/choose).\n\n</div>",
            "metadata": {}
        },
        {
            "id": "aba3af4f",
            "cell_type": "markdown",
            "source": "Chebyshev polynomials of the second kind of order $n$ can\nbe obtained as the determinant of specific $n \\times n$\nmatrices. As an example we can check how the points obtained from\nthe determinant of the following $3 \\times 3$ matrix\nlay exactly on $U_3$:\n",
            "metadata": {}
        },
        {
            "id": "5e5fe1bf",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.linalg import det\nfrom scipy.special import chebyu\nx = np.arange(-1.0, 1.0, 0.01)\nfig, ax = plt.subplots()\nax.set_ylim(-2.0, 2.0)\nax.set_title(r'Chebyshev polynomial $U_3$')\nax.plot(x, chebyu(3)(x), label=rf'$U_3$')\nfor p in np.arange(-1.0, 1.0, 0.1):\n    ax.plot(p,\n            det(np.array([[2*p, 1, 0], [1, 2*p, 1], [0, 1, 2*p]])),\n            'rx')\nplt.legend(loc='best')\nplt.show()",
            "outputs": []
        },
        {
            "id": "94c19b34",
            "cell_type": "markdown",
            "source": "They satisfy the recurrence relation:\n\n$$ U_{2n-1}(x) = 2 T_n(x)U_{n-1}(x) $$\nwhere the $T_n$ are the Chebyshev polynomial of the first kind.\nLet's verify it for $n = 2$:\n",
            "metadata": {}
        },
        {
            "id": "97468012",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.special import chebyt\nx = np.arange(-1.0, 1.0, 0.01)\nnp.allclose(chebyu(3)(x), 2 * chebyt(2)(x) * chebyu(1)(x))",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "True"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "0e123080",
            "cell_type": "markdown",
            "source": "We can plot the Chebyshev polynomials $U_n$ for some values\nof $n$:\n",
            "metadata": {}
        },
        {
            "id": "e799948f",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "x = np.arange(-1.0, 1.0, 0.01)\nfig, ax = plt.subplots()\nax.set_ylim(-1.5, 1.5)\nax.set_title(r'Chebyshev polynomials $U_n$')\nfor n in np.arange(1,5):\n    ax.plot(x, chebyu(n)(x), label=rf'$U_n={n}$')\nplt.legend(loc='best')\nplt.show()",
            "outputs": []
        }
    ]
}