{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from IPython.display import HTML\n", "from ipywidgets import interact\n", "%matplotlib inline\n" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "The raw code for this IPython notebook is by default hidden for easier reading.\n", "To toggle on/off the raw code, click here." ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HTML('''\n", "The raw code for this IPython notebook is by default hidden for easier reading.\n", "To toggle on/off the raw code, click here.''')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "

\"Cube
By Francisco Antunes - https://www.flickr.com/photos/francisco-antunes/3815031014/, CC BY 2.0, Link

\n" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HTML(\"\"\"\n", "

\"Cube
By Francisco Antunes - https://www.flickr.com/photos/francisco-antunes/3815031014/, CC BY 2.0, Link

\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Des boules dans différentes normes du plan et de l'espace" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pour un espace vectoriel normé donné $(E, ||.||)$, on définit la *boule unité* par $B(0,1) = \\{x \\in E, ||x|| <1 \\}.$ L'ensemble qu'on obtient dépend bien sûr de la norme sur $E$. \n", "\n", "Dans le cas du plan $\\mathbb{R}^2$, on utilise usuellement la *norme euclidienne* donnée par $$\\|(x_1,x_2)\\|_2 = \\sqrt{|x_1|^2+|x_2|^2}$$, et la boule qu'on obtient a effectivement une tête de boule:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HTML(\"\"\"\n", "\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "On peut aussi munir $\\mathbb{R}^2$ de la *norme 1*:\n", "$$\\|(x_1,x_2)\\|_1 = |x_1|+|x_2|$$\n", "ou de la *norme infini*:\n", "$$\\|(x_1,x_2)\\|_\\infty = \\max\\{|x_1|^2+|x_2|^2\\}$$\n", "\n", "Les boules correspondantes n'ont pas la même tête !" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HTML(\"\"\"\n", "\n", "\"\"\")" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HTML(\"\"\"\n", "\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Toutefois, ces normes ont quand même un lien entre elles: elles sont *équivalentes*.\n", "\n", "Deux normes $\\|.\\|_a$ et $\\|.\\|_b$ sur $E$ sont équivalentes s'il existe des constantes positives $c,\\ C$ telles que pour tout $x$, $c\\|x\\|_a \\leq \\|x\\|_b \\leq C\\|x\\|_a)$. L'équivalence des normes peut se réécrire en termes d'inclusion de boules: l'inégalité précédente se réécrit\n", "$$B_a(0,\\frac1C) \\subset B_b(0,1) \\subset B_a(0, \\frac1c) $$\n", "\n", "En l'occurrence, on a \n", "$$\\dfrac12 ||x||_1 \\leq ||x||_\\infty \\leq ||x||_2 \\leq \\sqrt{2} ||x||_\\infty\\leq \\sqrt{2} ||x||_1$$\n", "donc\n", "$$||x||_1 \\leq \\frac{1}{\\sqrt{2}} \\Rightarrow ||x||_\\infty\\leq \\frac{1}{\\sqrt{2}}\\Rightarrow ||x||_2 \\leq 1 \\Rightarrow ||x||_\\infty \\leq 1 \\Rightarrow ||x||_1 \\leq 2$$\n", "c'est-à-dire\n", "$$B_1(0, \\frac{1}{\\sqrt{2}}) \\subset B_\\infty(0, \\frac{1}{\\sqrt{2}})\\subset B_2(0,1) \\subset B_\\infty(0,1)\\subset B_1(0,2):$$" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HTML(\"\"\"\n", "\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "En fait, pour tout $p \\geq 1$, on peut définir une norme sur $\\mathbb{R}^2$ par\n", "$$ \\|x\\|_p = (|x_1|^p + |x_2|^p)^{\\frac1p} $$\n", "Les boules unités associées passent continûment du losange de la norme 1, à la sphère usuelle, et tendent à se rapprocher du carré de la norme infinie quand $p$ devient grand:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f0f05648bf204022bd8b3a192f6732ef", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(FloatSlider(value=15.0, description='p', max=30.0, min=1.0, step=0.2), Output()), _dom_c…" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import ipywidgets as widgets\n", "from IPython.display import display\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from math import pi\n", "\n", "\n", "\n", "p_min = 1 # the minimial value of the parameter a\n", "p_max = 30 # the maximal value of the parameter a\n", "p_init = 2 # the value of the parameter a to be used initially, when the graph is created\n", "\n", "x = np.linspace(-1, 1, 500)\n", "\n", "#fig,ax = plt.subplots(1,figsize=(6,6))\n", "\n", "\n", "\n", "def update_plot(p):\n", " fig = plt.figure()\n", " ax=fig.gca()\n", " ax.clear()\n", " plt.xlim(-1.5, 1.5)\n", " plt.ylim(-1.5, 1.5)\n", " plt.plot(x, (1-abs(x)**p)**(1/p), 'r')\n", " plt.plot(x, -(1-abs(x)**p)**(1/p), 'r')\n", " plt.show()\n", "\n", "\n", "#plt.title(\"Boule unité pour la norme p\")\n", "\n", "interact ( update_plot, p = (1,30,0.2) )\n", "\n", "#p=widgets.FloatSlider(min=p_min, max=p_max,value=p_init,description=\"p\")\n", "\n", "\n", "#widgets.interactive(update_plot, p=p)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Remarquons que quand $p$ est plus petit que 1, on n'obtient pas une norme, car l'inégalité triangulaire n'est plus vérifiée. Par exemple pour $p=\\frac12$, en prenant $e_1=(1,0)$, $e_2=(0,1)$, on a \n", "$$\\|e_1+e_2\\|_{\\frac12} = (\\sqrt{1}+\\sqrt{1})^2 = 4$$\n", "et\n", "$$\\|e_1\\|_\\frac12+\\|e_2\\|_\\frac12 = (\\sqrt{0}+\\sqrt{1})^2+ (\\sqrt{1}+\\sqrt{0})^2 =2 $$\n", "donc $\\|e_1+e_2\\|_{\\frac12} > \\|e_1\\|_\\frac12+\\|e_2\\|_\\frac12$.\n", "Ceci se traduit par des boules concaves:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "3ce8f41e6e6d4f4ab5d47ad4dc9562df", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(FloatSlider(value=0.54, description='p', max=1.0, min=0.1, step=0.02), Output()), _dom_c…" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import ipywidgets as widgets\n", "from IPython.display import display\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from math import pi\n", "\n", "\n", "\n", "p_min = 0.1 # the minimial value of the parameter a\n", "p_max = 1 # the maximal value of the parameter a\n", "p_init = 0.5 # the value of the parameter a to be used initially, when the graph is created\n", "\n", "x = np.linspace(-1, 1, 500)\n", "\n", "#fig,ax = plt.subplots(1,figsize=(6,6))\n", "\n", "\n", "\n", "def update_plot(p):\n", " fig = plt.figure()\n", " ax=fig.gca()\n", " ax.clear()\n", " plt.xlim(-1.5, 1.5)\n", " plt.ylim(-1.5, 1.5)\n", " plt.plot(x, (1-abs(x)**p)**(1/p), 'r')\n", " plt.plot(x, -(1-abs(x)**p)**(1/p), 'r')\n", " plt.show()\n", "\n", "\n", "#plt.title(\"Boule unité pour la norme p\")\n", "\n", "interact ( update_plot, p = (0.1,1,0.02) )\n", "\n", "#p=widgets.FloatSlider(min=p_min, max=p_max,value=p_init,description=\"p\")\n", "\n", "\n", "#widgets.interactive(update_plot, p=p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Dans $\\mathbb{R}^3$, on peut de même définir, pour tout $p\\geq 1$, une *norme p* donnée par\n", "$$\\|x\\|_p = (|x_1|^p + |x_2|^p + |x_3|^p)^{\\frac1p} $$.\n", "Les plus usuelles sont la norme 1, la norme 2 (ou euclidienne), et la norme infinie, qui donnent des boules comme ci-dessous:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HTML(\"\"\"\n", "\n", "\"\"\")" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HTML(\"\"\"\n", "\n", "\"\"\")" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HTML(\"\"\"\n", "\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "On peut, comme précédemment, faire varier $p$:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "1d0fd3519eed4085adfcc58d94809b32", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(IntSlider(value=5, description='p', max=10, min=1), Output()), _dom_classes=('widget-int…" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "import matplotlib.pyplot as plt\n", "from mpl_toolkits.mplot3d import Axes3D\n", "from matplotlib.widgets import Slider # import the Slider widget\n", "import ipywidgets as widgets\n", "from IPython.display import display\n", "\n", "import numpy as np\n", "\n", "\n", "p_min = 1 # the minimial value of the parameter a\n", "p_max = 5 # the maximal value of the parameter a\n", "p_init = 2 \n", "\n", "\n", "n=10\n", "\n", "\n", "\n", "\n", "def update(p):\n", " fig = plt.figure()\n", " ax = fig.gca(projection='3d')\n", "\n", " ax.clear()\n", " \n", " x=[]\n", " y=[]\n", " for i in np.linspace(-1,1,2*n):\n", " for j in np.linspace(-(1-np.abs(i)**p)**(1/p), (1-np.abs(i)**p)**(1/p),n):\n", " x=x+[i]\n", " y=y+[j]\n", " x=np.array(x)\n", " y=np.array(y)\n", " z1=(np.abs(1-np.abs(x)**p-np.abs(y)**p))**(1/p)\n", " z2=-z1\n", " ax.plot_trisurf(x, y, z1, linewidth=0.2, antialiased=True, color='b')\n", " ax.plot_trisurf(x, y, z2, linewidth=0.2, antialiased=True, color='b')\n", " fig.canvas.draw_idle() \n", " plt.show()\n", "\n", "#p=widgets.FloatSlider(min=p_min, max=p_max,value=p_init,description=\"p\")\n", "\n", "#widgets.interactive(update, p=p)\n", "\n", "interact ( update, p = (1,10,1) )\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "et on a, comme précédemment, l'équivalence des normes, traduite en inclusion de boules:" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HTML(\"\"\"\n", "\n", "\"\"\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.7.2" } }, "nbformat": 4, "nbformat_minor": 2 }