diff --git "a/Chapitre 2 - Algebre matricielle/2.4 Syst\303\250mes d'\303\251quations et matrices.ipynb" "b/Chapitre 2 - Algebre matricielle/2.4 Syst\303\250mes d'\303\251quations et matrices.ipynb" index a16c376..236eb89 100644 --- "a/Chapitre 2 - Algebre matricielle/2.4 Syst\303\250mes d'\303\251quations et matrices.ipynb" +++ "b/Chapitre 2 - Algebre matricielle/2.4 Syst\303\250mes d'\303\251quations et matrices.ipynb" @@ -1,359 +1,419 @@ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# **Concept(s)-clé(s) et théorie**\n", "\n", "## Théorème\n", "Soit $A$ une matrice $n\\times n $ inversible. Alors pour tout vecteur $\\overrightarrow{b}\\in \\mathbb{R}^n$, l'équation $A\\overrightarrow{x}=\\overrightarrow{b}$ admet pour unique solution le vecteur $$\n", "\\overrightarrow{\\tilde{x}}=A^{-1}\\overrightarrow{b}$$" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + " \n", + " " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + " \n", + " " + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "import Librairie.AL_Fct as al\n", "import Corrections.corrections as corrections\n", "import numpy as np\n", "from IPython.display import display, Math" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### EXEMPLE 1\n", "Considérez le système d'équations linéaires donné sous forme d'équation matricielle $ A\\vec{x} = \\vec{b} $, avec\n", "\\begin{equation}\n", "A = \n", "\\begin{pmatrix}\n", "2 & 0 & 1\\\\\n", "0 & 3 & 4 \\\\\n", "2 & 2 & 1\n", - "\\end{pmatrix} \\text{ et } \\qquad \\vec{b} = \n", + "\\end{pmatrix}; \\qquad \\vec{b} = \n", "\\begin{pmatrix}\n", "2\\\\\n", "4\\\\\n", "3\\\\\n", "\\end{pmatrix}.\n", "\\end{equation}\n", "\n", "Nous allons trouver la solution du système en utilisant deux méthode. D'abord en résolvant le système d'équations linéaires avec la méthode d'élimintation de Gauss, puis en inversant la matrice $A$." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "#Entrez la matrice A et le vecteur b\n", "A = [[2, 0, 1], [0, 3, 4], [2, 2, 1]]\n", "b = [[2], [4], [3]]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Méthode 1: résoudre le système linéaire en utilisant la méthode d'élimination de Gauss" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('Vous allez échelonner la matrice augmentée')\n", "al.printAAug(A,b)\n", "[i,j,r,alpha]= al.manualEch(A)\n", "MatriceList=[np.array(A)]\n", "RHSList = [np.array(b)]\n", "m=np.concatenate((A,b), axis=1)\n", "print('\\033[1mExécutez la ligne suivante pour effectuer l\\'opération choisie \\033[0m')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "m=al.echelonnage(i, j, r, alpha, A, m, MatriceList, RHSList)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "#Entrez la solution que vous avez obtenue et vérifiez s'il s'agit bien d'une solution\n", "sol1 = [[11/16], [1/2], [5/8]]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"La solution entrée est\")\n", - "al.printA(sol)\n", - "res1 = al.SolOfSyst(sol, A, b)" + "al.printA(sol1)\n", + "res1 = al.SolOfSyst(sol1, A, b)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Méthode 2: calculer l'inverse de la matrice A ([voir le Notebook 2.3](./2.3%20Matrices%20carrées%2C%20inversibles.ipynb)) et trouver la solution du système linéaire en fonction du résultat obtenu" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "I=[[1,0,0],[0,1,0],[0,0,1]]\n", "print('Vous allez échelonner la matrice A augmentée de la matrice identité')\n", "al.printA(A,I)\n", "[i,j,r,alpha]= al.manualEch(A,I)\n", "m=np.concatenate((A,I), axis=1)\n", "MatriceList=[A]\n", "RhSList=[I]\n", "print('\\033[1mExécutez la ligne suivante pour effectuer l\\'opération choisie \\033[0m')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "m=al.echelonnage(i,j,r,alpha,A,m,MatriceList,RhSList)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "#Entrez l'inverse de la matrice A et vérifiez si vous obtenez la bonne solution.\n", - "A_inv = [[5/16,-1/8,3/16], [-1/2,0,1/2], [6/16,1/4,-6/16]]\n" + "A_inv = [[5/16,-1/8,3/16], [-1/2,0,1/2], [6/16,1/4,-6/16]]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"L'inverse obtenu est\")\n", "al.printA(A_inv)\n", "sol2 = np.dot(np.array(A_inv), np.array(b))\n", "print('Et la solution est donnée par')\n", "display(Math('x=A^{}b={}'.format({-1},sol2)))\n", "res2 = al.SolOfSyst(sol2, A, b)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ - "if sol1 and sol2:\n", + "if res1 and res2:\n", " print(f'C\\'est correct! Et en plus, {sol1} est la seule solution au système linéaire')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### EXERCICE 1\n", "Considérez le système d'équations suivant:\n", "\\begin{equation}\n", "\\begin{cases}\n", - "x_1 + 2x_2 - x_3 &=0\\\\\n", - "2x_1 - x_2 - x_3 &=1\\\\\n", - "x_1 - 2x_2 + x_3 &=2\n", + "x_1 + 2x_2 - x_3 &=1\\\\\n", + "2x_1 - x_2 - x_3 &=-2\\\\\n", + "x_1 - 2x_2 + x_3 &=1\n", "\\end{cases}\n", "\\end{equation}\n", "Lesquelles des affirmations suivantes sont correctes?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "corrections.Ex1Chapitre2_4()\n", - "#Sol is 1,0,1\n", - "#why are cells not displaying as before? " + "corrections.Ex1Chapitre2_4()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Vous pouvez exécuter les cellules suivantes pour vous aider à calculer (éventuellement) la solution du système linéaire et l'inverse de la matrice $A$, si elle existe." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "A = [[1,2,-1],[2,-1,-1],[1,-2,1]]\n", "b = [[1], [-2], [1]]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "scrolled": true + "scrolled": false }, "outputs": [], "source": [ "print('Vous allez échelonner la matrice augmenteé')\n", "al.printAAug(A,b)\n", "[i,j,r,alpha]= al.manualEch(A,b)\n", "MatriceList=[np.array(A)]\n", "RHSList = [np.array(b)]\n", "m=np.concatenate((A,b), axis=1)\n", "print('\\033[1mExecutez la ligne suivante pour effectuer l\\'opération choisie \\033[0m')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "m=al.echelonnage(i, j, r, alpha, A, m, MatriceList, RHSList)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "scrolled": true + "scrolled": false }, "outputs": [], "source": [ "I=[[1,0,0],[0,1,0],[0,0,1]]\n", "print('Vous allez échelonner la matrice augmenteé avec la matrice identité')\n", "al.printA(A,I)\n", "[i,j,r,alpha]= al.manualEch(A,I)\n", "m=np.concatenate((A,I), axis=1)\n", "MatriceList=[A]\n", "RhSList=[I]\n", "print('\\033[1mExecutez la ligne suivante pour effectuer l\\'opération choisie \\033[0m')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "m=al.echelonnage(i,j,r,alpha,A,m,MatriceList,RhSList)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### EXERCICE 2\n", "\n", "Considérez le système linéaire $Ax = b$ avec:\n", "\\begin{equation}\n", "A = \n", "\\begin{pmatrix}\n", "1 & 3 & 2\\\\\n", "0 & 4 & 1\\\\\n", "1 & -5 & 0\n", "\\end{pmatrix}\n", "\\qquad b=\n", "\\begin{pmatrix}\n", "3\\\\\n", "5\\\\\n", "\\alpha\n", "\\end{pmatrix}\n", "\\end{equation}\n", "Laquelle des affirmations suivantes est correcte?" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "139dbe3fd62f4a23a67d441e6ac74ee2", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(Checkbox(value=False, description='Le système admet une solution unique seulement si $\\\\…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ - "corrections.Ex2Chapitre2_4()\n", - "#How is 2 chosen? as when row reduced we obtain alpha=-7 as a condition for consistency? and therefore infinite number of sol? \n", - "#I mean 2 and -7 are \"too different\" \n" + "corrections.Ex2Chapitre2_4()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[Passez au notebook 2.5: Matrices élémentaires](2.5%20Matrices%20élémentaires.ipynb)" ] } ], "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.9" + "version": "3.7.4" } }, "nbformat": 4, "nbformat_minor": 4 }