{ "cells": [ { "cell_type": "markdown", "id": "cb1edcb1", "metadata": {}, "source": [ "# Systèmes d'équations linéaires" ] }, { "cell_type": "markdown", "id": "b802b136", "metadata": {}, "source": [ "Il est également possible de résoudre des équations linéaires (sous forme polynomiale) ou des systèmes d'équations linéaires" ] }, { "cell_type": "markdown", "id": "f3a0b5ba", "metadata": {}, "source": [ "## Equations polynomiales" ] }, { "cell_type": "markdown", "id": "e39a9cae", "metadata": {}, "source": [ "Pour résoudre une équation du type : $\\sum_{k=0}^{n}(a_k . x^k) = 0$, il est possible d'utiliser une branche particulière de Numpy." ] }, { "cell_type": "code", "execution_count": null, "id": "9707ea3f", "metadata": {}, "outputs": [], "source": [ "import numpy.polynomial.polynomial as nppol" ] }, { "cell_type": "markdown", "id": "1ab66503", "metadata": {}, "source": [ "On souahite résoudre l'équation : $-6 . x^2 - 2 . x + 4 = 0$ " ] }, { "cell_type": "markdown", "id": "b423a358", "metadata": {}, "source": [ "> **Exécutez les instructions suivantes** et déterminez que contient la variable *X*" ] }, { "cell_type": "code", "execution_count": null, "id": "e8cff478", "metadata": {}, "outputs": [], "source": [ "X = nppol.polyroots( [ 4, -2, -6] )\n", "print( X )" ] }, { "cell_type": "markdown", "id": "f2d55be2", "metadata": {}, "source": [ "## Systèmes d'équations linéaires" ] }, { "cell_type": "markdown", "id": "52a60bd9", "metadata": {}, "source": [ "Soit le système d'équations suivant :\n", "\n", "$$\\begin{cases} a_1 . x + b_1 . y = c_1 \\\\ a_2 . x + b_2 . y = c_2 \\end{cases}$$" ] }, { "cell_type": "markdown", "id": "1f44f79d", "metadata": {}, "source": [ "Il est possible de le mettre sous une forme matricielle en posant :\n", "\n", "$$A = \\begin{pmatrix}a_1 & b_1\\\\ a_2 & b_2\\end{pmatrix} \\text{, } b = \\begin{pmatrix}c_1\\\\ c_2\\end{pmatrix} \\text{et } X = \\begin{pmatrix}x\\\\y\\end{pmatrix} $$" ] }, { "attachments": {}, "cell_type": "markdown", "id": "9f54b5ef", "metadata": {}, "source": [ "Si le système possède une solution, alors la matrice **A** est inversible et le résultat peut s'obtenir par : \n", "$$ X = A^{-1} \\cdot b$$" ] }, { "cell_type": "markdown", "id": "104bbbed", "metadata": {}, "source": [ "Par exemple, on souhaite résoudre le système suivant :\n", "$$\\begin{cases} x + 2 . y = 5 \\\\ 3 . x + 4 . y = 6 \\end{cases}$$" ] }, { "cell_type": "markdown", "id": "55240f04", "metadata": {}, "source": [ "On définit les matrices suivantes :" ] }, { "cell_type": "code", "execution_count": null, "id": "95a89e38", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "A = np.array([[1, 2], [3, 4]])\n", "b = np.array([[5], [6]])" ] }, { "cell_type": "markdown", "id": "a1e94423", "metadata": {}, "source": [ "On utilise ensuite la méthode ***solve*** de la bibliothèque **linalg** de **SciPy**." ] }, { "cell_type": "code", "execution_count": null, "id": "5d8b9925", "metadata": {}, "outputs": [], "source": [ "from scipy import linalg\n", "X = linalg.solve(A, b)\n", "print(X)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.16" } }, "nbformat": 4, "nbformat_minor": 5 }