diff --git a/Chapitre 1 - Systemes equations lineaires/.ipynb_checkpoints/AL_Fct-checkpoint.py b/Chapitre 1 - Systemes equations lineaires/.ipynb_checkpoints/AL_Fct_old-checkpoint.py similarity index 100% copy from Chapitre 1 - Systemes equations lineaires/.ipynb_checkpoints/AL_Fct-checkpoint.py copy to Chapitre 1 - Systemes equations lineaires/.ipynb_checkpoints/AL_Fct_old-checkpoint.py diff --git "a/Chapitre 1 - Systemes equations lineaires/1.1. Introduction et d\303\251finition.ipynb" "b/Chapitre 1 - Systemes equations lineaires/1.1. Introduction et d\303\251finition.ipynb" index ef06df6..b6a6386 100644 --- "a/Chapitre 1 - Systemes equations lineaires/1.1. Introduction et d\303\251finition.ipynb" +++ "b/Chapitre 1 - Systemes equations lineaires/1.1. Introduction et d\303\251finition.ipynb" @@ -1,295 +1,463 @@ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Concept(s)-clé(s) et théorie\n", "\n", "### DÉFINITION 1 :\n", "\n", "Une *équation linéaire* aux inconnues $x_1,\\ldots,x_n$ à coefficients réels est une équation de la forme\n", "\n", "$$a_1x_1+a_2x_2+\\cdots+a_nx_n=b,$$ \n", "où $a_1,a_2,\\ldots,a_n,b\\in \\mathbb{R}.$\n", " \n", "---\n", "### DÉFINITION 2 :\n", "\n", "On appelle *système d'équations linéaires* (ou simplement système linéaire) une famille d'équations linéaires aux inconnues $x_1,\\ldots,x_n$ à coefficients réels de la forme \n", "\n", "$$S=\\left\\{\\begin{array}{ccccccc}\n", "a_{11}x_1 &+a_{12}x_2 & + &\\cdots &+a_{1n}x_n &= &b_1 \\\\\n", "a_{21}x_1 &+a_{22}x_2 & + &\\cdots &+a_{2n}x_n &= &b_2 \\\\\n", "\\vdots & & & &\\vdots & \\vdots &\\vdots \\\\\n", "a_{m1}x_1 &+a_{m2}x_2 & + &\\cdots &+a_{mn}x_n &= &b_m\n", "\\end{array},\\right. $$\n", "\n", "où $a_{ij},b_i\\in \\mathbb{R}$ pour tout $1\\leq i\\leq m$ et tout $1\\leq j\\leq n.$ \n", "\n", "Aussi, on dit qu'une suite ordonnée de $n$ nombres réels $\\alpha=(\\alpha_1,\\ldots,\\alpha_n)$ est une *solution du système linéaire* $S$ si toutes les égalités du système sont vérifiées lorsque l'on remplace $x_j$ par $\\alpha_j,$ ceci pout tout $1\\leq j\\leq n.$" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ - "import AL_Fct as al\n", - "from IPython.core.magic import register_cell_magic\n", - "from IPython.display import HTML, display\n", - "import numpy as np" + "import Librairie.AL_Fct as al\n", + "#from IPython.core.magic import register_cell_magic\n", + "#from IPython.display import HTML, display\n", + "#import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### EXEMPLE 1\n", "\n", "Dans ce premier exemple nous nous familiarisons avec les équations et les ensembles de solutions. Soit \n", "$$ \n", "a_{1}x_{1} + a_{2}x_{2} + \\ldots a_{n}x_{n}=b_1.\n", "$$ \n", "On utilise *la syntaxe suivante pour définir les coefficients* de l'équation \n", "\n", "$$\n", "\\begin{align*}\n", "A&=[a_1, a_2, \\ldots, a_n]\\\\\n", "b&=[b_1].\n", "\\end{align*}\n", "$$\n", "\n", "---\n", "Dans la case ci-dessous, entrer les coefficients de l'équation \n", "$$3x_1 + 2x_2=7$$\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "al.bgc('seashell')\n", "#Toutes les valeurs sont initialisées à 1\n", "\n", "A = [1] \n", "b = [1]\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/latex": [ + "$1x_1=1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "al.printEq(A,b)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "On utilise *la syntaxe suivante pour entrer une solution* d'une équation\n", "$$\\rm{alpha}=[\\alpha_1, \\alpha_2, \\ldots, \\alpha_n]$$" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "al.bgc('seashell')\n", "#Toutes les valeurs sont initialisées à 1\n", "\n", "alpha = [1] #solution" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "La suite entrée est une solution de l'équation 1\n" + ] + } + ], "source": [ "isSol = [al.SolOfEq(alpha, A+b,1)]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### **EXERCICE 1**\n", "\n", "Enter l'équation $$ \\frac{2}{5}x_1 -4x_2 + x_3 = 8$$ et donner une solution $$\\alpha=(\\alpha_1, \\alpha_2, \\alpha_3).$$\n", "\n", "Vous pouvez aussi adapter le code à l'équation de votre choix." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "al.bgc('seashell')\n", "\n", "#Par défaut, les valeurs sont fixées à 1\n", "\n", "A = [1] \n", "b =[1]\n", "alpha = [1] #solution " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/latex": [ + "$1x_1=1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "La suite entrée est une solution de l'équation 1\n" + ] + } + ], "source": [ "al.printEq(A,b)\n", "isSol=[al.SolOfEq(alpha, A+b,1)]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### EXEMPLE 2\n", "\n", "Dans cet exercice nous nous familiarisonns avec les systèmes d'équations. La partie ci-dessous vous demande de rentrer un système d'équation. \n", "\n", "Soit\n", "$$S=\\left\\{\\begin{array}{ccccccc}\n", "a_{11}x_1 &+a_{12}x_2 & + &\\cdots &+a_{1n}x_n &= &b_1 \\\\\n", "a_{21}x_1 &+a_{22}x_2 & + &\\cdots &+a_{2n}x_n &= &b_2 \\\\\n", "\\vdots & & & &\\vdots & \\vdots &\\vdots \\\\\n", "a_{m1}x_1 &+a_{m2}x_2 & + &\\cdots &+a_{mn}x_n &= &b_m\n", "\\end{array},\\right. $$\n", "\n", "On utilise *la syntaxe suivante pour entrer les coefficients du système*\n", "\n", "$$\n", "\\begin{align*}\n", "A&=\\quad [\\quad [ a_{11} , a_{12}, \\ldots, a_{1n} ], \\quad [ a_{21}, a_{22}, \\ldots, a_{2n}]\\quad, \\ldots , \\quad[a_{m1}, a_{m2}, \\ldots, a_{mn}]\\quad]\\\\\n", "b&=\\quad [\\quad b_1, b_2, \\ldots, b_m \\quad]\n", "\\end{align*}$$\n", "\n", "---\n", "Essayer d'entrer le système d'équations ci-dessous\n", "\n", "$$\\begin{cases}\n", "x_1 &-3 x_2 &&=4\\\\\n", "-x_1 & + 4 x_2&&= 5\n", "\\end{cases}\n", "$$" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "al.bgc('seashell')\n", "\n", "#Par défaut, les valeurs sont fixées à 1\n", "\n", "A = [ [1, 1], [1, 1]] \n", "b=[1,1] \n", "alpha = [1,1] #solution" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/latex": [ + "$\\begin{cases}1x_1 + 1x_2=1\\\\1x_1 + 1x_2=1\\\\\\end{cases}$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "al.printSyst(A,b)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "La suite entrée n'est pas une solution de l'équation 1\n", + "La suite entrée n'est pas une solution de l'équation 2\n", + "Ce n'est pas une solution du système\n" + ] + } + ], "source": [ "al.SolOfSyst(alpha, A,b)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### **EXERCICE 2**\n", " \n", "Entrer le système suivant et donner une solution du système.\n", "\n", "$$\\begin{cases}\n", "&2x_1 -3 x_2 + x_3&&=-5\\\\\n", "&-\\dfrac{1}{3}x_1 + x_3&&= 2\\\\\n", "&x_1 + 4x_2 -x_3 &&=0\n", "\\end{cases}\n", "$$\n", "\n", "Vous pouvez aussi adapter le code à l'équation de votre choix." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "al.bgc('seashell')\n", "#Par défaut, les valeurs sont fixées à 1\n", "\n", "A = [[1,1,1], [1,1,1], [1,1,1]]\n", "b =[1,1,1]\n", "alpha =[1,1,1] #solution\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/latex": [ + "$\\begin{cases}1x_1 + 1x_2 + 1x_3=1\\\\1x_1 + 1x_2 + 1x_3=1\\\\1x_1 + 1x_2 + 1x_3=1\\\\\\end{cases}$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "La suite entrée n'est pas une solution de l'équation 1\n", + "La suite entrée n'est pas une solution de l'équation 2\n", + "La suite entrée n'est pas une solution de l'équation 3\n", + "Ce n'est pas une solution du système\n" + ] + } + ], "source": [ "al.printSyst(A,b)\n", "al.SolOfSyst(alpha, A,b)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "[Passez au notebook du chapitre 1.2: Nombre de solutions d'un système](https://stag-noto.epfl.ch/user/ch-epfl-178578/lab?)" + "[Passez au notebook du chapitre 1.2: Nombre de solutions d'un système](./1.2.%20Nombre%20de%20solution%20d'un%20système.ipynb)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "b=al.np.array([1,2,3])" ] + }, + { + "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.6.8" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/Chapitre 1 - Systemes equations lineaires/AL_Fct.py b/Chapitre 1 - Systemes equations lineaires/AL_Fct_old.py similarity index 100% copy from Chapitre 1 - Systemes equations lineaires/AL_Fct.py copy to Chapitre 1 - Systemes equations lineaires/AL_Fct_old.py diff --git a/Chapitre 1 - Systemes equations lineaires/Librairie b/Chapitre 1 - Systemes equations lineaires/Librairie new file mode 120000 index 0000000..a65e52f --- /dev/null +++ b/Chapitre 1 - Systemes equations lineaires/Librairie @@ -0,0 +1 @@ +../Librairie \ No newline at end of file diff --git "a/Chapitre 2 - Algebre matricielle/.ipynb_checkpoints/2.5 Matrices \303\251l\303\251mentaires-checkpoint.ipynb" "b/Chapitre 2 - Algebre matricielle/.ipynb_checkpoints/2.5 Matrices \303\251l\303\251mentaires-checkpoint.ipynb" index ffd27e1..946c27c 100644 --- "a/Chapitre 2 - Algebre matricielle/.ipynb_checkpoints/2.5 Matrices \303\251l\303\251mentaires-checkpoint.ipynb" +++ "b/Chapitre 2 - Algebre matricielle/.ipynb_checkpoints/2.5 Matrices \303\251l\303\251mentaires-checkpoint.ipynb" @@ -1,145 +1,279 @@ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# **Concept(s)-clé(s) et théorie**\n", "\n", "Une matrice élémentaire (de taille $n \\times n$) est une matrice obtenue en effectuant une (et une seule) opération élémentaire, de type (I), (II) ou (III), sur les lignes de la matrice $I_n.$ Concrétement, on adoptera les notations suivantes.\n", "\n", "1. La matrice $T_{ij}$ est la matrice obtenue en échangeant les lignes $i$ et $j$ de $I_n.$\n", "2. La matrice $D_r(\\lambda)$ est la matrice obtenue en multipliant la $r$-ème ligne de $I_n$ par $\\lambda \\in \\mathbb{R}.$\n", "3. La matrice $L_{rs}(\\lambda)$ est la matrice obtenue en ajoutant $\\lambda$ fois la ligne $s$ à la ligne $r$ de $I_n.$" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "ImportError", + "evalue": "cannot import name 'multi_dot_three'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlinalg\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlinalg\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mmulti_dot_three\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mipywidgets\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0minteract_manual\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mImportError\u001b[0m: cannot import name 'multi_dot_three'" + ] + } + ], "source": [ "import AL_Fct as al\n", "import numpy as np\n", "from numpy.linalg import *\n", - "from numpy.linalg import multi_dot" + "from numpy.linalg import multi_dot\n", + "from ipywidgets import interact_manual" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Soient les deux matrices élémentaires ci-dessous.\n", + "$$\n", + "E_1=\\begin{pmatrix}\n", + "1 & 0 & 0 & 0\\\\\n", + "0 & 1 & 0 & -6 \\\\\n", + "0 & 0 & 1 &0 \\\\\n", + "0 & 0 & 0 & 1\n", + "\\end{pmatrix}\\hspace{3cm}\n", + "E_2=\\begin{pmatrix}\n", + "0 & 0 & 1 & 0\\\\\n", + "0 & 1 & 0 & 0 \\\\\n", + "1 & 0 & 0 &0 \\\\\n", + "0 & 0 & 0& 1\n", + "\\end{pmatrix}\n", + "$$\n", + "Laquelle des affirmations ci-dessous est correcte?\n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "931a1887a6a94966bd983255086cbfea", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(Checkbox(value=False, description='\\\\(E_1E_2\\\\) multiplie la ligne 4 par -6 et échange l…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "from IPython.display import display, Latex\n", + "from ipywidgets import Button, HBox, VBox,Layout\n", + "import ipywidgets as widgets\n", + " # OK PUT in AL_FCT\n", + "\n", + "a=widgets.Checkbox(\n", + " value=False,\n", + " description=r'\\(E_1E_2\\) multiplie la ligne 4 par -6 et échange les lignes 2 et 3',\n", + " disabled=False,\n", + " layout=Layout(width='80%', height='40px')\n", + ")\n", + "b=widgets.Checkbox(\n", + " value=False,\n", + " description=r'\\(E_1E_2\\) ajoute 6 fois la ligne 4 à la ligne 2 et échange les lignes 1 et 3',\n", + " disabled=False,\n", + " layout=Layout(width='80%', height='40px')\n", + "\n", + ")\n", + "c=widgets.Checkbox(\n", + " value=False,\n", + " description=r'\\(E_1E_2\\) échange les lignes 1 et 3 et ajoute -6 fois la ligne 4 à la ligne 2',\n", + " disabled=False,\n", + " layout=Layout(width='80%', height='40px')\n", + ")\n", + "d=widgets.Checkbox(\n", + " value=False,\n", + " description=r\"\\(E_1E_2\\) ajoute -6 fois la ligne 4 à la ligne 2 et échange les lignes 1 et 2\",\n", + " disabled=False,\n", + " layout=Layout(width='80%', height='40px')\n", + ")\n", + "def correction(a,b,c,d): \n", + " if c and not(a) and not(d) and not(b):\n", + " print(\"C'est correct! Par exemple, si on applique le produit à la matrice ci-dessous\")\n", + " A=np.asmatrix([[1, -1,0,0], [0, 0 ,0,1], [1,2,1,2],[1,0,0,1]])\n", + " B=np.asmatrix([[1,0,0,0],[0,1,0,-6],[0,0,1,0],[0,0,0,1]])\n", + " C=np.asmatrix([[0,0,1,0],[0,1,0,0],[1,0,0,0],[0,0,0,1]])\n", + " al.printA(A)\n", + " print(\"on obtient\")\n", + " al.printA(np.linalg.multi_dot([B,C,A]))\n", + " else:\n", + " print(\"C'est faux.\")\n", + "\n", + "out=interact_manual(correction,a=a,b=b,c=c,d=d)\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Donner l'inverse de $E_1E_2$" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "inverse=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1 0 0 0]\n", + " [0 1 0 0]\n", + " [0 0 1 0]\n", + " [0 0 0 1]]\n" + ] + } + ], + "source": [ + "if inverse==[[0,0,1,0],[0,1,0,6],[1,0,0,0],[0,0,0,1]]:\n", + " print(\"C'est correct!\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Soient $A$ et $B$ les deux matrices ci-dessous. \n", "\n", "$$\n", "A=\\begin{pmatrix}\n", "-2 &1& 4\\\\\n", "1 & 0 & 2\\\\\n", "-1 & -\\dfrac{1}{2} & 3\n", "\\end{pmatrix}, \\hspace{2em}\n", "B=\\begin{pmatrix}\n", "-1 & -\\dfrac{1}{2} & 3 \\\\\n", "5 & -2 & -6\\\\\n", "-10 & 5 & 20\n", "\\end{pmatrix}\n", "$$" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "A=[[-2,1,4],[1,0,2],[-1, -1/2 , 3]]\n", "B=[[-1, -1/2, 3],[5, -2, -6],[-10,5,20]]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "On passe de la matrice $A$ à la matrice $B$ à l'aide de trois matrices élémentaires $T_{ij}$, $D_{r}(\\lambda)$ et $L_{rs}(\\lambda)$\n", "$$\n", "L_{rs}(\\lambda) \\cdot D_{r}(\\lambda)\\cdot T_{ij}\\cdot A =B\n", "$$\n", "\n", "Trouver les trois matrices." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "T=[[1,0,0],[0,1,0],[0,0,1]]\n", "D=[[5,0,0],[0,1,0],[0,0,1]]\n", "L=[[1,0,0],[0,1,0],[0,0,1]]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#OK put in the al_FCt file\n", "if ~(B-np.linalg.multi_dot([L,D,T,A])).any():\n", " print(\"C'est correct!\")\n", "else :\n", " str='Il faut entrer la/les matrice(s) '\n", " if (np.asmatrix(T)-np.asmatrix([[0,0,1],[0,1,0],[1,0,0]])).any():\n", " str=str+ ' T '\n", " if (np.asmatrix(D)-np.asmatrix([[5,0,0],[0,1,0],[0,0,1]])).any():\n", " str=str+ ' D '\n", " if L!=[[1,0,0],[-2,1,0],[0,0,1]]:\n", " str=str+ ' L '\n", " str=str + 'à nouveau. Le produit des matrices entrées vaut'\n", " print(str)\n", " al.printA(np.linalg.multi_dot([L,D,T,A]))\n", " \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "a=np.asmatrix([1,1])\n", - "b=np.asmatrix([1,1])\n", - "print(a-b)\n", - "~(a-b).any()" - ] + "source": [] }, { "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.6.8" } }, "nbformat": 4, "nbformat_minor": 2 } diff --git "a/Chapitre 2 - Algebre matricielle/.ipynb_checkpoints/2.6-2.7 Crit\303\250res d'inversibilit\303\251-checkpoint.ipynb" "b/Chapitre 2 - Algebre matricielle/.ipynb_checkpoints/2.6-2.7 Crit\303\250res d'inversibilit\303\251-checkpoint.ipynb" new file mode 100644 index 0000000..2fd6442 --- /dev/null +++ "b/Chapitre 2 - Algebre matricielle/.ipynb_checkpoints/2.6-2.7 Crit\303\250res d'inversibilit\303\251-checkpoint.ipynb" @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/Chapitre 2 - Algebre matricielle/2.5 Matrices \303\251l\303\251mentaires.ipynb" "b/Chapitre 2 - Algebre matricielle/2.5 Matrices \303\251l\303\251mentaires.ipynb" index ffd27e1..946c27c 100644 --- "a/Chapitre 2 - Algebre matricielle/2.5 Matrices \303\251l\303\251mentaires.ipynb" +++ "b/Chapitre 2 - Algebre matricielle/2.5 Matrices \303\251l\303\251mentaires.ipynb" @@ -1,145 +1,279 @@ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# **Concept(s)-clé(s) et théorie**\n", "\n", "Une matrice élémentaire (de taille $n \\times n$) est une matrice obtenue en effectuant une (et une seule) opération élémentaire, de type (I), (II) ou (III), sur les lignes de la matrice $I_n.$ Concrétement, on adoptera les notations suivantes.\n", "\n", "1. La matrice $T_{ij}$ est la matrice obtenue en échangeant les lignes $i$ et $j$ de $I_n.$\n", "2. La matrice $D_r(\\lambda)$ est la matrice obtenue en multipliant la $r$-ème ligne de $I_n$ par $\\lambda \\in \\mathbb{R}.$\n", "3. La matrice $L_{rs}(\\lambda)$ est la matrice obtenue en ajoutant $\\lambda$ fois la ligne $s$ à la ligne $r$ de $I_n.$" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "ImportError", + "evalue": "cannot import name 'multi_dot_three'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlinalg\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlinalg\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mmulti_dot_three\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mipywidgets\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0minteract_manual\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mImportError\u001b[0m: cannot import name 'multi_dot_three'" + ] + } + ], "source": [ "import AL_Fct as al\n", "import numpy as np\n", "from numpy.linalg import *\n", - "from numpy.linalg import multi_dot" + "from numpy.linalg import multi_dot\n", + "from ipywidgets import interact_manual" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Soient les deux matrices élémentaires ci-dessous.\n", + "$$\n", + "E_1=\\begin{pmatrix}\n", + "1 & 0 & 0 & 0\\\\\n", + "0 & 1 & 0 & -6 \\\\\n", + "0 & 0 & 1 &0 \\\\\n", + "0 & 0 & 0 & 1\n", + "\\end{pmatrix}\\hspace{3cm}\n", + "E_2=\\begin{pmatrix}\n", + "0 & 0 & 1 & 0\\\\\n", + "0 & 1 & 0 & 0 \\\\\n", + "1 & 0 & 0 &0 \\\\\n", + "0 & 0 & 0& 1\n", + "\\end{pmatrix}\n", + "$$\n", + "Laquelle des affirmations ci-dessous est correcte?\n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "931a1887a6a94966bd983255086cbfea", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(Checkbox(value=False, description='\\\\(E_1E_2\\\\) multiplie la ligne 4 par -6 et échange l…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "from IPython.display import display, Latex\n", + "from ipywidgets import Button, HBox, VBox,Layout\n", + "import ipywidgets as widgets\n", + " # OK PUT in AL_FCT\n", + "\n", + "a=widgets.Checkbox(\n", + " value=False,\n", + " description=r'\\(E_1E_2\\) multiplie la ligne 4 par -6 et échange les lignes 2 et 3',\n", + " disabled=False,\n", + " layout=Layout(width='80%', height='40px')\n", + ")\n", + "b=widgets.Checkbox(\n", + " value=False,\n", + " description=r'\\(E_1E_2\\) ajoute 6 fois la ligne 4 à la ligne 2 et échange les lignes 1 et 3',\n", + " disabled=False,\n", + " layout=Layout(width='80%', height='40px')\n", + "\n", + ")\n", + "c=widgets.Checkbox(\n", + " value=False,\n", + " description=r'\\(E_1E_2\\) échange les lignes 1 et 3 et ajoute -6 fois la ligne 4 à la ligne 2',\n", + " disabled=False,\n", + " layout=Layout(width='80%', height='40px')\n", + ")\n", + "d=widgets.Checkbox(\n", + " value=False,\n", + " description=r\"\\(E_1E_2\\) ajoute -6 fois la ligne 4 à la ligne 2 et échange les lignes 1 et 2\",\n", + " disabled=False,\n", + " layout=Layout(width='80%', height='40px')\n", + ")\n", + "def correction(a,b,c,d): \n", + " if c and not(a) and not(d) and not(b):\n", + " print(\"C'est correct! Par exemple, si on applique le produit à la matrice ci-dessous\")\n", + " A=np.asmatrix([[1, -1,0,0], [0, 0 ,0,1], [1,2,1,2],[1,0,0,1]])\n", + " B=np.asmatrix([[1,0,0,0],[0,1,0,-6],[0,0,1,0],[0,0,0,1]])\n", + " C=np.asmatrix([[0,0,1,0],[0,1,0,0],[1,0,0,0],[0,0,0,1]])\n", + " al.printA(A)\n", + " print(\"on obtient\")\n", + " al.printA(np.linalg.multi_dot([B,C,A]))\n", + " else:\n", + " print(\"C'est faux.\")\n", + "\n", + "out=interact_manual(correction,a=a,b=b,c=c,d=d)\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Donner l'inverse de $E_1E_2$" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "inverse=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1 0 0 0]\n", + " [0 1 0 0]\n", + " [0 0 1 0]\n", + " [0 0 0 1]]\n" + ] + } + ], + "source": [ + "if inverse==[[0,0,1,0],[0,1,0,6],[1,0,0,0],[0,0,0,1]]:\n", + " print(\"C'est correct!\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Soient $A$ et $B$ les deux matrices ci-dessous. \n", "\n", "$$\n", "A=\\begin{pmatrix}\n", "-2 &1& 4\\\\\n", "1 & 0 & 2\\\\\n", "-1 & -\\dfrac{1}{2} & 3\n", "\\end{pmatrix}, \\hspace{2em}\n", "B=\\begin{pmatrix}\n", "-1 & -\\dfrac{1}{2} & 3 \\\\\n", "5 & -2 & -6\\\\\n", "-10 & 5 & 20\n", "\\end{pmatrix}\n", "$$" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "A=[[-2,1,4],[1,0,2],[-1, -1/2 , 3]]\n", "B=[[-1, -1/2, 3],[5, -2, -6],[-10,5,20]]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "On passe de la matrice $A$ à la matrice $B$ à l'aide de trois matrices élémentaires $T_{ij}$, $D_{r}(\\lambda)$ et $L_{rs}(\\lambda)$\n", "$$\n", "L_{rs}(\\lambda) \\cdot D_{r}(\\lambda)\\cdot T_{ij}\\cdot A =B\n", "$$\n", "\n", "Trouver les trois matrices." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "T=[[1,0,0],[0,1,0],[0,0,1]]\n", "D=[[5,0,0],[0,1,0],[0,0,1]]\n", "L=[[1,0,0],[0,1,0],[0,0,1]]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#OK put in the al_FCt file\n", "if ~(B-np.linalg.multi_dot([L,D,T,A])).any():\n", " print(\"C'est correct!\")\n", "else :\n", " str='Il faut entrer la/les matrice(s) '\n", " if (np.asmatrix(T)-np.asmatrix([[0,0,1],[0,1,0],[1,0,0]])).any():\n", " str=str+ ' T '\n", " if (np.asmatrix(D)-np.asmatrix([[5,0,0],[0,1,0],[0,0,1]])).any():\n", " str=str+ ' D '\n", " if L!=[[1,0,0],[-2,1,0],[0,0,1]]:\n", " str=str+ ' L '\n", " str=str + 'à nouveau. Le produit des matrices entrées vaut'\n", " print(str)\n", " al.printA(np.linalg.multi_dot([L,D,T,A]))\n", " \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "a=np.asmatrix([1,1])\n", - "b=np.asmatrix([1,1])\n", - "print(a-b)\n", - "~(a-b).any()" - ] + "source": [] }, { "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.6.8" } }, "nbformat": 4, "nbformat_minor": 2 } diff --git "a/Chapitre 2 - Algebre matricielle/2.6-2.7 Crit\303\250res d'inversibilit\303\251.ipynb" "b/Chapitre 2 - Algebre matricielle/2.6-2.7 Crit\303\250res d'inversibilit\303\251.ipynb" new file mode 100644 index 0000000..3898d99 --- /dev/null +++ "b/Chapitre 2 - Algebre matricielle/2.6-2.7 Crit\303\250res d'inversibilit\303\251.ipynb" @@ -0,0 +1,52 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# **Concept(s)-clé(s) et théorie**\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import AL_Fct as al\n", + "import numpy as np\n", + "from numpy.linalg import *\n", + "from numpy.linalg import multi_dot\n", + "from ipywidgets import interact_manual" + ] + }, + { + "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.6.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Chapitre 3 - Espace vectoriel/.ipynb_checkpoints/Untitled-checkpoint.ipynb b/Chapitre 3 - Espace vectoriel/.ipynb_checkpoints/Untitled-checkpoint.ipynb new file mode 100644 index 0000000..2fd6442 --- /dev/null +++ b/Chapitre 3 - Espace vectoriel/.ipynb_checkpoints/Untitled-checkpoint.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Chapitre 3 - Espace vectoriel/Untitled.ipynb b/Chapitre 3 - Espace vectoriel/Untitled.ipynb new file mode 100644 index 0000000..a4c7d81 --- /dev/null +++ b/Chapitre 3 - Espace vectoriel/Untitled.ipynb @@ -0,0 +1,46 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "v=[1,2,3]\n", + "w=[0,-3,4]\n", + "#Quel vecteur on ajoute à v pour obtenir w?\n", + "\n", + "u=[-1, 5,1]\n", + "#maintenant que l'on a plus que des vecteurs, on peut utiliser [...]" + ] + }, + { + "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.6.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Chapitre 1 - Systemes equations lineaires/.ipynb_checkpoints/AL_Fct-checkpoint.py b/Librairie/.ipynb_checkpoints/AL_Fct-checkpoint.py similarity index 100% rename from Chapitre 1 - Systemes equations lineaires/.ipynb_checkpoints/AL_Fct-checkpoint.py rename to Librairie/.ipynb_checkpoints/AL_Fct-checkpoint.py diff --git a/Chapitre 1 - Systemes equations lineaires/AL_Fct.py b/Librairie/AL_Fct.py similarity index 100% rename from Chapitre 1 - Systemes equations lineaires/AL_Fct.py rename to Librairie/AL_Fct.py diff --git a/Librairie/__pycache__/AL_Fct.cpython-36.pyc b/Librairie/__pycache__/AL_Fct.cpython-36.pyc new file mode 100644 index 0000000..4370188 Binary files /dev/null and b/Librairie/__pycache__/AL_Fct.cpython-36.pyc differ