{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "FEUILLE DE TP 5\n",
    "\n",
    "---\n",
    "# Polynôme interpolateur de Lagrange (Partie 2)\n",
    "---"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "%config InlineBackend.figure_format = 'retina'\n",
    "\n",
    "import matplotlib.pyplot as plt  # librairie graphique\n",
    "import numpy as np  # pour les numpy array"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Nous rappelons le résultat d'existence et d'unicité vu en cours\n",
    "\n",
    "> **(Polynôme interpolateur de Lagrange)**<br>\n",
    "> Etant donnés $N$ un entier strictement positif, $x_1,\\ldots,x_N$ des réels deux à deux distincts et $y_1,\\ldots,y_N$ des réels, il existe un unique polynôme $P$ qui vérifie\n",
    "> $$ P\\in\\mathbb{R}_{N-1}[X], \\qquad P(x_i)=y_i, \\quad 1\\leq i\\leq N.$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Construction en utilisant la base duale des polynômes de Lagrange\n",
    "\n",
    "Nous rappelons que les polynômes de Lagrange associés aux points $x_1,\\ldots,x_N$ sont définis par\n",
    "$$\n",
    "L_i = \\prod_{j\\neq i} \\frac{X-x_j}{x_i-x_j}, \\qquad 1\\leq i\\leq N.\n",
    "$$\n",
    "Le polynôme interpolateur de Lagrange s'exprime alors dans la base des polynômes de Lagrange \n",
    "$$\n",
    "P = \\sum_{i=1}^N y_i L_i.\n",
    "$$\n",
    "\n",
    "**Question**\n",
    "\n",
    "> Proposez une fonction `interp_Lagrange` qui\n",
    "> * prend en argument deux `ndarray` `x` et `y` de taille `N` et un `ndarray` `xx` de taille `M` ;\n",
    "> * retourne l'évaluation du polynôme interpolateur aux points du vecteur `xx` en utilisant la décomposition dans la base des polynômes de Lagrange.\n",
    "> Testez votre nouvelle fonction en reprenant le test fait avec la méthode de Vandermonde."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "def interp_Lagrange(x, y, xx):\n",
    "    N = len(x)\n",
    "    M = len(xx)\n",
    "    L = np.ones((M, N))\n",
    "\n",
    "    for i in range(N):\n",
    "        for j in range(N):\n",
    "            if i != j:\n",
    "                L[:, i] *= (xx - x[j]) / (x[i] - x[j])\n",
    "    return L.dot(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x7fe342378850>]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 65624 characters]\n",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {
      "image/png": {
       "height": 416,
       "width": 559
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "N = 5\n",
    "x = np.linspace(0, 1, 5)\n",
    "y = np.random.rand(N)\n",
    "xx = np.linspace(0, 1, 200)\n",
    "\n",
    "plt.scatter(x, y)\n",
    "plt.plot(xx, interp_Lagrange(x, y, xx))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Le choix des points d'interpolation\n",
    "\n",
    "Etant donné un intervalle $[a, b]$, nous rappelons la définition des familles de points classiques pour l'interpolation :\n",
    "* les points équi-répartis\n",
    "$$ x_{i, N} = a + (b-a) \\frac{i-1}{N-1}, \\qquad 1\\leq i\\leq N,$$\n",
    "* les points de Tchebychev\n",
    "$$ x_{i, N} = \\frac{a+b}{2} + \\frac{b-a}{2} \\cos \\Bigl( \\frac{2i-1}{2N}\\pi \\Bigr), \\qquad 1\\leq i\\leq N,$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Question 1**\n",
    "\n",
    "> 1. Proposez une fonction `equirepartis(a, b, N)` qui prend en arguments 2 réels, les valeurs des bornes de l'intervalle $a$ et $b$ et 1 entier $N$ et qui retourne la famille des $N$ points équi-répartis entre $a$ et $b$.\n",
    "> 2. Proposez une fonction `tchebychev(a, b, N)` qui prend en arguments 2 réels, les valeurs des bornes de l'intervalle $a$ et $b$ et 1 entier $N$ et qui retourne la famille des $N$ points de Tchebychev entre $a$ et $b$. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "def equirepartis(a, b, N):\n",
    "    return np.array([a + (b - a) * (i - 1) / (N - 1) for i in range(1, N + 1)])\n",
    "\n",
    "\n",
    "def tchebychev(a, b, N):\n",
    "    return np.array(\n",
    "        [\n",
    "            (a + b) / 2 + (b - a) / 2 * np.cos((2 * i - 1) / (2 * N) * np.pi)\n",
    "            for i in range(1, N + 1)\n",
    "        ]\n",
    "    )"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Question 2**\n",
    "\n",
    "> 1. Proposez une fonction `Li(i, x, xx)` qui prend en arguments un entier $i$ et deux vecteurs $x$ et $xx$ et qui retourne (si c'est possible) l'évaluation du polynôme $L_i$ aux points $xx$ avec pour rappel\n",
    "$$ L_i(X) = \\prod_{j\\neq i} \\frac{X-x_j}{x_i-x_j}.$$\n",
    "> 2. Tracez dans des fenêtres graphiques séparés l'allure des différents polynômes pour les points équi-répartis et les points de Tchebychev (pour différentes valeurs de $N$). Vous pouvez essayer d'obtenir une figure ressemblant à celle-ci.\n",
    "> 3. Que remarquez-vous ?\n",
    "\n",
    "![polynomesLi](TP05_Li.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "def Li(i, x, xx):\n",
    "    N = len(x)\n",
    "    L = np.ones_like(xx)\n",
    "    for j in range(N):\n",
    "        if i != j:\n",
    "            L *= (xx - x[j]) / (x[i] - x[j])\n",
    "    return L"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 156208 characters]\n",
      "text/plain": [
       "<Figure size 800x300 with 2 Axes>"
      ]
     },
     "metadata": {
      "image/png": {
       "height": 296,
       "width": 671
      }
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 225100 characters]\n",
      "text/plain": [
       "<Figure size 800x300 with 2 Axes>"
      ]
     },
     "metadata": {
      "image/png": {
       "height": 296,
       "width": 692
      }
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 292956 characters]\n",
      "text/plain": [
       "<Figure size 800x300 with 2 Axes>"
      ]
     },
     "metadata": {
      "image/png": {
       "height": 296,
       "width": 670
      }
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 299468 characters]\n",
      "text/plain": [
       "<Figure size 800x300 with 2 Axes>"
      ]
     },
     "metadata": {
      "image/png": {
       "height": 296,
       "width": 696
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "N = [3, 5, 11, 21]\n",
    "a, b = 0, 1\n",
    "\n",
    "xx = np.linspace(a, b, 200)\n",
    "\n",
    "for n in N:\n",
    "    fig, ax = plt.subplots(1, 2, figsize=(8, 3))\n",
    "    ax[0].set_title(f\"Points équi-repartis (N={n})\")\n",
    "    xeq = equirepartis(a, b, n)\n",
    "    for i in range(n):\n",
    "        ax[0].scatter(xeq[i], 0, color=\"black\")\n",
    "        ax[0].scatter(xeq[i], 1, color=\"black\")\n",
    "        ax[0].plot(xx, Li(i, xeq, xx))\n",
    "    ax[0].grid()\n",
    "\n",
    "    ax[1].set_title(f\"Points de Tchebychev (N={n})\")\n",
    "    xchev = tchebychev(a, b, n)\n",
    "    for i in range(n):\n",
    "        ax[1].scatter(xchev[i], 0, color=\"black\")\n",
    "        ax[1].scatter(xchev[i], 1, color=\"black\")\n",
    "        ax[1].plot(xx, Li(i, xchev, xx))\n",
    "    ax[1].grid()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Question 3**\n",
    "\n",
    "Afin de visualiser la convergence ou la non convergence du polynôme interpolateur vers une fonction régulière, nous choisissons de prendre la fonction $f$ définie sur $[-5, 5]$ par\n",
    "$$f(x) = \\frac{1}{1+x^2}.$$\n",
    "\n",
    "> 1. Tracez dans une même fenêtre graphique\n",
    ">    - la fonction $f$\n",
    ">    - les polynômes interpolateurs de Lagrange pour $N$ points équi-répartis avec $N\\in\\lbrace 5, 10, 20 \\rbrace$. Ajoutez un titre et une légende.\n",
    "> 2. Recommencez la question précédente avec des points de Tchebychev.\n",
    "> 3. Que remarquez-vous ?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 650404 characters]\n",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {
      "image/png": {
       "height": 435,
       "width": 568
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "def f(x):\n",
    "    return 1 / (1 + x**2)\n",
    "a, b = -5, 5\n",
    "xx = np.linspace(a, b, 200)\n",
    "\n",
    "plt.plot(xx, f(xx), label=\"Courbe de f\")\n",
    "for n in [5, 10, 20]:\n",
    "    xeq = equirepartis(a, b, n)\n",
    "    for i in range(n):\n",
    "        plt.scatter(xeq[i], f(xeq[i]))\n",
    "        plt.plot(xx, Li(i, xeq, xx))\n",
    "\n",
    "plt.ylim(-1, 1)\n",
    "plt.legend()\n",
    "plt.title(\"Interpolation de f avec Lagrange pour N points répartis\")\n",
    "plt.grid()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 594296 characters]\n",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {
      "image/png": {
       "height": 434,
       "width": 580
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "def f(x):\n",
    "    return 1 / (1 + x**2)\n",
    "a, b = -5, 5\n",
    "xx = np.linspace(a, b, 200)\n",
    "\n",
    "plt.plot(xx, f(xx), label=\"Courbe de f\")\n",
    "\n",
    "for n in [5, 10, 20]:\n",
    "    xchev = tchebychev(a, b, n)\n",
    "    for i in range(n):\n",
    "        plt.scatter(xchev[i], f(xchev[i]))\n",
    "        plt.plot(xx, Li(i, xchev, xx))\n",
    "\n",
    "plt.legend()\n",
    "plt.title(\"Interpolation de f avec Lagrange pour N points de Tchebychev\")\n",
    "plt.grid()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Question 4**\n",
    "\n",
    "Pour mesurer l'écart entre la fonction $f$ et un polynôme interpolateur $P$, nous choisissons la norme infinie.\n",
    "\n",
    "> 1. Tracez dans une fenêtre graphique la norme infinie de la différence entre la fonction et son polynôme interpolateur à $N$ points équi-répartis en fonction de $N$. Vous prendrez $N$ entre $5$ et $100$ par pas de $5$ et vous choisirez une échelle logarithmique pour les ordonnées.\n",
    "> 2. Ajoutez sur la même figure la courbe obtenue pour les points de Techbychev.\n",
    "> 3. Que remarquez-vous ?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "x and y must have same first dimension, but have shapes (200,) and (1,)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[140], line 10\u001b[0m\n\u001b[1;32m      8\u001b[0m xeq \u001b[38;5;241m=\u001b[39m equirepartis(a, b, n)\n\u001b[1;32m      9\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(n):\n\u001b[0;32m---> 10\u001b[0m     \u001b[43mplt\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mplot\u001b[49m\u001b[43m(\u001b[49m\u001b[43mxx\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mn_inf\u001b[49m\u001b[43m(\u001b[49m\u001b[43mf\u001b[49m\u001b[43m(\u001b[49m\u001b[43mxx\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mLi\u001b[49m\u001b[43m(\u001b[49m\u001b[43mi\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mxeq\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mxx\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m/opt/conda/lib/python3.10/site-packages/matplotlib/pyplot.py:2785\u001b[0m, in \u001b[0;36mplot\u001b[0;34m(scalex, scaley, data, *args, **kwargs)\u001b[0m\n\u001b[1;32m   2783\u001b[0m \u001b[38;5;129m@_copy_docstring_and_deprecators\u001b[39m(Axes\u001b[38;5;241m.\u001b[39mplot)\n\u001b[1;32m   2784\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mplot\u001b[39m(\u001b[38;5;241m*\u001b[39margs, scalex\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m, scaley\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m, data\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[0;32m-> 2785\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mgca\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mplot\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m   2786\u001b[0m \u001b[43m        \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mscalex\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mscalex\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mscaley\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mscaley\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m   2787\u001b[0m \u001b[43m        \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m{\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mdata\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[43m}\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mis\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mnot\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43m{\u001b[49m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m/opt/conda/lib/python3.10/site-packages/matplotlib/axes/_axes.py:1688\u001b[0m, in \u001b[0;36mAxes.plot\u001b[0;34m(self, scalex, scaley, data, *args, **kwargs)\u001b[0m\n\u001b[1;32m   1445\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m   1446\u001b[0m \u001b[38;5;124;03mPlot y versus x as lines and/or markers.\u001b[39;00m\n\u001b[1;32m   1447\u001b[0m \n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m   1685\u001b[0m \u001b[38;5;124;03m(``'green'``) or hex strings (``'#008000'``).\u001b[39;00m\n\u001b[1;32m   1686\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m   1687\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m cbook\u001b[38;5;241m.\u001b[39mnormalize_kwargs(kwargs, mlines\u001b[38;5;241m.\u001b[39mLine2D)\n\u001b[0;32m-> 1688\u001b[0m lines \u001b[38;5;241m=\u001b[39m [\u001b[38;5;241m*\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_get_lines(\u001b[38;5;241m*\u001b[39margs, data\u001b[38;5;241m=\u001b[39mdata, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)]\n\u001b[1;32m   1689\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m line \u001b[38;5;129;01min\u001b[39;00m lines:\n\u001b[1;32m   1690\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39madd_line(line)\n",
      "File \u001b[0;32m/opt/conda/lib/python3.10/site-packages/matplotlib/axes/_base.py:311\u001b[0m, in \u001b[0;36m_process_plot_var_args.__call__\u001b[0;34m(self, data, *args, **kwargs)\u001b[0m\n\u001b[1;32m    309\u001b[0m     this \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m args[\u001b[38;5;241m0\u001b[39m],\n\u001b[1;32m    310\u001b[0m     args \u001b[38;5;241m=\u001b[39m args[\u001b[38;5;241m1\u001b[39m:]\n\u001b[0;32m--> 311\u001b[0m \u001b[38;5;28;01myield from\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_plot_args\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m    312\u001b[0m \u001b[43m    \u001b[49m\u001b[43mthis\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mambiguous_fmt_datakey\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mambiguous_fmt_datakey\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m/opt/conda/lib/python3.10/site-packages/matplotlib/axes/_base.py:504\u001b[0m, in \u001b[0;36m_process_plot_var_args._plot_args\u001b[0;34m(self, tup, kwargs, return_kwargs, ambiguous_fmt_datakey)\u001b[0m\n\u001b[1;32m    501\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39maxes\u001b[38;5;241m.\u001b[39myaxis\u001b[38;5;241m.\u001b[39mupdate_units(y)\n\u001b[1;32m    503\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m x\u001b[38;5;241m.\u001b[39mshape[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;241m!=\u001b[39m y\u001b[38;5;241m.\u001b[39mshape[\u001b[38;5;241m0\u001b[39m]:\n\u001b[0;32m--> 504\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mx and y must have same first dimension, but \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m    505\u001b[0m                      \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhave shapes \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mx\u001b[38;5;241m.\u001b[39mshape\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m and \u001b[39m\u001b[38;5;132;01m{\u001b[39;00my\u001b[38;5;241m.\u001b[39mshape\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m    506\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m x\u001b[38;5;241m.\u001b[39mndim \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m2\u001b[39m \u001b[38;5;129;01mor\u001b[39;00m y\u001b[38;5;241m.\u001b[39mndim \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m2\u001b[39m:\n\u001b[1;32m    507\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mx and y can be no greater than 2D, but have \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m    508\u001b[0m                      \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mshapes \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mx\u001b[38;5;241m.\u001b[39mshape\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m and \u001b[39m\u001b[38;5;132;01m{\u001b[39;00my\u001b[38;5;241m.\u001b[39mshape\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[0;31mValueError\u001b[0m: x and y must have same first dimension, but have shapes (200,) and (1,)"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 24060 characters]\n",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {
      "image/png": {
       "height": 418,
       "width": 558
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "N = np.arange(5, 101, 5)\n",
    "\n",
    "\n",
    "def n_inf(f, p):\n",
    "    return np.max([f, p])\n",
    "\n",
    "\n",
    "# Norme inf en fct de N\n",
    "for n in N:\n",
    "    xeq = equirepartis(a, b, n)\n",
    "    for i in range(n):\n",
    "        plt.plot(xx, n_inf(f(xx), Li(i, xeq, xx)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
