Page MenuHomec4science

2.4 Systèmes d'équations et matrices.ipynb
No OneTemporary

File Metadata

Created
Sat, May 11, 21:27

2.4 Systèmes d'équations et matrices.ipynb

{
"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,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"import Librairie.AL_Fct as al\n",
"import Corrections.corrections as corrections\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### EXEMPLE 1\n",
"Considérez le système linéaire $ Ax = 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}; \\qquad b = \n",
"\\begin{pmatrix}\n",
"2\\\\\n",
"4\\\\\n",
"3\\\\\n",
"\\end{pmatrix};\n",
"\\end{equation}\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"A = [[2, 0, 1], [0, 3, 4], [2, 2, 1]]\n",
"b = [[2], [4], [3]]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### ÉTAPE 1: résoudre le système linéaire en utilisant la méthode d'élimination de Gauss"
]
},
{
"cell_type": "code",
<<<<<<< HEAD
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Vous allez échelonner la matrice augmenteé\n"
]
},
{
"data": {
"text/latex": [
"$\\left(\\begin{array}{ccc| cc} 2 & 0 & 1 & 2 \\\\0 & 3 & 4 & 4 \\\\2 & 2 & 1 & 3 \\end{array}\\right)$"
],
"text/plain": [
"<IPython.core.display.Latex object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Régler les paramètres et évaluer la cellule suivante\n",
"Répéter cela jusqu'à obtenir une forme échelonnée réduite\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a335480cf87d452fb14da54f9faccd29",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"RadioButtons(description='Opération:', options=('Eij', 'Ei(alpha)', 'Eij(alpha)', 'Revert'), value='Eij')"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1ac4b957938e4af1a0a062018d5cbd5a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"BoundedIntText(value=1, description='Ligne i:', max=3, min=1)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "22a213ee957342cb98d57e4363ad154c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"BoundedIntText(value=1, description='Ligne j:', max=3, min=1)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3788864db10c45569be6bdea2479be02",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Text(value='1', description='Coeff. alpha:')"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1mExecutez la ligne suivante pour effectuer l'opération choisie \u001b[0m\n"
]
}
],
=======
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
>>>>>>> e05dd5c1c87dd88990947782050b038375e5cfae
"source": [
"print('Vous allez échelonner la matrice augmenteé')\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[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
},
"outputs": [],
"source": [
"print('Insérez ici la valeur de la solution calculée')\n",
"x1 = [[1], [1], [1]]\n",
"res1 = al.SolOfSyst(x1, A, b)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### TASK 2: calculer l'inverse de la matrice A ([voir le Notebook 2.3](./2.3%20Matrices%20carrées%2C%20inversibles.ipynb)) et dériver la solution du système linéaire en fonction du résultat obtenu"
]
},
{
"cell_type": "code",
<<<<<<< HEAD
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Vous allez échelonner la matrice augmenteé avec la matrice identité\n"
]
},
{
"data": {
"text/latex": [
"$\\left[\\begin{array}{ccc| cccc} 2 & 0 & 1 & 1 & 0 & 0 \\\\0 & 3 & 4 & 0 & 1 & 0 \\\\2 & 2 & 1 & 0 & 0 & 1 \\end{array}\\right]$"
],
"text/plain": [
"<IPython.core.display.Latex object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Régler les paramètres et évaluer la cellule suivante\n",
"Répéter cela jusqu'à obtenir une forme échelonnée réduite\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ff9b416fec6a4fcb8a3c4a05b6e775fd",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"RadioButtons(description='Opération:', options=('Eij', 'Ei(alpha)', 'Eij(alpha)', 'Revert'), value='Eij')"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4d7fd6e14c014932b5e29a10697c04c2",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"BoundedIntText(value=1, description='Ligne i:', max=3, min=1)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8f3c7d22892c48dea9ebfc070b7bb766",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"BoundedIntText(value=1, description='Ligne j:', max=3, min=1)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "51ec7a7353aa4228959840ebd2325deb",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Text(value='1', description='Coeff. alpha:')"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1mExecutez la ligne suivante pour effectuer l'opération choisie \u001b[0m\n"
]
}
],
=======
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
>>>>>>> e05dd5c1c87dd88990947782050b038375e5cfae
"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": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"print('Insérez ici la valeur de la solution calculée')\n",
"A_inv = [[1,0,0], [0,1,0], [0,0,1]]\n",
"x2 = np.dot(np.array(A_inv), np.array(b))\n",
"res2 = al.SolOfSyst(x2, A, b)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"if res1 and res2:\n",
" print(f'Tu as raison! Et en plus, x1 = {x1} 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",
"\\end{cases}\n",
"\\end{equation}\n",
"Laquelle des affirmations suivantes est correcte?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"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
},
"outputs": [],
"source": [
"print('Vous allez échelonner la matrice augmenteé')\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[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
},
"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,
"metadata": {},
"outputs": [],
"source": [
"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"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

Event Timeline