diff --git "a/Chapitre 2 - Algebre matricielle/2.11 D\303\251composition en blocs.ipynb" "b/Chapitre 2 - Algebre matricielle/2.11 D\303\251composition en blocs.ipynb" index a13f1b7..afbb994 100644 --- "a/Chapitre 2 - Algebre matricielle/2.11 D\303\251composition en blocs.ipynb" +++ "b/Chapitre 2 - Algebre matricielle/2.11 D\303\251composition en blocs.ipynb" @@ -1,438 +1,438 @@ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Concept(s)-clé(s) et théorie\n", "\n", "## DÉFINITION:\n", "Soit $A$ une matrice de taille $m \\times n$ à coefficients réels. Une décomposition par blocs de $A$ est une manière de partitionner cette dernière matrice en plus petites matrices, que l'on obtient en traçant des lignes verticales et horizontales dans la matrice.\n", "\n", "## EXEMPLE\n", "Étant donné une matrice $A \\in \\mathcal{M}_{3 \\times 3}(\\mathbb{R})$, des exemples de sa décomposition en blocs sont les suivants:\n", "\n", "$$\n", "A_1 = \n", "\\left(\\begin{array}{@{}c|cc@{}}\n", "a_{11} & a_{12} & a_{13} \\\\\n", "a_{21} & a_{22} & a_{23} \\\\\\hline\n", "a_{31} & a_{32} & a_{33}\n", "\\end{array}\\right) \\quad\n", "A_2 = \n", "\\left(\\begin{array}{@{}ccc@{}}\n", "a_{11} & a_{12} & a_{13} \\\\\\hline\n", "a_{21} & a_{22} & a_{23} \\\\\n", "a_{31} & a_{32} & a_{33}\n", "\\end{array}\\right) \\quad\n", "A_3 = \n", "\\left(\\begin{array}{@{}cc|c@{}}\n", "a_{11} & a_{12} & a_{13} \\\\\n", "a_{21} & a_{22} & a_{23} \\\\\n", "a_{31} & a_{32} & a_{33}\n", "\\end{array}\\right) \\quad\n", "A_4 = \n", "\\left(\\begin{array}{@{}c|c|c@{}}\n", "a_{11} & a_{12} & a_{13} \\\\\\hline\n", "a_{21} & a_{22} & a_{23} \\\\\\hline\n", "a_{31} & a_{32} & a_{33}\n", "\\end{array}\\right) \\quad\n", "$$\n", "\n", "En général, une matrice de taille $m \\times n$ peut être décomposée en blocs de différentes manières $2^{m-1}2^{n-1}$.\n", "\n", "\n", "## PROPRIÉTÉS\n", "### Lemma 1: addition par blocs ###\n", "Soient $A,B \\in \\mathcal{M}_{m \\times n}(\\mathbb{R})$ deux matrices décomposées en matrices par blocs de la même façon, alors on peut additionner $A$ et $B$ par blocs comme suit:\n", "\n", "$$\n", "A = \n", "\\left(\\begin{array}{@{}c|c|c@{}}\n", "A_{11} & \\cdots & A_{1Q} \\\\\\hline\n", "\\vdots & \\ddots & \\vdots \\\\\\hline\n", "A_{P1} & \\cdots & A_{PQ} \\\\\n", "\\end{array}\\right) \\quad\n", "B = \n", "\\left(\\begin{array}{@{}c|c|c@{}}\n", "B_{11} & \\cdots & B_{1Q} \\\\\\hline\n", "\\vdots & \\ddots & \\vdots \\\\\\hline\n", "B_{P1} & \\cdots & B_{PQ} \\\\\n", "\\end{array}\\right)\n", "\\quad \\Longrightarrow \\quad\n", "A+B = \n", "\\left(\\begin{array}{@{}c|c|c@{}}\n", "A_{11}+B_{11} & \\cdots & A_{1Q}+B_{1Q} \\\\\\hline\n", "\\vdots & \\ddots & \\vdots \\\\\\hline\n", "A_{P1}+B_{P1} & \\cdots & A_{PQ}+B_{PQ} \\\\\n", "\\end{array}\\right) \\quad\n", "$$\n", "\n", "### Lemma 2: multiplication par un scalaire par blocs ###\n", "Soit $A \\in \\mathcal{M}_{m \\times n}(\\mathbb{R})$ un matrice decomposée en matrices par blocs. Alors il est possible de multiplier $A$ par un scalaire, simplement en multipliant chaque bloc de $A$ par un tel scalaire.\n", "C'est à dire:\n", "$$\n", "A = \n", "\\left(\\begin{array}{@{}c|c|c@{}}\n", "A_{11} & \\cdots & A_{1Q} \\\\\\hline\n", "\\vdots & \\ddots & \\vdots \\\\\\hline\n", "A_{P1} & \\cdots & A_{PQ} \\\\\n", "\\end{array}\\right), \\quad \\lambda \\in \\mathbb{R}\n", "\\quad \\Longrightarrow \\quad\n", "\\lambda A = \n", "\\left(\\begin{array}{@{}c|c|c@{}}\n", "\\lambda A_{11} & \\cdots & \\lambda A_{1Q} \\\\\\hline\n", "\\vdots & \\ddots & \\vdots \\\\\\hline\n", "\\lambda A_{P1} & \\cdots & \\lambda A_{PQ} \\\\\n", "\\end{array}\\right)\n", "$$\n", "\n", "### Lemma 3: multiplication matricielle par blocs ###\n", "Soient $A \\in \\mathcal{M}_{m \\times n}(\\mathbb{R}), B \\in \\mathcal{M}_{n \\times p}(\\mathbb{R})$ deux matrices décomposées en matrices par blocs telles que:\n", "- le nombre de blocs dans chaque ligne de la matrice A est égal au nombre de blocs dans chaque colonne de la matrice B \n", "- le nombre de colonnes de chaque bloc $A_{ik}$ soit égal au nombre de lignes de chaque bloc $B_{kj}$.\n", "Alors on peut multiplier $A$ et $B$ par blocs comme suit:\n", "\n", "$$\n", "A = \n", "\\left(\\begin{array}{@{}c|c|c@{}}\n", "A_{11} & \\cdots & A_{1Q} \\\\\\hline\n", "\\vdots & \\ddots & \\vdots \\\\\\hline\n", "A_{P1} & \\cdots & A_{PQ} \\\\\n", "\\end{array}\\right) \\quad\n", "B = \n", "\\left(\\begin{array}{@{}c|c|c@{}}\n", "B_{11} & \\cdots & B_{1R} \\\\\\hline\n", "\\vdots & \\ddots & \\vdots \\\\\\hline\n", "B_{Q1} & \\cdots & B_{QR} \\\\\n", "\\end{array}\\right)\n", "\\quad \\Longrightarrow \\quad\n", "AB = \n", "\\left(\\begin{array}{@{}c|c|c@{}}\n", "\\sum\\limits_{i=0}^Q A_{1i}B_{i1} & \\cdots & \\sum\\limits_{i=0}^Q A_{1i}B_{iQ} \\\\\\hline\n", "\\vdots & \\ddots & \\vdots \\\\\\hline\n", "\\sum\\limits_{i=0}^Q A_{Pi}B_{i1} & \\cdots & \\sum\\limits_{i=0}^Q A_{Pi}B_{iQ} \\\\\n", "\\end{array}\\right) \\quad\n", "$$\n", "\n", "### Lemma 4 ###\n", "Soit $A \\in \\mathcal{M}_{n \\times n}(\\mathbb{R})$ une matrice carrée, decomposée en blocs $\\left(\\begin{array}{@{}c|c@{}} A_{11} & A_{12} \\\\\\hline 0 & A_{22} \\\\ \\end{array}\\right)$, avec $A_{11} \\in \\mathcal{M}_{r \\times r}(\\mathbb{R})$, $A_{22} \\in \\mathcal{M}_{s \\times s}(\\mathbb{R})$ et $r+s=n$. Si $A_{11}$ et $A_{22}$ sont inversibles, alors $A$ l'est egalment et sont inverse est:\n", "\n", "$$\n", "A^{-1} = \n", "\\left(\\begin{array}{@{}c|c@{}}\n", "A_{11}^{-1} & -A_{11}^{-1}A_{12}A_{22}^{-1} \\\\\\hline\n", "0 & A_{22}^{-1}\n", "\\end{array}\\right)\n", "$$\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import Librairie.AL_Fct as al\n", "import Corrections.corrections as corrections\n", "from ipywidgets import interact_manual\n", "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## EXERCICE 1\n", "Pour chacun des couples de matrices decomposée en blocs suivantes, déterminez s'ils peuvent être additionnés, multipliés, additionnés par blocs et multipliés par blocs.\n", "\n", "$$\n", "A_1 = \n", "\\left(\\begin{array}{@{}c|cc@{}}\n", "a_{11} & a_{12} & a_{13} \\\\\n", "a_{21} & a_{22} & a_{23} \\\\\\hline\n", "a_{31} & a_{32} & a_{33}\n", "\\end{array}\\right) \\quad\n", "B_1 = \n", "\\left(\\begin{array}{@{}c|cc@{}}\n", "b_{11} & b_{12} & b_{13} \\\\\n", "b_{21} & b_{22} & b_{23} \\\\\\hline\n", "b_{31} & b_{32} & b_{33}\n", "\\end{array}\\right) \\qquad\n", "A_2 = \n", "\\left(\\begin{array}{@{}c|cc@{}}\n", "a_{11} & a_{12} & a_{13} \\\\\n", "a_{21} & a_{22} & a_{23} \\\\\\hline\n", "a_{31} & a_{32} & a_{33}\n", "\\end{array}\\right) \\quad\n", "B_2 = \n", "\\left(\\begin{array}{@{}cc|c@{}}\n", "b_{11} & b_{12} & b_{13} \\\\\\hline\n", "b_{21} & b_{22} & b_{23} \\\\\n", "b_{31} & b_{32} & b_{33}\n", "\\end{array}\\right) \\\\\n", "A_3 = \n", "\\left(\\begin{array}{@{}cc|cc@{}}\n", "a_{11} & a_{12} & a_{13} & a_{14} \\\\\n", "a_{21} & a_{22} & a_{23} & a_{24} \\\\\\hline\n", "a_{31} & a_{32} & a_{33} & a_{34}\n", "\\end{array}\\right) \\quad\n", "B_3 = \n", "\\left(\\begin{array}{@{}cc@{}}\n", "b_{11} & b_{12} \\\\\n", "b_{21} & b_{22} \\\\\\hline\n", "b_{31} & b_{32} \\\\\n", "b_{41} & b_{42}\n", "\\end{array}\\right) \\qquad\n", "A_4 = \n", "\\left(\\begin{array}{@{}c|cc@{}}\n", "a_{11} & a_{12} & a_{13} \\\\\n", "a_{21} & a_{22} & a_{23} \\\\\n", "a_{31} & a_{32} & a_{33} \\\\\n", "a_{41} & a_{42} & a_{43}\n", "\\end{array}\\right) \\quad\n", "B_4 = \n", "\\left(\\begin{array}{@{}cc|c@{}}\n", "b_{11} & b_{12} & b_{13} \\\\\n", "b_{21} & b_{22} & b_{23} \\\\\\hline\n", "b_{31} & b_{32} & b_{33}\n", "\\end{array}\\right)\n", "$$" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "corrections.Ex1Chapitre2_11()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## EXERCICE 2\n", "Considérez les matrices suivantes\n", "\n", "$$\n", "A = \n", "\\left(\\begin{array}{@{}ccccc@{}}\n", "a_{11} & a_{12} & a_{13} & a_{14} & a_{15} \\\\\n", "a_{21} & a_{22} & a_{23} & a_{24} & a_{25} \\\\\n", "a_{31} & a_{32} & a_{33} & a_{34} & a_{35} \\\\\n", "a_{41} & a_{42} & a_{43} & a_{44} & a_{45}\n", "\\end{array}\\right) \\quad\n", "B = \n", "\\left(\\begin{array}{@{}cc|c@{}}\n", "b_{11} & b_{12} & b_{13} \\\\\n", "b_{21} & b_{22} & b_{23} \\\\\\hline\n", "b_{31} & b_{32} & b_{33} \\\\\n", "b_{41} & b_{42} & b_{43} \\\\\\hline\n", "b_{51} & b_{52} & b_{53}\n", "\\end{array}\\right)\n", "$$\n", "\n", "Déterminez combien de façons différentes de décomposer $A$ en blocs existent, afin qu'il puisse être post-multiplié par blocs par $B$." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "corrections.Ex2Chapitre2_11()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## EXERCICE 3\n", "Consider the following couples of matrices. Compute their multiplication by blocks, if possible.\n", "\n", "1. $$\n", " A_1 = \n", " \\left(\\begin{array}{@{}c|cc@{}}\n", " 1 & 3 & 1 \\\\\n", " 0 & 0 & -1 \\\\\\hline\n", " 0 & -1 & -2\n", " \\end{array}\\right) \\qquad\n", " B_1 = \n", " \\left(\\begin{array}{@{}c|cc@{}}\n", " 1 & 0 & 2 \\\\\n", " 4 & 0 & 1 \\\\\\hline\n", " 0 & -1 & -1\n", " \\end{array}\\right) \n", " $$\n", " \n", "2. $$\n", " A_2 = \n", " \\left(\\begin{array}{@{}c|cc@{}}\n", " 0 & 1 & 2 \\\\\n", " 0 & 0 & -2 \\\\\\hline\n", " 2 & 1 & 1\n", " \\end{array}\\right) \\qquad\n", " B_2 = \n", " \\left(\\begin{array}{@{}cc|c@{}}\n", " 0 & 0 & 1 \\\\\\hline\n", " 3 & 2 & -1 \\\\\n", " -2 & -3 & 1\n", " \\end{array}\\right)\n", " $$\n", " \n", "3. $$\n", " A_3 = \n", " \\left(\\begin{array}{@{}cc|cc|c@{}}\n", " 1 & -1 & 2 & -1 & 0 \\\\\n", " -1 & 1 & -3 & 2 & 0 \\\\\\hline\n", " 0 & 0 & 1 & -1 & 4 \\\\\n", " 0 & 0 & -1 & 1 & -2\n", " \\end{array}\\right) \\qquad\n", " B_3 = \n", " \\left(\\begin{array}{@{}cc|c@{}}\n", " 0 & 0 & 1 \\\\\n", " 0 & 0 & -1 \\\\\\hline\n", " 2 & 3 & 0 \\\\\n", " -2 & -1 & 0 \\\\\\hline\n", " 0 & 2 & 2\n", " \\end{array}\\right)\n", " $$" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Insérez ici les valeurs des matrices que vous avez calculées.\n", "# Si la multiplication par blocs n'est pas possible, laissez la matrice vide (Cn = [[ ]])\n", "\n", "C1 = [[0]]\n", "C2 = [[0]]\n", "C3 = [[0]]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "corrections.Ex3Chapitre2_11(C1, C2, C3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## EXERCICE 4\n", "Considérez les matrices suivantes\n", "\n", "$$\n", "A_1 = \n", "\\left(\\begin{array}{@{}ccc|cc@{}}\n", "1 & 2 & 0 & 1 & 0 \\\\\n", "0 & -2 & 1 & -1 & 0 \\\\\n", "-2 & -1 & 1 & 0 & 1 \\\\\\hline\n", "0 & 0 & 0 &2 & 0 \\\\\n", "0 & 0 & 0 & 0 & 1\n", "\\end{array}\\right) \\qquad\n", "A_2 = \n", "\\left(\\begin{array}{@{}cc|ccc@{}}\n", "1 & 2 & 2 & 1 & -1 \\\\\n", "-1 & 0 & 0 & 1 & -2 \\\\\\hline\n", "0 & 0 & 2 & -1 & 3 \\\\\n", "0 & 0 & 1 & 1 & 2 \\\\\n", "0 & 0 & 1 & -5 & 0\n", "\\end{array}\\right)\n", "$$\n", "\n", "Déterminez leurs inverses, s'ils existent.\n", "\n", "**Aide**: profitez du lemme 4!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Vous pouvez vous aider à déterminer si les matrices suivantes sont inversibles ou non en exécutant les cellules suivantes et en calculant manuellement leurs inverses (éventuelles)**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "A=[[1,0,0], [0,1,0], [0,0,1]]\n", "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": {}, "outputs": [], "source": [ "m=al.echelonnage(i,j,r,alpha,A,m,MatriceList,RhSList)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Insérez ici les valeurs des matrices que vous avez calculées.\n", "# Si l'inverse n'existe pas, laissez la matrice vide (An_inv = [[ ]])\n", "\n", "A1_inv = [[0]]\n", "A2_inv = [[0]]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "corrections.Ex4Chapitre2_11(A1_inv, A2_inv)" ] } ], "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.4" + "version": "3.6.9" } }, "nbformat": 4, "nbformat_minor": 4 } 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 6189a09..d38f76c 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,325 +1,216 @@ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# **Concept(s)-clé(s) et théorie**\n", "\n", "## Rappel\n", "\n", "Soit une matrice $A \\in \\mathcal{M}_{m \\times n}(\\mathbb{R})$ quelconque, nous définissons les opérations élémentaires de type:\n", "* (I) échanger deux lignes de la matrice A;\n", "* (II) multiplier une ligne de la matrice A par un scalaire non nul;\n", "* (III) ajouter à une ligne de la matrice A le multiple d'une autre ligne de A.\n", "\n", "## Définition\n", "Une matrice élémentaire (de taille $m \\times m$) 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_m$ (i.e. la matrice d'identité de taille $m \\times m$). On adoptera les notations suivantes:\n", "\n", "* (I) la matrice $T_{ij}$ est la matrice obtenue en échangeant les lignes $i$ et $j$ de $I_m$;\n", "* (II) la matrice $D_r(\\lambda)$ est la matrice obtenue en multipliant la $r$-ème ligne de $I_m$ par $\\lambda \\in \\mathbb{R}$ , $\\lambda\\neq 0$;\n", "* (III) la matrice $L_{rs}(\\lambda)$ est la matrice obtenue en ajoutant $\\lambda\\in \\mathbb{R}$ fois la ligne $s$ à la ligne $r$ de $I_m$.\n", "\n", "**Remarque** Dans les matrices élémentaires de type (II) ($D_r(\\lambda)$) le scalaire $\\lambda$ **doit être différent de zéro**. Cette condition sur $\\lambda$ n'est pas nécessaire dans les matrices élémentaires de type (III).\n", "\n", "## Théorème\n", "Soient $A \\in \\mathcal{M}_{m \\times n}(\\mathbb{R})$ une matrice quelconque et $E \\in \\mathcal{M}_{m \\times m}(\\mathbb{R})$ une matrice élémentaire de type (I), (II) ou (III). Alors $EA$ est la matrice obtenue en effectuant sur les lignes de $A$ l'opération de type (I), (II) ou (III) utilisée pour former $E$.\n", "\n", "## Corollaire\n", "Les matrices élémentaires sont inversibles. En effet, on trouve facilement leur inverse respectif:\n", "* (I) $T_{ij}^{-1} = T_{ji} = T_{ij}$;\n", "* (II) $D_r(\\lambda)^{-1} = D_r(\\lambda^{-1})$;\n", "* (III)$L_{rs}(\\lambda)^{-1} = L_{rs}(-\\lambda)$;" ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - " \n", - " " - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - " \n", - " " - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "import Librairie.AL_Fct as al\n", "import Corrections.corrections as corrections\n", "import numpy as np\n", "from numpy.linalg import *\n", "from ipywidgets import interact_manual" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercice 1\n", "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", "**ÉTAPE 1**: Laquelle des affirmations ci-dessous est correcte?\n" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "8edb8a177211473ca6bfcad2adaec45f", - "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" - } - ], + "outputs": [], "source": [ "corrections.Ex1aChapitre2_5()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**ÉTAPE 2**: Donner l'inverse de $E_1E_2$\n", "\n", "**Aide** \n", "Considérez deux matrices inversibles $A, B \\in M_{n \\times n}(\\mathbb{R})$; alors $$(AB)^{- 1}=B^{- 1}A^{- 1}$$\n", "\n", "*Observation*: Inverser l'effet de $n$ opérations élémentaires consécutives consiste à appliquer l'inverse de chaque opération, de la dernière à la première." ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "La matrice inverse entrée est\n" - ] - }, - { - "data": { - "text/latex": [ - "$\\left(\\begin{array}{cccc} 1 & 0 & 0 & 0 \\\\0 & 1 & 0 & 0 \\\\0 & 0 & 1 & 0 \\\\0 & 0 & 0 & 1 \\end{array}\\right)$" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "C'est faux." - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "#Insérez ci-dessous la valeur de la matrice inverse\n", "inverse= [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]\n", "\n", "print('La matrice inverse entrée est')\n", "al.printA(inverse)\n", "corrections.Ex1bChapitre2_5(inverse)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercice 2\n", "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 & -10\\\\\n", "-10 & 5 & 20\n", "\\end{pmatrix}\n", "$$" ] }, { "cell_type": "code", - "execution_count": 8, + "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, -10],[-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}(\\mu)$\n", "$$\n", "L_{rs}(\\mu) \\cdot D_{r}(\\lambda)\\cdot T_{ij}\\cdot A =B\n", "$$\n", "\n", "**ÉTAPE 1**: Trouvez les 3 matrices et insérez-les ci-dessous." ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "T=[[0,0,1],[0,1,0],[1,0,0]]\n", "D=[[1,0,0],[0,1,0],[0,0,5]]\n", "L=[[1,0,0],[-4,1,0],[0,0,1]]" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/latex": [ - "C'est correct!" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "corrections.Ex2aChapitre2_5(A, B, T, D, L)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**ÉTAPE 2**: Donner l'inverse de $L_{rs}(\\mu) \\cdot D_{r}(\\lambda)\\cdot T_{ij}$" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('Insérez ici la valeur de la matrice inverse')\n", "inverse= [[1,0,0],[0,1,0],[0,0,1]]\n", "corrections.Ex2bChapitre2_5(inverse)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[Passez au notebook 2.6-7: Critéres d'inversibilité](2.6-2.7%20Critères%20d'inversibilité.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" } }, "nbformat": 4, "nbformat_minor": 4 } 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" index 0b72554..3ea28da 100644 --- "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" @@ -1,343 +1,279 @@ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# **Concept(s)-clé(s) et théorie**\n", "\n", "## PREMIER CRITÈRE D'INVERSIBILITÉ \n", "Une matrice $A \\in \\mathcal{M}_{n \\times n}(\\mathbb{R})$ est inversible si et seulement si le système homogène $Ax=0$ possède une solution unique, à savoir, la solution triviale.\n", "\n", "## COROLLAIRE DU PREMIER CRITÈRE D'INVERSIBILITÉ \n", "Soit $A \\in \\mathcal{M}_{n \\times n}(\\mathbb{R})$ alors les deux affirmations suivantes sont vérifiées.\n", "\n", "1. La matrice $A$ est inversible si et seulement s'il existe $B \\in \\mathcal{M}_{n \\times n}(\\mathbb{R})$ telle que $BA = I_n$.\n", "2. La matrice $A$ est inversible si et seulement s'il existe $C \\in \\mathcal{M}_{n \\times n}(\\mathbb{R})$ telle que $AC = I_n$.\n", "\n", "## RAPPEL: ALGORITHME POUR TROUVER L'INVERSE D'UNE MATRICE DONNÉE\n", "Soit $A \\in \\mathcal{M}_{n \\times n}(\\mathbb{R})$ une matrice carrée. Afin de déterminer si $A$ est inversible et de calculer son inverse (lorsque c'est possible), on procède comme suit :\n", "\n", "1. Ecrire les matrices $A$ et $I_n$ l'une à côté de l'autre, formant ainsi une nouvelle matrice de taille $n \\times 2n$\n", "2. Opérer sur les lignes de cette matrice ainsi obtenue, afin de réduire le côté gauche à $I_n$\n", "3. Si l'on y arrive, alors $A$ est inversible et son inverse $A^{-1}$ est donnée par la matrice à droite." ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - " \n", - " " - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - " \n", - " " - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "import Librairie.AL_Fct as al\n", "import Corrections.corrections as corrections\n", "from ipywidgets import interact_manual\n", "import plotly as py\n", "import plotly.graph_objs as go\n", "from ipywidgets import interactive, HBox, VBox, widgets, interact, FloatSlider\n", "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### EXERCICE 1\n", "Considérez le système linéaire générique $Ax=b$ avec $A \\in \\mathcal{M}_{n \\times n}(\\mathbb{R})$ et $b \\in \\mathcal{M}_{n \\times 1}(\\mathbb{R})$; cochez les déclarations suivantes qui pourraient être vraies pour certaines valeurs de $A$ et $b$." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "corrections.Ex1Chapitre2_6_7()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## EXERCICE 2 ##\n", "Cochez, parmi les matrices suivantes, celles qui sont inversibles.\n", "\\begin{equation}\n", "A_1 = \n", "\\begin{pmatrix}\n", "2 & 0 & 1\\\\\n", "0 & 6 & 4 \\\\\n", "2 & 2 & 1\n", "\\end{pmatrix} \\qquad A_2 = \n", "\\begin{pmatrix}\n", "3 & -7 & 0\\\\\n", "1 & 0 & 1\\\\\n", "-5 & 35/3 & 0\n", "\\end{pmatrix} \\qquad A_3 = \n", "\\begin{pmatrix}\n", "2 & 1 & -1\\\\\\\n", "2 & -5 & 4\\\\\n", "6 & -3 & 2\n", "\\end{pmatrix}\n", "\\end{equation}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "corrections.Ex2Chapitre2_6_7()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Vous pouvez vous aider à déterminer si les matrices suivantes sont inversibles ou non en exécutant les cellules suivantes et en calculant manuellement leurs inverses (éventuelles)**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "A=[[2,0,1], [0,6,4], [2,2,1]]\n", "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": {}, "outputs": [], "source": [ "m=al.echelonnage(i,j,r,alpha,A,m,MatriceList,RhSList)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## EXERCISE 3 ##\n", "Considéz le système linéaire générique $Ax = b$, avec:\n", "\\begin{equation}\n", "A = \n", "\\begin{pmatrix}\n", "2 & -\\alpha\\\\\n", "\\beta & -4 \\\\\n", "\\end{pmatrix} \\qquad b = \n", "\\begin{pmatrix}\n", "1\\\\\n", "-2\\\\\n", "\\end{pmatrix}\n", "\\end{equation}\n", "Identifiez les valeurs des paramètres $\\alpha$ et $\\beta$ pour lesquels $A$ n'est pas inversible et cochez les déclarations suivantes qui sont correctes." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "with alpha =4 and beta=1, we have one unique sol.??why is h wrong?" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "a8e5e9d114f9457d99764e65588b44df", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(Checkbox(value=False, description=\"Si $\\\\alpha = 4$ et $\\\\beta = 2$, alors $A$ n'est pas…" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "corrections.Ex3Chapitre2_6_7()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**AIDE: vous pouvez exécuter la cellule interactive suivante pour mieux visualiser le système paramétré**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "np.seterr(divide='ignore', invalid='ignore')\n", "\n", "A=[[2, 0], [0, -4]] # we initialize the problem. The values of alpha and beta are fixed\n", "b=[1, -2]\n", "\n", "m=len(A)\n", "MatCoeff = [A[i]+[b[i]]for i in range(m)] #becomes augmented matrix\n", "MatCoeff=np.array(MatCoeff)\n", "data=[]\n", "x=np.linspace(-15,15,101)\n", "y=np.linspace(-10,10,101)\n", "MatCoeff=np.array(MatCoeff)\n", "for i in range(len(MatCoeff)):\n", " trace=go.Scatter(x=x, y= (MatCoeff[i,2]-MatCoeff[i,0]*x)/MatCoeff[i,1], name='d) Droite %d'%(i+1))\n", " data.append(trace)\n", " \n", "f=go.FigureWidget(data=data,\n", " layout=go.Layout(xaxis=dict(\n", " range=[-15, 15]\n", " ),\n", " yaxis=dict(\n", " range=[-10, 10]\n", " ) ) \n", ")\n", "\n", "def update_y(alpha, beta):\n", " MatCoeff= [[2, -alpha, 1],[beta, -4, -2]]\n", " MatCoeff=np.array(MatCoeff)\n", " if MatCoeff[0,1] == 0:\n", " MatCoeff[0,1] += 1e-3\n", " f.data[0].y = (MatCoeff[0,2]-MatCoeff[0,0]*x)/MatCoeff[0,1]\n", " if MatCoeff[1,1] == 0:\n", " MatCoeff[1,1] += 1e-3\n", " f.data[1].y=(MatCoeff[1,2]-MatCoeff[1,0]*x)/MatCoeff[1,1]\n", "\n", "freq_slider = interactive(update_y, alpha=(-20, 20, 1/2), beta=(-20, 20, 1/2))\n", "\n", "vb = VBox((f, freq_slider))\n", "vb.layout.align_items = 'center'\n", "vb" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## EXERCISE 4\n", "\n", "Considérez les matrices suivantes:\n", "\\begin{equation}\n", "A = \n", "\\begin{pmatrix}\n", "0.5 & a & 1\\\\\n", "0 & 2 & -1\\\\\n", "-2 & 1 & b\n", "\\end{pmatrix}; \\qquad B = \n", "\\begin{pmatrix}\n", "-6 & -2 & -2\\\\\n", "4 & 2 & 1\\\\\n", "8 & 3 & 2\n", "\\end{pmatrix}\n", "\\end{equation}\n", "\n", - "Trouvez les valeurs des paramètres $a$ et $b$ pour lesquels $A$ et $B$ sont l'un l'inverse de l'autre." + "Trouvez les valeurs des paramètres $a$ et $b$ pour lesquels $A$ et $B$ sont l'inverse l'une de l'autre." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "corrections.Ex4Chapitre2_6_7()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[Passez au notebook 2.8-2.9: Décomposition LU (existance et algorithm)](2.8-2.9%20Décomposition%20LU%20(existance%20et%20algorithm).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.7.4" + "version": "3.6.9" } }, "nbformat": 4, "nbformat_minor": 4 } diff --git "a/Chapitre 2 - Algebre matricielle/2.8-2.9 D\303\251composition LU (existance et algorithm).ipynb" "b/Chapitre 2 - Algebre matricielle/2.8-2.9 D\303\251composition LU (existance et algorithm).ipynb" index 9b5abf7..8f543cd 100644 --- "a/Chapitre 2 - Algebre matricielle/2.8-2.9 D\303\251composition LU (existance et algorithm).ipynb" +++ "b/Chapitre 2 - Algebre matricielle/2.8-2.9 D\303\251composition LU (existance et algorithm).ipynb" @@ -1,347 +1,355 @@ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# **Concept(s)-clé(s) et théorie**\n", "\n", "## Propriété: Opérations élémentaires sur les colonnes d'une matrice\n", "Soit $A \\in \\mathcal{M}_{m \\times n}(\\mathbb{R})$. Alors les affirmations suivantes sont vérifiées:\n", "\n", "* La matrice $AT_{ij}$ est obtenue en échangeant les colonnes $i$ et $j$ de $A$.\n", "* La matrice $AD_{r}(\\lambda)$ est obtenue en multipliant la $r$-ème colonne de $A$ par $\\lambda$.\n", "* La matrice $AL_{rs}(\\lambda)$ est obtenue en ajoutant $\\lambda$ fois la $r$-ème colonne de $A$ à la s-ème.\n", "\n", - "## Theoréme: Existance de la dècomposition LU d'une matrice\n", - "Soit $A$ une matrice de taille $m \\times n$ et supposons qu'il soit possible de réduire $A$ à une forme échelonnée en n'utilisant que des opérations élémentaires de la forme $D_r(\\lambda), L_{rs}(\\lambda)$ (avec $r>s$) sur les lignes de $A$. Alors il existe une matrice triangulaire inférieure $L$ et une matrice triangulaire supérieure $U$ telles que $A=LU$.\n", + "**Remarque** En multipliant une matrice $A$ par la gauche par une matrice élémentaire $E$ on modifie les lignes, et par la droite les colonnes. En général on a\n", "\n", - "## Algorithme: Trouver L et U dans la dècomposition LU d'une matrice\n", + "\\begin{align*}\n", + "&EA & &\\neq & &AE\\\\\n", + "\\nearrow& & & & &\\nwarrow\\\\\n", + "\\text{Opération sur les lignes}& & & & & \\text{Opérations sur les colonnes} \n", + "\\end{align*}\n", + "\n", + "## Théorème: Existance de la décomposition LU d'une matrice\n", + "Soit $A$ une matrice de taille $m \\times n$ et supposons qu'il soit possible de réduire $A$ à une forme échelonnée en n'utilisant que des opérations élémentaires de la forme $D_r(\\lambda), L_{rs}(\\lambda)$, avec $r>s$, sur les lignes de $A$. Alors il existe une matrice triangulaire inférieure $L$ ($n\\times n$) et une matrice échelonnée $U$ ($m\\times n$) telles que $A=LU$.\n", + "\n", + "## Algorithme: Trouver L et U dans la décomposition LU d'une matrice\n", "Soit $A$ une matrice admettant une décomposition $LU$. Afin de déterminer les matrices $L$ et $U$ dans une telle décomposition, on procède comme suit:\n", "\n", - "1. On applique successivement les opérations élémentaires de types **(II)** (i.e. $D_{r}(\\lambda)$) et **(III)** (i.e. $L_{rs}(\\lambda)$), avec matrices élémentaires correspondantes $E_1, E_2, \\dots, E_k$, aux lignes de la matrice $A$ afin de la rendre échelonnée.\n", + "1. On applique successivement les opérations élémentaires de types **(II)** (i.e. $D_{r}(\\lambda)$ avec $\\lambda\\neq 0$) et **(III)** (i.e. $L_{rs}(\\lambda)$), avec matrices élémentaires correspondantes $E_1, E_2, \\dots, E_k$, aux lignes de la matrice $A$ afin de la rendre échelonnée.\n", "2. On pose $U = E_k \\dots E_1A$, c'est-à-dire $U$ est la forme échelonnée de $A$ obtenue à l'aide des opérations élémentaires ci-dessus.\n", "3. La matrice $L$ est alors obtenue en opérant sur les colonnes de $I_n$ par $E_1^{-1} \\dots E_k^{-1}$, dans cet ordre." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import Librairie.AL_Fct as al\n", "import Corrections.corrections as corrections\n", "from ipywidgets import interact_manual\n", "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercice 1\n", "\n", "Considérez la matrice suivante:\n", "\n", "\\begin{equation}\n", "A = \n", "\\begin{pmatrix}\n", "2 & 0 & 4 & 2 \\\\\n", "3 & 0 & -1 & 0 \\\\\n", "0 & 2 & -2 & 1 \\\\\n", "1 & 1 & 0 & -2\n", "\\end{pmatrix}\n", "\\end{equation}\n", "\n", - "Insérez les valeurs des matrices élémentaires par lesquelles $A$ doit être pré et post multiplié afin d'obtenir chacune des matrices suivantes.\n", + "Insérez les valeurs des matrices élémentaires par lesquelles $A$ doit être multipliée à gauche et à droite afin d'obtenir chacune des matrices suivantes.\n", "\n", "\\begin{equation}\n", "A_1 = \n", "\\begin{pmatrix}\n", "4 & 0 & 4 & 2 \\\\\n", "3 & 0 & -1 & 0 \\\\\n", "1 & 2 & -2 & 1 \\\\\n", - "-1 & 1 & 0 & 2\n", + "-1 & 1 & 0 & -2\n", "\\end{pmatrix}\n", "\\quad A_2 = \n", "\\begin{pmatrix}\n", "2 & 0 & 2 & -2 \\\\\n", "0 & 2 & -1 & -1 \\\\\n", "3 & 0 & -0.5 & 0 \\\\\n", "1 & 1 & 0 & 2\n", "\\end{pmatrix}\n", "\\quad A_3 = \n", "\\begin{pmatrix}\n", "2 & 0 & 4 & -6 \\\\\n", "3 & 0 & -1 & 2 \\\\\n", "0 & 2 & -2 & 5 \\\\\n", - "1 & 1 & 0 & 2\n", + "-1 & -1 & 0 & 2\n", "\\end{pmatrix}\n", "\\quad A_4 = \n", "\\begin{pmatrix}\n", "1 & 0 & 2 & -1 \\\\\n", "3 & 0 & -1 & 0 \\\\\n", "0 & 2 & 0 & -1 \\\\\n", "1 & 1 & 1 & 2\n", "\\end{pmatrix}\n", "\\end{equation}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# MATRIX A1\n", - "E_pre_1 = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]]\n", - "E_post_1 = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]]\n", + "E_gauche_1 = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]]\n", + "E_droite_1 = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]]\n", "\n", "# MATRIX A2\n", - "E_pre_2 = [[1,0,0,0], [0,0,1,0], [0,1,0,0], [0,0,0,1]]\n", - "E_post_2 = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]]\n", + "E_gauche_2 = [[1,0,0,0], [0,0,1,0], [0,1,0,0], [0,0,0,1]]\n", + "E_droite_2 = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]]\n", "\n", "# MATRIX A3\n", - "E_pre_3 = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]]\n", - "E_post_3 = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]]\n", + "E_gauche_3 = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]]\n", + "E_droite_3 = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]]\n", "\n", "# MATRIX A4\n", - "E_pre_4 = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]]\n", - "E_post_4 = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]]" + "E_gauche_4 = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]]\n", + "E_droite_4 = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "corrections.Ex1Chapitre2_8_9([E_pre_1, E_post_1],\n", - " [E_pre_2, E_post_2], \n", - " [E_pre_3, E_post_3], \n", - " [E_pre_4, E_post_4])" + "corrections.Ex1Chapitre2_8_9([E_gauche_1, E_droite_1],\n", + " [E_gauche_2, E_droite_2], \n", + " [E_gauche_3, E_droite_3], \n", + " [E_gauche_4, E_droite_4])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercice 2\n", "\n", "Pour chacune des matrices suivantes appartenant à $\\mathcal{M}_{4 \\times 4}(\\mathbb{R})$, déterminez si elles admettent ou non une décomposition LU.\n", "\n", "\\begin{equation}\n", "A_1 = \n", "\\begin{pmatrix}\n", "2 & -1 & -4 & 0 \\\\\n", "-1 & 2 & 0 & 3 \\\\\n", "3 & 1 & -3 & 5 \\\\\n", "1 & -3 & -5 & -5\n", "\\end{pmatrix}\n", "\\quad A_2 = \n", "\\begin{pmatrix}\n", "3 & 2 & 1 & -1 \\\\\n", "0 & -1 & 1 & -2 \\\\\n", "2 & -3 & 2 & 0 \\\\\n", "1 & 0 & 0 & -1 \n", "\\end{pmatrix}\n", "\\quad A_3 = \n", "\\begin{pmatrix}\n", "1 & 0 & -1 & 2 \\\\\n", "0 & 2 & -1 & 1 \\\\\n", "0 & -4 & 2 & 3 \\\\\n", "2 & 3 & -1 & -1\n", "\\end{pmatrix}\n", "\\end{equation}\n", "\n", "\n", "**Exécutez les cellules suivantes pour effectuer la méthode d'élimination de Gauss sur les 3 matrices**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "A=[[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]] # INSEREZ ICI LA VALEUR DE LA MATRICE!!\n", + "A=[[2,-1,-4,0], [-1,2,0,3], [3,1,-3,5], [1, -3,-5,-5]] # INSEREZ ICI LA VALEUR DE LA MATRICE!!\n", "print('Vous allez échelonner la matrice A')\n", "[i,j,r,alpha]= al.manualEch(A)\n", "m=np.array(A)\n", "MatriceList=[A]\n", "print('\\033[1mExecutez la ligne suivante pour effectuer l\\'opération choisie \\033[0m')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m=al.echelonnage(i,j,r,alpha,A,m,MatriceList)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "corrections.Ex3Chapitre2_8_9()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercice 3\n", "\n", "Considérez la matrice carrée $A \\in \\mathcal{M}_{3 \\times 3}(\\mathbb{R})$ suivante:\n", "\n", "\\begin{equation}\n", "A = \n", "\\begin{pmatrix}\n", "2 & 0 & 1 \\\\\n", "0 & 6 & 4 \\\\\n", "2 & 2 & 1\n", "\\end{pmatrix}\n", "\\end{equation}\n", "\n", "En utilisant la la méthode d'élimination de Gauss, calculez, si possible, la décomposition LU de $A$. Profitez des cellules interactives suivantes et comprenez, à chaque passage, comment ont été dérivées $L$ et $U$." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "A=[[2,0,1], [0,6,4], [2,2,1]]\n", "print('Vous allez échelonner la matrice A')\n", "al.printA(A)\n", "[i,j,r,alpha]= al.manualEch(A)\n", "LList = [np.eye(3)]\n", "UList=[np.array(A).astype(float)]\n", "print('\\033[1mExecutez la ligne suivante pour effectuer l\\'opération choisie \\033[0m')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m=al.LU_interactive(i,j,r,alpha, LList, UList)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Exécutez la cellule suivante pour calculer les valeurs corrects de $ L $ et $ U $ et comparez-les à celles que vous venez de dériver**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "L_ref, U_ref = al.LU_no_pivoting(A)\n", "al.printA(L_ref, name='L')\n", "al.printA(U_ref, name='U')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercice 4\n", "\n", "Considérez la matrice rectangulaire $B \\in \\mathcal{M}_{3 \\times 4}(\\mathbb{R})$ (**représentant un système linéaire sous-déterminé**) suivante:\n", "\n", "\\begin{equation}\n", "B = \n", "\\begin{pmatrix}\n", "-1 & 2 & 0 & 3 \\\\\n", "-1 & 0 & 2 & 4 \\\\\n", "0 & -2 & 1 & 1\n", "\\end{pmatrix}\n", "\\end{equation}\n", "\n", "En utilisant la la méthode d'élimination de Gauss, calculez, si possible, la décomposition LU de $A$. Profitez des cellules interactives suivantes et comprenez, à chaque passage, comment ont été dérivées $L$ et $U$." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "B=[[-1,2,0,3], [-1,0,2,4], [0,-2,1,1]]\n", "print('Vous allez échelonner la matrice A')\n", "al.printA(B)\n", "[i,j,r,alpha]= al.manualEch(B)\n", "LList = [np.eye(3)]\n", "UList=[np.array(B).astype(float)]\n", "print('\\033[1mExecutez la ligne suivante pour effectuer l\\'opération choisie \\033[0m')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m=al.LU_interactive(i,j,r,alpha, LList, UList)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Exécutez la cellule suivante pour calculer les valeurs corrects de $ L $ et $ U $ et comparez-les à celles que vous venez de dériver**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "L_ref, U_ref = al.LU_no_pivoting(B)\n", "al.printA(L_ref, name='L')\n", "al.printA(U_ref, name='U')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[Passez au notebook 2.10: Décomposition LU (applications au systèmes linéaires)](2.10%20Décomposition%20LU%20(applications%20aux%20systèmes%20linéaires).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.7.4" } }, "nbformat": 4, "nbformat_minor": 4 } diff --git a/Chapitre 2 - Algebre matricielle/Corrections/corrections.py b/Chapitre 2 - Algebre matricielle/Corrections/corrections.py index 3916260..44d33e4 100644 --- a/Chapitre 2 - Algebre matricielle/Corrections/corrections.py +++ b/Chapitre 2 - Algebre matricielle/Corrections/corrections.py @@ -1,1228 +1,1228 @@ import sys sys.path.insert(0, './../') import numpy as np import plotly plotly.offline.init_notebook_mode(connected=True) import ipywidgets as widgets from IPython.display import display, Latex from ipywidgets import interact_manual, Layout from Librairie.AL_Fct import printA, texMatrix, isDiag, isSym def Ex2Chapitre2_1(): """Provides the correction of exercise 2 of notebook 2_1 """ a = widgets.Checkbox( value=False, description=r'Il existe \(\lambda\in \mathbb{R}\) tel que \((A-\lambda B)^T\) soit échelonnée réduite', disabled=False, layout=Layout(width='80%', height='30px') ) b = widgets.Checkbox( value=False, description=r'Il existe \(\lambda\in \mathbb{R}\) tel que \((A-\lambda B)^T\) soit échelonnée (mais pas réduite)', disabled=False, layout=Layout(width='80%', height='30px') ) c = widgets.Checkbox( value=False, description=r"Il n'existe pas de \(\lambda\in \mathbb{R}\) tel que \((A-\lambda B)^T\) soit échelonnée", disabled=False, layout=Layout(width='80%', height='30px') ) def correction(a, b, c): if a and not c and not b: display(Latex("C'est correct! Pour $\lambda=-3$ La matrice échelonnée réduite est:")) A = [[1, 0, -2, 3], [0, 1, -1, 7]] printA(A) else: display(Latex("C'est faux.")) interact_manual(correction, a=a, b=b, c=c) return def Ex3Chapitre2_1(): """Provides the correction of exercise 3 of notebook 2_1 """ a = widgets.Checkbox( value=False, description=r'\(C_{32}\) vaut -14', disabled=False, layout=Layout(width='80%', height='30px') ) b = widgets.Checkbox( value=False, description=r'\(C_{32}\) vaut 14', disabled=False, layout=Layout(width='80%', height='30px') ) c = widgets.Checkbox( value=False, description=r'\(C_{32}\) vaut -10', disabled=False, layout=Layout(width='80%', height='30px') ) d = widgets.Checkbox( value=False, description=r"\(C_{32}\) n'existe pas", disabled=False, layout=Layout(width='80%', height='30px') ) def correction(a, b, c, d): if c and not a and not b and not d: display(Latex("C'est correct! La matrice C vaut:")) C = [[-6, 64], [-32, -22], [28, -10], [-2, 6]] printA(C) else: display(Latex("C'est faux.")) interact_manual(correction, a=a, b=b, c=c, d=d) return def Ex1Chapitre2_2(): """Provides the correction of exercise 1 of notebook 2_2 """ a = widgets.Checkbox( value=False, description=r'Le produit $AB$ vaut:
' r'\begin{equation*} \qquad AB = \begin{pmatrix}-1 & 4\\-3& -3\\2 & 0\end{pmatrix}\end{equation*}', disabled=False, layout=Layout(width='100%', height='110px') ) b = widgets.Checkbox( value=False, description=r'Le produit $AB$ vaut:
' r'\begin{equation*} \qquad AB =\begin{pmatrix}-1 & 8\\-3& 3\\-2 & 4\end{pmatrix}\end{equation*}', disabled=False, layout=Layout(width='100%', height='110px') ) c = widgets.Checkbox( value=False, description=r'Le produit $AB$ vaut:
' r'\begin{equation*} \qquad AB =\begin{pmatrix}5 & -4\\1 & 0\end{pmatrix}\end{equation*}', disabled=False, layout=Layout(width='100%', height='90px') ) d = widgets.Checkbox( value=False, description=r"Le produit $AB$ n'est pas défini", disabled=False, layout=Layout(width='100%', height='60px') ) def correction(a, b, c, d): if b and not a and not c and not d: display(Latex("C'est correct!")) else: display(Latex("C'est faux.")) interact_manual(correction, a=a, b=b, c=c, d=d) return def Ex2Chapitre2_2(): """Provides the correction of exercise 2 of notebook 2_2 """ a = widgets.Checkbox( value=False, description=r'Le produit $AB$ appartient à $\mathcal{M}_{3 \times 3}(\mathbb{R})$', disabled=False, layout=Layout(width='80%', height='50px') ) b = widgets.Checkbox( value=False, description=r'Le produit $AB$ appartient à $\mathcal{M}_{3 \times 2}(\mathbb{R})$', disabled=False, layout=Layout(width='80%', height='50px') ) c = widgets.Checkbox( value=False, description=r'Le produit $AB$ appartient à $\mathcal{M}_{2 \times 1}(\mathbb{R})$', disabled=False, layout=Layout(width='80%', height='50px') ) d = widgets.Checkbox( value=False, description=r"$AB$ n'est pas définie", disabled=False, layout=Layout(width='80%', height='50px') ) def correction(a, b, c, d): if c and not a and not b and not d: A = [[14], [6]] texA = '$' + texMatrix(A) + '$' display(Latex(r"C'est correct! Le produit $ AB$ vaut: $AB$ = " + texA)) else: display(Latex("C'est faux.")) interact_manual(correction, a=a, b=b, c=c, d=d) return def Ex3Chapitre2_2(): """Provides the correction of exercise 3 of notebook 2_2 """ display(Latex("Insérez les valeurs de a et b")) a = widgets.FloatText( value=0.0, step=0.1, description='a:', disabled=False ) b = widgets.FloatText( value=0.0, step=0.1, description='b:', disabled=False ) display(a) display(b) def f(): A = np.array([[-1, 2], [5, -2]]) B = np.array([[-1, 1], [a.value, b.value]]) AB = np.dot(A,B) texAB = '$' + texMatrix(AB) + '$' BA = np.dot(B,A) texBA = '$' + texMatrix(BA) + '$' if a.value == 5/2 and b.value == -3/2: display(Latex(r"Correcte! Le produits $AB$ et $BA$ valent chacun: " + texAB)) else: display(Latex(r"Incorrecte! Le produit $AB$ vaut " + texAB + r"et par contre le produit " r"$BA$ vaut " + texBA + r". Entrez de nouvelles valeurs!")) interact_manual(f) return def Ex1Chapitre2_3(A, B, C): """Provides the correction to exercise 1 of notebook 2_3 :param A: original matrix :type A: list[list] or numpy.ndarray :param B: matrix such that A+B should be diagonal :type B: list[list] or numpy.ndarray :param C: matrix such that A+C should be symmetric and not diagonal :type C: list[list] or numpy.ndarray :return: :rtype: """ if not type(A) is np.ndarray: A = np.array(A) if not type(B) is np.ndarray: B = np.array(B) if not type(C) is np.ndarray: C = np.array(C) ans1 = isDiag(A+B) ans2 = isSym(A+C) and not isDiag(A+C) if ans1 and ans2: display(Latex('Correcte!')) else: display(Latex('Incorrecte! Entrez des nouvelles valeurs pur le matrices B et C!\n')) if ans1: display(Latex("A+B est bien diagonale!")) else: display(Latex("A+B est n'est pas diagonale!")) texAB = '$' + texMatrix(A+B) + '$' display(Latex(r"A+B=" + texAB)) if ans2: display(Latex("A+C est bien symétrique et non diagonale!")) elif isSym(A + C) and isDiag(A + C): display(Latex("A+C est bien symétrique mais elle est aussi diagonale!")) else: display(Latex("A + C n'est pas symétrique")) texAC = '$' + texMatrix(A + C) + '$' display(Latex(r"A+C=" + texAC)) return def Ex2Chapitre2_3(): """Provides the correction to exercise 2 of notebook 2_3 """ a = widgets.Checkbox( value=False, description=r'$(A^{-1})^T$ et $(A^T)^{-1}$ sont triangulaires supérieures mais différentes', disabled=False, layout=Layout(width='80%', height='40px') ) b = widgets.Checkbox( value=False, description=r'$(A^{-1})^T$ et $(A^T)^{-1}$ sont triangulaires inférieures mais différentes', disabled=False, layout=Layout(width='80%', height='40px') ) c = widgets.Checkbox( value=False, description=r'$(A^{-1})^T$ et $(A^T)^{-1}$ sont triangulaires inférieures et identiques', disabled=False, layout=Layout(width='80%', height='40px') ) d = widgets.Checkbox( value=False, description=r'$(A^{-1})^T$ et $(A^T)^{-1}$ sont triangulaires supérieures et identiques', disabled=False, layout=Layout(width='80%', height='40px') ) def correction(a, b, c, d): if d and not a and not c and not b: A = np.array(([-1, 0, 0], [3, 1/2, 0], [1, 2, 1])) res = np.transpose(np.linalg.inv(A)) texAres = '$' + texMatrix(res) + '$' display(Latex("C'est correct! $(A^T)^{-1}$ est donnée par: $\quad$" + texAres)) else: display(Latex("C'est faux.")) interact_manual(correction, a=a, b=b, c=c, d=d) return def Ex1Chapitre2_4(): """Provides the correction to exercise 2 of notebook 2_4 """ a = widgets.Checkbox( value=False, description=r'Le système admet une solution unique et elle est:' r'$$\qquad \qquad x = \begin{pmatrix} 1&4/3&4/3\end{pmatrix}^T$$', disabled=False, layout=Layout(width='80%', height='70px') ) b = widgets.Checkbox( value=False, description=r"Le système n'admet aucune solution", disabled=False, layout=Layout(width='80%', height='40px') ) c = widgets.Checkbox( value=False, description=r'Le système admet une solution unique et elle est:' r'$$\qquad \qquad x = \begin{pmatrix} 1&4/3&8/3\end{pmatrix}^T$$', disabled=False, layout=Layout(width='80%', height='70px') ) d = widgets.Checkbox( value=False, description=r'Le système admet plusieurs solutions', disabled=False, layout=Layout(width='80%', height='40px') ) e = widgets.Checkbox( value=False, description=r'$A$ est inversible et son inverse est:
' r'$$\qquad \qquad A^{-1} = \begin{pmatrix} 1/2&0&1/2\\1/2&-1/3&5/3\\1/2&-2/3&5/6\end{pmatrix}$$', disabled=False, layout=Layout(width='80%', height='100px') ) f = widgets.Checkbox( value=False, description=r"$A$ n'est pas inversible", disabled=False, layout=Layout(width='80%', height='40px') ) g = widgets.Checkbox( value=False, description=r'$A$ est inversible et son inverse est:' r'$$\qquad \qquad A^{-1} = \begin{pmatrix} 1/2&0&1/2\\1/2&-1/3&5/3\\1/2&-2/3&-1/2\end{pmatrix}$$', disabled=False, layout=Layout(width='80%', height='100x') ) def correction(a, b, c, d, e, f, g): if c and e and not a and not b and not d and not f and not g: display(Latex("C'est correct!")) else: display(Latex("C'est faux.")) interact_manual(correction, a=a, b=b, c=c, d=d, e=e, f=f, g=g) return def Ex2Chapitre2_4(): """Provides the correction to exercise 3 of notebook 2_4 """ a = widgets.Checkbox( value=False, description=r"Le système n'admet une solution unique que si $\alpha < 2$", disabled=False, layout=Layout(width='80%', height='40px') ) b = widgets.Checkbox( value=False, description=r"Le système n'admet une solution unique que si $\alpha \geq 2$", disabled=False, layout=Layout(width='80%', height='40px') ) c = widgets.Checkbox( value=False, description=r'Le système admet une solution unique $\forall \alpha \in \mathbb{R}$', disabled=False, layout=Layout(width='80%', height='40px') ) d = widgets.Checkbox( value=False, description=r"Le système n'admet aucune solution si $\alpha < 2$, alors qu'il admet une solution unique si " r"$\alpha \geq 2$", disabled=False, layout=Layout(width='80%', height='40px') ) e = widgets.Checkbox( value=False, description=r"Le système admet plusieurs solutions si $\alpha \neq 2$, alors qu'il admet une solution unique si" r" $\alpha = 2$", disabled=False, layout=Layout(width='80%', height='40px') ) f = widgets.Checkbox( value=False, description=r"Le système n'admet jamais une solution unique, quelle que soit $\alpha \in \mathbb{R}$", disabled=False, layout=Layout(width='80%', height='40px') ) def correction(a, b, c, d, e, f): if f and not a and not b and not c and not d and not e: display(Latex("C'est correct!")) else: display(Latex("C'est faux.")) interact_manual(correction, a=a, b=b, c=c, d=d, e=e, f=f) return def Ex1aChapitre2_5(): """Provides the correction to exercise 1a of notebook 2_5 """ a = widgets.Checkbox( value=False, description=r'\(E_1E_2\) multiplie la ligne 4 par -6 et échange les lignes 2 et 3', disabled=False, layout=Layout(width='80%', height='40px') ) b = widgets.Checkbox( value=False, description=r'\(E_1E_2\) ajoute 6 fois la ligne 4 à la ligne 2 et échange les lignes 1 et 3', disabled=False, layout=Layout(width='80%', height='40px') ) c = widgets.Checkbox( value=False, description=r'\(E_1E_2\) échange les lignes 1 et 3 et ajoute -6 fois la ligne 4 à la ligne 2', disabled=False, layout=Layout(width='80%', height='40px') ) d = widgets.Checkbox( value=False, description=r"\(E_1E_2\) ajoute -6 fois la ligne 4 à la ligne 2 et échange les lignes 1 et 2", disabled=False, layout=Layout(width='80%', height='40px') ) def correction(a, b, c, d): if c and not(a) and not(d) and not(b): display(Latex("C'est correct! Par exemple, si on applique le produit à la matrice ci-dessous")) A=[[1,-1,0,0], [0,0,0,1], [1,2,1,2], [1,0,0,1]] B=[[1,0,0,0], [0,1,0,-6], [0,0,1,0], [0,0,0,1]] C=[[0,0,1,0], [0,1,0,0], [1,0,0,0], [0,0,0,1]] BCA = np.linalg.multi_dot([B,C,A]) texA = '$' + texMatrix(A) + '$' texBCA = '$' + texMatrix(BCA) + '$' display(Latex('$\qquad A = $' + texA)) display(Latex("on obtient")) display((Latex('$\qquad \hat{A} = $' + texBCA))) else: display(Latex("C'est faux.")) interact_manual(correction,a=a,b=b,c=c,d=d) return def Ex1bChapitre2_5(inv): """Provides the correction to exercise 1b of notebook 2_5 :param inv: inverse of the matrix to be calculated :type inv: list[list] """ if inv == [[0, 0, 1, 0], [0, 1, 0, 6], [1, 0, 0, 0], [0, 0, 0, 1]]: display(Latex("C'est correct!")) else: display(Latex("C'est faux.")) return def Ex2aChapitre2_5(A, B, T, D, L): """Provides the correction to exercise 2a of notebook 2_5 :param A: starting matrix :type A: list[list] :param B: target matrix :type B: list[list] :param T: permutation (type I) matrix :type T: list[list] :param D: scalar multiplication (type II) matrix :type D: list[list] :param L: linear combination (type III) matrix :type L: list[list] """ if ~(B - np.linalg.multi_dot([L, D, T, A])).any(): display(Latex("C'est correct!")) else: display(Latex("C'est faux.")) str = 'Il faut entrer la/les matrice(s) {' if (np.asmatrix(T) - np.asmatrix([[0, 0, 1], [0, 1, 0], [1, 0, 0]])).any(): str = str + ' T, ' if (np.asmatrix(D) - np.asmatrix([[1, 0, 0], [0, 1, 0], [0, 0, 5]])).any(): str = str + ' D, ' if (np.asmatrix(L) - np.asmatrix([[1, 0, 0], [-4, 1, 0], [0, 0, 1]])).any(): str = str + ' L, ' str = str + '}. Le produit des matrices entrées vaut:' display(Latex(str)) tmp = np.linalg.multi_dot([L, D, T, A]) texM = '$' + texMatrix(tmp) + '$' display(Latex('$\qquad \hat{B} = $' + texM)) return def Ex2bChapitre2_5(inv): """Provides the correction to exercise 2b of notebook 2_5 :param inv: inverse of the matrix to be calculated :type inv: list[list] """ if inv == [[0, 0, 1/5], [4, 1, 0], [1, 0, 0]]: display(Latex("C'est correct!")) else: display(Latex("C'est faux.")) return def Ex1Chapitre2_6_7(): """Provides the correction to exercise 1 of notebook 2_6-7 """ a = widgets.Checkbox( value=False, description=r'$A^{-1}$ existe et le système admet plusieurs solutions, quelle que soit la valeur de $b$', disabled=False, layout=Layout(width='80%', height='40px') ) b = widgets.Checkbox( value=False, description=r'$A^{-1}$ existe et le système admet une solution unique ou plusieurs solutions en fonction ' r'de la valeur de $b$', disabled=False, layout=Layout(width='80%', height='40px') ) c = widgets.Checkbox( value=False, description=r'$A$ est inversible et le système admet une solution unique, quelle que soit la valeur de $b$', disabled=False, layout=Layout(width='80%', height='40px') ) d = widgets.Checkbox( value=False, description=r'$A^{-1}$ existe et le système admet au moins une solution, quelle que soit la valeur de $b$', disabled=False, layout=Layout(width='80%', height='40px') ) e = widgets.Checkbox( value=False, description=r"$A$ n'est pas inversible et le système admet une unique solution ou plusieurs solutions, " r"selon la valeur de $b$ ", disabled=False, layout=Layout(width='80%', height='40px') ) f = widgets.Checkbox( value=False, description=r"$A$ n'est pas inversible et le système admet une solution unique, " r"quelle que soit la valeur de $b$", disabled=False, layout=Layout(width='80%', height='40px') ) g = widgets.Checkbox( value=False, description=r"Le système admet une solution unique et $A$ n'est pas inversible", disabled=False, layout=Layout(width='80%', height='40px') ) h = widgets.Checkbox( value=False, description=r'Le système admet une solution unique et $A$ est inversible', disabled=False, layout=Layout(width='80%', height='40px') ) def correction(a, b, c, d, e, f, g, h): if c and d and h and not a and not b and not e and not f and not g: display(Latex("C'est correct!")) else: display(Latex("C'est faux.")) interact_manual(correction, a=a, b=b, c=c, d=d, e=e, f=f, g=g, h=h) return def Ex2Chapitre2_6_7(): """Provides the correction to exercise 2 of notebook 2_6-7 """ a = widgets.Checkbox( value=False, description=r'$A_1$ est inversible', disabled=False, layout=Layout(width='80%', height='40px') ) b = widgets.Checkbox( value=False, description=r'$A_2$ est inversible', disabled=False, layout=Layout(width='80%', height='40px') ) c = widgets.Checkbox( value=False, description=r'$A_3$ est inversible', disabled=False, layout=Layout(width='80%', height='40px') ) def correction(a, b, c): if a and not b and not c: A1 = np.array([[2, 0, 1], [0, 6, 4], [2, 2, 1]]) A1_inv = np.linalg.inv(A1) texA1inv = '$' + texMatrix(A1_inv) + '$' display(Latex("C'est correct! $A_1$ est la seule matrice inversible et son inverse est: $\quad A_1^{-1} = $" + texA1inv)) else: display(Latex("C'est faux.")) interact_manual(correction, a=a, b=b, c=c) return def Ex3Chapitre2_6_7(): """Provides the correction to exercise 3 of notebook 2_6-7 """ style = {'description_width': 'initial'} a = widgets.Checkbox( value=False, description=r"Si $\alpha = 4$ et $\beta = 2$, alors $A$ n'est pas inversible et le système linéaire " r"admet une infinité de solutions", disabled=False, style=style, layout=Layout(width='80%', height='40px') ) b = widgets.Checkbox( value=False, description=r"Si $\alpha=8$ et $\beta=-1$, alors $A$ n'est pas inversible et le système linéaire n'admet pas de" r" solutions", disabled=False, style=style, layout=Layout(width='80%', height='40px') ) c = widgets.Checkbox( value=False, description=r"Si $\alpha=-2$ et $\beta=-4$, alors $A$ n'est pas inversible et le système linéaire admet " r"une infinité de solutions", disabled=False, style=style, layout=Layout(width='80%', height='40px') ) d = widgets.Checkbox( value=False, description=r"Si $\alpha=8$ et $\beta=1$, alors $A$ n'est pas inversible et le système linéaire admet " r"une infinité de solutions", disabled=False, style=style, layout=Layout(width='80%', height='40px') ) e = widgets.Checkbox( value=False, description=r"Si $\alpha=-4$ et $\beta=-2$, alors $A$ n'est pas inversible et le système linéaire n'admet pas " r"de solutions", disabled=False, style=style, layout=Layout(width='80%', height='40px') ) f = widgets.Checkbox( value=False, description=r'Si $\alpha=4$ et $\beta=1$, alors $A$ est inversible et le système linéaire admet une infinité ' r'de solutions', disabled=False, style=style, layout=Layout(width='80%', height='40px') ) g = widgets.Checkbox( value=False, description=r'Si $\alpha=4$ et $\beta=1$, alors $A$ est inversible et le système linéaire admet une solution' r' unique', disabled=False, style=style, layout=Layout(width='80%', height='40px') ) h = widgets.Checkbox( value=False, description=r"Pour infinite de valeurs de $\alpha$ et $\beta$ $A$ n'est pas inversible, mais seulement pour l'un" r" d'eux le système admet une infinité de solutions", disabled=False, style=style, layout=Layout(width='100%', height='40px') ) def correction(a, b, c, d, e, f, g, h): if c and e and g and h and not a and not b and not d and not f: display(Latex(r"C'est correct! En effet $A$ n'est pas inversible si $\alpha = \dfrac{8}{\beta}$ (résultat " r"obtenu en divisant par élément les lignes de A les unes par les autres et en imposant que " r"les résultats des divisions soient les mêmes). De plus, si $\alpha = -2$ et $\beta = -4$, " r"alors le système admet une infinité de solutions, puisque les rapports obtenus par la " r"division est $-\dfrac{1}{2}$, qui est égal au rapport entre les éléments du vecteur de droite " r"$b$.")) else: display(Latex("C'est faux.")) interact_manual(correction, a=a, b=b, c=c, d=d, e=e, f=f, g=g, h=h) return def Ex4Chapitre2_6_7(): """Provides the correction of exercise 4 of notebook 2_6-7 """ display(Latex("Insérez les valeurs de a et b")) a = widgets.FloatText( value=0.0, step=0.1, description='a:', disabled=False ) b = widgets.FloatText( value=0.0, step=0.1, description='b:', disabled=False ) display(a) display(b) def f(): A = np.array([[0.5, a.value, 1], [0, 2, -1], [-2, 1, b.value]]) B = np.array([[-6, -2, -2], [4, 2, 1], [8, 3, 2]]) AB = np.dot(A, B) texAB = '$' + texMatrix(AB) + '$' BA = np.dot(B, A) texBA = '$' + texMatrix(BA) + '$' if a.value == -1 and b.value == -2: display(Latex(r"Correcte! Le produits $AB$ et $BA$ valent chacun: $I$ = " + texAB)) else: display(Latex(r"Incorrecte! Le produit $AB$ vaut " + texAB + r" et le produit " r"$BA$ vaut " + texBA + r", donc $A$ ne peut pas être l'inverse de $B$. " r"Entrez de nouvelles valeurs!")) interact_manual(f) return def Ex1Chapitre2_8_9(E1, E2, E3, E4): """Provides the correction of exercise 2 of notebook 2_8_9 :param E1: :type E1: :param E2: :type E2: :param E3: :type E3: :param E4: :type E4: :return: :rtype: """ # MATRIX A1 E_pre_1 = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] E_post_1 = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [1, 0, 0, 1]] # MATRIX A2 E_pre_2 = [[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]] E_post_2 = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1/2, 0], [0, 0, 0, -1]] # MATRIX A3 - E_pre_3 = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] + E_pre_3 = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, -1]] E_post_3 = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, -2], [0, 0, 0, 1]] # MATRIX A4 E_pre_4 = [[1/2, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] E_post_4 = [[1, 0, 0, 0], [0, 1, 1, 0], [0, 0, 1, 0], [0, 0, 0, -1]] E_bool = np.zeros(4).astype(bool) E_bool[0] = E1[0] == E_pre_1 and E1[1] == E_post_1 E_bool[1] = E2[0] == E_pre_2 and E2[1] == E_post_2 E_bool[2] = E3[0] == E_pre_3 and E3[1] == E_post_3 E_bool[3] = E4[0] == E_pre_4 and E4[1] == E_post_4 correct = set(np.where(E_bool)[0]+1) wrong = set(np.arange(1,5)) - correct if wrong: if correct: display(Latex(f"Corrects: {correct}")) else: display((Latex("Corrects: {}"))) display(Latex(f"Manqué: {wrong}")) else: display(Latex("C'est correcte.")) return def Ex3Chapitre2_8_9(): """Provides the correction of exercise 3 of notebook 2_8_9 """ a_1 = widgets.Checkbox( value=False, description=r'La matrice $A_1$ admet la décomposition LU', disabled=False, layout=Layout(width='80%', height='30px') ) a_2 = widgets.Checkbox( value=False, description=r'La matrice $A_2$ admet la décomposition LU', disabled=False, layout=Layout(width='80%', height='30px') ) a_3 = widgets.Checkbox( value=False, description=r'La matrice $A_3$ admet la décomposition LU', disabled=False, layout=Layout(width='80%', height='30px') ) def correction(a_1, a_2, a_3): if not a_1 and a_2 and not a_3: display(Latex("C'est correct! Plus précisément, la matrice $A_1$ n'admet pas décomposition LU car elle n'est pas inversible, la matrice $A_2$ admet décomposition LU et la matrice $A_3$ n'admet pas décomposition LU car elle ne peut pas être réduite sans échanger deux lignes pendant la méthode d'élimination de Gauss")) else: display(Latex("C'est faux.")) interact_manual(correction, a_1=a_1, a_2=a_2, a_3=a_3) return def Ex1Chapitre2_10(): """Provides the correction to exercise 1 of notebook 2_10 """ a = widgets.Checkbox( value=False, description=r"Le système linéaire n'admet aucune solution", disabled=False, layout=Layout(width='80%', height='40px') ) b = widgets.Checkbox( value=False, description=r"Le système linéaire admet une solution unique", disabled=False, layout=Layout(width='80%', height='40px') ) c = widgets.Checkbox( value=False, description=r"Le système linéaire admet deux solutions distinctes", disabled=False, layout=Layout(width='80%', height='40px') ) d = widgets.Checkbox( value=False, description=r"Le système linéaire admet une infinité de solutions", disabled=False, layout=Layout(width='80%', height='40px') ) e = widgets.Checkbox( value=False, description=r"La décomposition LU de $A$ ne peut pas être calculée", disabled=False, layout=Layout(width='80%', height='40px') ) f = widgets.Checkbox( value=False, description=r"La dernière colonne de $U$ est entièrement composée de zéros", disabled=False, layout=Layout(width='80%', height='40px') ) g = widgets.Checkbox( value=False, description=r'La dernière ligne de $U$ est entièrement composée de zéros', disabled=False, layout=Layout(width='80%', height='40px') ) h = widgets.Checkbox( value=False, description=r'La première entrée de la première ligne de $L$ est égale à 1', disabled=False, layout=Layout(width='80%', height='40px') ) def correction(a, b, c, d, e, f, g, h): if not a and not b and not c and d and not e and not f and g and not h: display(Latex("C'est correct. En effet, $A$ n'est clairement pas inversible, car la dernière ligne est " "égale à la seconde moins la première, et il en va de même pour le vecteur de droite $b$. " "Par conséquent, la dernière ligne de $U$ est entièrement composée de zéros (réponse 7) et la " "dernière entrée du vecteur de droite $b$, après l'application de la méthode d'élimination de " "Gauss, est également égale à 0. Ainsi, la dernière équation du système linéaire résultant a " "tous les coefficients égaux à 0, ce qui donne lieu à une infinité de solutions " "(réponse 4).")) else: display(Latex("C'est faux.")) interact_manual(correction, a=a, b=b, c=c, d=d, e=e, f=f, g=g, h=h) return def Ex2Chapitre2_10(L, U, b, x, y): """Provides the correction to exercise 2 of notebook 2_10 :param L: lower triangular matrix from LU decomposition :type L: list[list] :param U: upper triangular matrix from LU decomposition :type U: list[list] :param b: right-hand side vector :type b: list[list] :param x: system solution :type x: list[list] :param y: temporary variable :type y: list[list] """ if type(L) is list: L = np.array(L) if type(U) is list: U = np.array(U) if type(x) is list: x = np.array(x) if type(y) is list: y = np.array(y) y_true = np.linalg.solve(L, b) x_true = np.linalg.solve(U, y) res_x = np.linalg.norm(x - x_true) / np.linalg.norm(x_true) <= 1e-4 res_y = np.linalg.norm(y - y_true) / np.linalg.norm(y_true) <= 1e-4 if res_x and res_y: display(Latex("C'est correct")) else: display(Latex("C'est faux")) return def Ex3Chapitre2_10(): """Provides the correction to exercise 3 of notebook 2_10 :return: :rtype: """ a = widgets.Checkbox( value=False, description=r"If L is such that all its diagonal elements equal 1, then the temporary variable y is a vector " r"of ones as well", disabled=False, layout=Layout(width='80%', height='40px') ) b = widgets.Checkbox( value=False, description=r"Matrix L is diagonal", disabled=False, layout=Layout(width='80%', height='40px') ) c = widgets.Checkbox( value=False, description=r"Matrix U is diagonal", disabled=False, layout=Layout(width='80%', height='40px') ) d = widgets.Checkbox( value=False, description=r"The second entry of the solution is always 2.5 times the fourth one", disabled=False, layout=Layout(width='80%', height='40px') ) e = widgets.Checkbox( value=False, description=r"The second entry of the solution is always 5 times the fourth one", disabled=False, layout=Layout(width='80%', height='40px') ) f = widgets.Checkbox( value=False, description=r"The sum of all the entries always equals 2.5", disabled=False, layout=Layout(width='80%', height='40px') ) g = widgets.Checkbox( value=False, description=r"The sum of all the entries but the second one always equals 0", disabled=False, layout=Layout(width='80%', height='40px') ) h = widgets.Checkbox( value=False, description=r"The vector $\hat{x} = (1, 0 -1, 0)$ is one of the solutions to the linear system", disabled=False, layout=Layout(width='80%', height='40px') ) def correction(a, b, c, d, e, f, g, h): if a and not b and not c and d and not e and not f and g and h: display(Latex("C'est correct. Indeed the set of all possible solutions can be written as " "$x = [1-4a, 2.5a, 3a-1, a]$. From this, it is clear that the second entry is 2.5 times the " "fourth one (answer 4), that the sum of all the entries but the second one equals $0$ " "(answer 7) and that $x^* = [1,0,-1,0]$ is a solution, in case $a$ is set to 0 (answer 8). " "Also, if L is computed so that it has ones on its diagonal, it is immediate to deduce that " "the temporary vector $y$ that solves the system $Ly=b$ is actually all made of ones.")) else: display(Latex("C'est faux.")) interact_manual(correction, a=a, b=b, c=c, d=d, e=e, f=f, g=g, h=h) return def Ex1Chapitre2_11(): """Provides the correction to exercise 1 of notebook 2_11 """ print("Cliquer sur CTRL pour sélectionner plusieurs réponses") style = {'description_width': 'initial'} ans1 = widgets.SelectMultiple( options=['Addition', 'Multiplication', 'Addition par blocs', 'Multiplication par blocs'], description='Cas 1:', style=style, layout=Layout(width='30%', height='90px'), disabled=False, ) ans2 = widgets.SelectMultiple( options=['Addition', 'Multiplication', 'Addition par blocs', 'Multiplication par blocs'], description='Cas 2:', style=style, layout=Layout(width='30%', height='90px'), disabled=False, ) ans3 = widgets.SelectMultiple( options=['Addition', 'Multiplication', 'Addition par blocs', 'Multiplication par blocs'], description='Cas 3:', style=style, layout=Layout(width='30%', height='90px'), disabled=False, ) ans4 = widgets.SelectMultiple( options=['Addition', 'Multiplication', 'Addition par blocs', 'Multiplication par blocs'], description='Cas 4:', style=style, layout=Layout(width='30%', height='90px'), disabled=False, ) def correction(ans1, ans2, ans3, ans4): res_ans = np.zeros(4).astype(bool) res_ans[0] = 'Sum' in ans1 and 'Multiplication' in ans1 \ and 'Block Sum' in ans1 and not 'Block Multiplication' in ans1 res_ans[1] = 'Sum' in ans2 and 'Multiplication' in ans2 \ and not 'Block Sum' in ans2 and 'Block Multiplication' in ans2 res_ans[2] = not 'Sum' in ans3 and 'Multiplication' in ans3 \ and not 'Block Sum' in ans3 and 'Block Multiplication' in ans3 res_ans[3] = not 'Sum' in ans4 and 'Multiplication' in ans4 \ and not 'Block Sum' in ans4 and not 'Block Multiplication' in ans4 if res_ans.all(): display(Latex("C'est correct!")) else: display(Latex("C'est faux.")) correct = set(np.where(res_ans)[0] + 1) wrong = set(np.arange(1, 5)) - correct if correct: display(Latex(f"Corrects: {correct}")) else: display((Latex("Corrects: {}"))) display(Latex(f"Manqué: {wrong}")) interact_manual(correction, ans1=ans1, ans2=ans2, ans3=ans3, ans4=ans4) return def Ex2Chapitre2_11(): """Provides the correction of exercise 2 of notebook 2_11 """ display(Latex("Insérez votre réponse ici")) a = widgets.IntText( value=0, step=1, description='Answer:', disabled=False ) display(a) def f(): A_tex = "$$ \\qquad \\qquad \\qquad \\qquad \\qquad \\qquad \\quad" \ " A = \\left(\\begin{array}{@{}cc|cc|c@{}} " \ "a_{11} & a_{12} & a_{13} & a_{14} & a_{15} \\\\" \ " a_{21} & a_{22} & a_{23} & a_{24} & a_{25} \\\\ " \ "a_{31} & a_{32} & a_{33} & a_{34} & a_{35} \\\\ " \ "a_{41} & a_{42} & a_{43} & a_{44} & a_{45} " \ "\\end{array}\\right)$$" if a.value == 8: display(Latex(r"Correcte! En effet les colonnes de la matrice A doivent être décomposées comme suit, " r"afin de satisfaire les contraintes de dimensionnalité" + A_tex + r"Ensuite, la décomposition " "en blocs par lignes peut être effectuée dans l'une des $2^{n-1}=8$ possibilités disponibles.")) else: display(Latex(r"Incorrecte! Aide: Faites attention à la façon dont A doit être décomposé en blocs par " r"colonnes.")) interact_manual(f) return def Ex3Chapitre2_11(C1, C2, C3): """Provides the correction of exercise 3 of notebook 2_11 :param C1: :type C1: :param C2: :type C2: :param C3: :type C3: :return: :rtype: """ C1_true = [[]] C2_true = [[-1,-4,1], [4,6,2], [1,-1,2]] C3_true = [[6,7,2], [-10,-11,-2], [4,12,8], [-4,-8,-4]] C_bool = np.zeros(3).astype(bool) C_bool[0] = C1 == C1_true C_bool[1] = C2 == C2_true C_bool[2] = C3 == C3_true correct = set(np.where(C_bool)[0]+1) wrong = set(np.arange(1,4)) - correct if wrong: display(Latex("C'est faux.")) if correct: display(Latex(f"Corrects: {correct}")) else: display((Latex("Corrects: {}"))) display(Latex(f"Manqué: {wrong}")) else: display(Latex("C'est correcte.")) return def Ex4Chapitre2_11(A1_inv, A2_inv): """Provides the correction to exercise 4 of notebook 2_11 :param A1_inv: inverse of matrix A1 :type A1_inv: list[list] :param A2_inv: inverse of matrix A2 :type A2_inv: list[list] """ A1 = np.array([[1, 2, 0, 1, 0], [0, -2, 1, -1, 0], [-2, -1, 1, 0, 1], [0, 0, 0, 2, 0], [0, 0, 0, 0, 1]]) A1_inv_true = np.linalg.inv(A1) A1_inv = np.array(A1_inv) A2_inv_true = [[]] A_inv_bool = np.zeros(3).astype(bool) A_inv_bool[0] = A1_inv.shape == A1_inv_true.shape and np.linalg.norm(A1_inv - A1_inv_true) < 1e-6 A_inv_bool[1] = A2_inv == A2_inv_true correct = set(np.where(A_inv_bool)[0] + 1) wrong = set(np.arange(1, 3)) - correct if wrong: display(Latex("C'est faux.")) if correct: display(Latex(f"Corrects: {correct}")) else: display((Latex("Corrects: {}"))) display(Latex(f"Manqué: {wrong}")) else: display(Latex("C'est correcte.")) return