diff --git "a/Chapitre 2 - Algebre matricielle/2.3 Matrices carr\303\251es, inversibles.ipynb" "b/Chapitre 2 - Algebre matricielle/2.3 Matrices carr\303\251es, inversibles.ipynb" index 89e9bd7..7c0d379 100644 --- "a/Chapitre 2 - Algebre matricielle/2.3 Matrices carr\303\251es, inversibles.ipynb" +++ "b/Chapitre 2 - Algebre matricielle/2.3 Matrices carr\303\251es, inversibles.ipynb" @@ -1,303 +1,283 @@ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# **Concept(s)-clé(s) et théorie**\n", "\n", "### DÉFINITION 1 :\n", - "On dit qu'une matrice $A$ est *carrée* si elle est de taille $n\\times n$ pour un certain entier $n\\in \\mathbb{N}^*,$ c'est-à-dire si elle possède le même nombre de lignes et de colonnes. Aussi, une telle matrice est dite *inversible* s'il existe une matrice $B\\in M_{n\\times n}(\\mathbb{R})$ telle que $$AB=I_n=BA.$$\n", + "On dit qu'une matrice $A$ est *carrée* si elle est de taille $n\\times n$ pour un certain entier $n\\in \\mathbb{N}^*,$ c'est-à-dire si elle possède le même nombre de lignes et de colonnes. Aussi, une telle matrice est dite *inversible* s'il existe une matrice $B\\in M_{n\\times n}(\\mathbb{R})$ telle que: \n", + "\\begin{equation*}\n", + "AB=I_n=BA\n", + "\\end{equation*}\n", + "où $I_n$ représente la matrice d'identité avec $n$ lignes et $n$ colonnes. Dans ce cas, on dit que $B$ est l'*inverse* de la matrice $A$.\n", "\n", "---\n", "### DÉFINITION 2 :\n", "Soit $A$ une matrice de taille $m\\times n$ à coefficients réels. La *diagonale principale* de $A$ est la \"ligne oblique\" formée des composantes $(i,i)$ de $A.$\n", "\n", "---\n", "### DÉFINITION 3 :\n", "On dit d'une matrice $A=(a_{ij})\\in M_{m\\times n}(\\mathbb{R})$) qu'elle est:\n", "\n", "$\\bullet$ *triangulaire supérieure*  si $a_{ij}=0$ pour tout $i>j$;\n", "\n", "$\\bullet$ *triangulaire inférieure*  si $a_{ij}=0$ pour tout $i\n", + " window.PlotlyConfig = {MathJaxConfig: 'local'};\n", + " if (window.MathJax) {MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}\n", + " if (typeof require !== 'undefined') {\n", + " require.undef(\"plotly\");\n", + " requirejs.config({\n", + " paths: {\n", + " 'plotly': ['https://cdn.plot.ly/plotly-latest.min']\n", + " }\n", + " });\n", + " require(['plotly'], function(Plotly) {\n", + " window._Plotly = Plotly;\n", + " });\n", + " }\n", + " \n", + " " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + " \n", + " " + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ - "import AL_Fct as al\n", + "import Librairie.AL_Fct as al\n", + "import Corrections.corrections as corrections\n", "import numpy as np\n", "from numpy.linalg import *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### **Exercice 1**\n", "\n", "Soit $A$ la matrice\n", "$$\n", - "A=\\begin{pmatrix}\n", + "A=\\begin{bmatrix}\n", "-2 & 4/3 & -1\\\\\n", "0 & 3 & -5\\\\\n", "1/2 & 1 & 1/2\n", - "\\end{pmatrix}.\n", + "\\end{bmatrix}.\n", "$$\n", "\n", - "Trouver une matrice $B$ et une matrice $C$ telles que\n", + "Trouver une matrice $B$ et une matrice $C$ telles que:\n", "1. $A + B$ soit diagonale\n", "2. $A + C$ soit symétrique mais non diagonale\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ + "# Reportez ici le matrices B et C\n", "A=[[-2, 4/3,-1],[0,3,-5],[1/2,1,1/2]]\n", - "B=[[0,-4/3,1],[0,0,5],[-1/2,-1,0]]\n", - "C=[[0,0,0],[4/3,0,0],[-3/2,-6,0]]" + "B=[[0,0,0],[0,0,0],[0,0,0]]\n", + "C=[[0,0,0],[0,0,0],[0,0,0]]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "print('La matrice B entrée est')\n", + "print('La matrice B entrée est:')\n", "al.printA(B)\n", - "print('La matrice C entrée est')\n", + "print('La matrice C entrée est:')\n", "al.printA(C)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "print('A+B='); al.printA(np.asmatrix(A)+np.asmatrix(B))\n", - "print('A+C=');al.printA(np.asmatrix(A)+np.asmatrix(C))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def isDiag(M):\n", - " i, j = M.shape\n", - " assert i == j \n", - " test = M.reshape(-1)[:-1].reshape(i-1, j+1)\n", - " return ~np.any(test[:, 1:])\n", - "def isSym(M):\n", - " return ~np.any(M-np.transpose(M))\n", - " \n", - "if isDiag(np.asarray(A)+np.asarray(B)):\n", - " print('A+B est bien diagonale!')\n", - "else:\n", - " print(\"A+B est n'est pas diagonale!\")\n", - "\n", - "if isSym(np.asmatrix(A)+np.asmatrix(C)):\n", - " print('A+C est bien symétrique!')\n", - "else:\n", - " print(\"A+C est n'est pas symétrique!\")\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "al.printA(inv(np.asmatrix(A)+np.asmatrix(B)))" + "corrections.Ex1Chapitre2_3(A,B,C)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### **Exemple 1**\n", "\n", "Soit $A$ la matrice carrée $3\\times 3$ donnée par\n", "$$\n", - "A=\\begin{pmatrix}\n", + "A=\\begin{bmatrix}\n", "1 & 2 & 3\\\\\n", "0 & -1 & 0\\\\\n", "0 & 2 & 3\n", - "\\end{pmatrix}\n", + "\\end{bmatrix}\n", "$$\n", "\n", - "Nous allons trouver l'inverse de $A$ en utilisant les opérations\n", + "Nous allons trouver l'inverse de $A$ en appliquant à la matrice $A|I$ (étant $I$ la matrice d'identité de la même dimension de $A$) les opérations élémentaires suivantes:\n", "1. $L_1-L_3$\n", "2. $(-1)L_2$\n", "3. $L_3-2L_2$\n", - "4. $\\dfrac{1}{3}L_3$" + "4. $\\dfrac{1}{3}L_3$\n", + "\n", + "où $L_i$ représente la i-ème ligne de la matrice $A|I$. En particulier, nous obtiendrons la forme échelonnée réduite de $A$ à la place de $A$ et, en même temps, nous trouverons l'expression de la inverse de $A$ à la place de $I$." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "A=[[1,2,3],[0,-1,0],[0,2,3]]\n", "I=[[1,0,0],[0,1,0],[0,0,1]]\n", "\n", - "print('Vous allez inverser la matrice en obtenant la forme échelonnée réduite à la place de A')\n", + "print(\"Appliquer l'opération élémentaire précitée pour obtenir la forme échelonnée reduit\" \n", + " \"de la matrice A; alors vous pouvez lire l'expression de l'inverse de A où il y avait\" \n", + " \"à l'origine la matrice d'identité I.\")\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]" ] }, { "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": [ - "print('En effet la matrice inverse de A est donnée par ' )\n", + "print('La matrice inverse de A est donnée par: ' )\n", "al.printA(inv(A))\n", - "print('Car A A^{-1}=I_3')\n", + "print('Le produit entre A et son inverse est en effet égal à: ')\n", "I=np.dot(A,inv(A))\n", - "print(I[:,2])\n", "al.printA(I)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### **Exercice 2**\n", "\n", "Soit $A$ la matrice ci-dessous\n", "$$\n", - "A=\\begin{pmatrix}\n", + "A=\\begin{bmatrix}\n", "-1 & 0 & 0 \\\\\n", "3 & \\dfrac{1}{2} & 0 \\\\\n", "1 & 2 & 1 \n", - "\\end{pmatrix}.\n", + "\\end{bmatrix}.\n", "$$\n", "\n", "Laquelle des affirmations ci-dessous est correcte?\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "56005b6712f84d55b4810da796178f66", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(Checkbox(value=False, description='$(A^{-1})^T$ et $(A^T)^{-1}$ sont triangulaires supér…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ - "from IPython.display import display, Latex\n", - "from ipywidgets import Button, HBox, VBox,Layout,interact, interactive, fixed, interact_manual\n", - "import ipywidgets as widgets\n", - "\n", - " # OK PUT in AL_FCT\n", - "\n", - "a=widgets.Checkbox(\n", - " value=False,\n", - " description=r'\\((A^{-1})^T\\) et \\((A^T)^{-1}\\) sont triangulaires supérieures mais différentes' ,\n", - " disabled=False,\n", - " layout=Layout(width='80%', height='40px')\n", - ")\n", - "b=widgets.Checkbox(\n", - " value=False,\n", - " description=r'\\((A^{-1})^T\\) et \\((A^T)^{-1}\\) sont triangulaires inférieures mais différentes',\n", - " disabled=False,\n", - " layout=Layout(width='80%', height='40px')\n", - "\n", - ")\n", - "c=widgets.Checkbox(\n", - " value=False,\n", - " description=r'\\((A^{-1})^T\\) et \\((A^T)^{-1}\\) sont triangulaires inférieures et identiques',\n", - " disabled=False,\n", - " layout=Layout(width='80%', height='40px')\n", - ")\n", - "d=widgets.Checkbox(\n", - " value=False,\n", - " description=r'\\((A^{-1})^T\\) et \\((A^T)^{-1}\\) sont triangulaires supérieures et identiques',\n", - " disabled=False,\n", - " layout=Layout(width='80%', height='40px')\n", - ")\n", - "def correction(a,b,c,d): \n", - " if d and not(a) and not(c) and not(b):\n", - " A=np.asmatrix(([-1,0,0], [3, 1/2, 0],[1,2,1]))\n", - " display(Latex(\"C'est correct! $(A^T)^{-1}$ est donnée par\"))\n", - " al.printA(np.transpose(inv(A)))\n", - " else:\n", - " print(\"C'est faux.\")\n", - "\n", - "out=interact_manual(correction,a=a,b=b,c=c,d=d)\n", - " " + "corrections.Ex2Chapitre2_3()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Vérification de vos exercices" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "A=[[1,0,0],[0,2,0],[0,0,3]]\n", - "print(\"L'inverse de A estdonnée par\")\n", - "al.printA(inv(A))" + "[Passez au notebook 2.4: Systèmes d'équations et matrices](2.4%20Systèmes%20d'équations%20et%20matrices.ipynb)" ] - }, - { - "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" + "version": "3.7.4" } }, "nbformat": 4, "nbformat_minor": 2 }