{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "47708bfa",
            "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": "448da3ad",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy.special import eval_legendre",
            "outputs": []
        },
        {
            "id": "1723b22f",
            "cell_type": "markdown",
            "source": "Evaluate the zero-order Legendre polynomial at x = 0\n",
            "metadata": {}
        },
        {
            "id": "41ebfac2",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "eval_legendre(0, 0)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "1.0"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "39f4c749",
            "cell_type": "markdown",
            "source": "Evaluate the first-order Legendre polynomial between -1 and 1\n",
            "metadata": {}
        },
        {
            "id": "3289fede",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "X = np.linspace(-1, 1, 5)  # Domain of Legendre polynomials\neval_legendre(1, X)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([-1. , -0.5,  0. ,  0.5,  1. ])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "a5e26570",
            "cell_type": "markdown",
            "source": "Evaluate Legendre polynomials of order 0 through 4 at x = 0\n",
            "metadata": {}
        },
        {
            "id": "79d07f31",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "N = range(0, 5)\neval_legendre(N, 0)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([ 1.   ,  0.   , -0.5  ,  0.   ,  0.375])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "f42e954c",
            "cell_type": "markdown",
            "source": "Plot Legendre polynomials of order 0 through 4\n",
            "metadata": {}
        },
        {
            "id": "5ad044fe",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "X = np.linspace(-1, 1)",
            "outputs": []
        },
        {
            "id": "81282e50",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import matplotlib.pyplot as plt\nfor n in range(0, 5):\n    y = eval_legendre(n, X)\n    plt.plot(X, y, label=r'$P_{}(x)$'.format(n))",
            "outputs": []
        },
        {
            "id": "18ad6f6f",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "plt.title(\"Legendre Polynomials\")\nplt.xlabel(\"x\")\nplt.ylabel(r'$P_n(x)$')\nplt.legend(loc='lower right')\nplt.show()",
            "outputs": []
        }
    ]
}