Résolution d'équations avec SymPy
Titre amélioré par l'IA
"nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "source": [ "exercice 1" ], "metadata": { "id": "ehZGAx7KBMYb" } }, { "cell_type": "markdown", "source": [ "Exercice 1 : Systèmes d'équations linéaires\n", "\n", "Résoudre le système suivant par substitution :\n",
"2𝑥 + 3𝑦 = 12\n", "\n",
"𝑥 − 𝑦 = 2" "\n",
], "metadata": { "id": "_qijsulKjn4O" } }, { "cell_type": "code", "source": [ "from sympy import symbols, Eq, solve\n", "\n", "x, y = symbols('x y')\n", "eq1 = Eq(2*x + 3*y, 12)\n", "eq2 = Eq(x - y, 2)\n", "solution = solve((eq1, eq2),( x, y))\n", "print(\"Les solutions du système sont x =\", float(solution[x]), \"et y=\", float(solution[y]))\n", "#------------\n", "import numpy as np\n", "\n", "A = [Link]([[2, 3], [1, -1]])\n", "B = [Link]([[12], [2]])\n", "result = [Link]([Link](A), B)\n", "print(result)" ], "metadata": { "id": "mt6oiHUyBr2X", "colab": { "base_uri": "[Link] }, "outputId": "e74a03b6-e912-4d3b-bb07-f18c080d6ace" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Les solutions du système sont x = 3.6 et y = 1.6\n", "[[3.6]\n", " [1.6]]\n" ] } ]},{ "cell_type": "markdown", "source": [ "Exercice 2 : Systèmes d'équations linéaires\n", "\n", "Résoudre le système suivant par la méthode d'élimination :\n",
"4𝑥 + 6𝑦 = 24\n", "\n",
"2𝑥 − 3𝑦 = 6" "\n",
], "metadata": { "id": "SPK0bOPoUCB7" }},{ "cell_type": "code", "source": [ "from sympy import symbols, Eq, solve\n", "\n", "x, y = symbols('x y')\n",
"𝑒𝑡\n", "𝐵 = {2, 3, 4, 5}\n", "\n", "Trouver :\n",
"a. 𝐴 ∪ 𝐵\n", "\n",
"b. 𝐴 ∩ 𝐵\n", "\n",
"c. 𝐴 − 𝐵 𝑜𝑢 𝐴 \\ B" "\n",
], "metadata": { "id": "vCGGMaemm5xI" } }, { "cell_type": "code", "source": [ "A = {1, 3, 5}\n", "B = {2, 3, 4, 5}\n", "union = [Link](B)\n", "intersection = [Link](B)\n", "soustraction = [Link](B)\n", "print(\"union = \", union, \"inter = \", intersection, \"sous = \",soustraction)" ], "metadata": { "colab": { "base_uri": "[Link] }, "id": "G2N5ZTuAnRzx", "outputId": "108a2513-eb4d-438b-9267-953ddce342c0" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "union = {1, 2, 3, 4, 5} inter = {3, 5} sous = {1}\n" ] } ] }, { "cell_type": "markdown", "source": [ "Exercice 4 : Ensemble et opérations d'ensembles\n", "\n", "Soit :\n",
"\n", "Trouver :\n",
"a. 𝐶 ∪ 𝐷\n", "\n",
"b. 𝐶 ∩ 𝐷\n", "\n",
"c. 𝐶 − 𝐷\n", "\n",
"\n" ], "metadata": { "id": "_2AVX5-Lor5f" } }, { "cell_type": "code", "source": [ "C = {'a', 'b', 'c', 'd'}\n", "D = {'b', 'c', 'e'}\n", "union = [Link](D)\n", "intersection = [Link](D)\n", "soustraction = [Link](D)\n", "print(\"union = \", union, \"inter = \", intersection, \"sous = \",soustraction)" ], "metadata": { "colab": { "base_uri": "[Link] }, "id": "U_kUeNZmo7yM", "outputId": "d328ca1f-3cc0-498d-fa8b-d99d3372c47b" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "union = {'a', 'c', 'e', 'd', 'b'} inter = {'c', 'b'} sous = {'a','d'}\n" ] } ] }, { "cell_type": "markdown", "source": [ "Exercice 5 : Fonction linéaire\n",
"a. 𝑓(2)\n", "\n",
"b. 𝑓(−1)\n" "\n",
], "metadata": { "id": "slX7SxGIquJG" }},{ "cell_type": "code", "source": [ "def func(x):\n", " return (3*x - 5)\n", "print(func(2))\n", "print(func(-1))" ], "metadata": { "colab": { "base_uri": "[Link] }, "id": "cAaIMi4qqyNP", "outputId": "d4bcc668-17b7-4c0d-e3e5-98d7cda4a82f" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "-5\n", "-8\n" ] } ]},{ "cell_type": "markdown", "source": [ "Exercice 6 : Résolution d'une équation linéaire simple\n",
], "metadata": { "id": "L-wEg5Xlsc9f" }},{ "cell_type": "code", "source": [ "from sympy import symbols, Eq, solve\n", "\n", "x = symbols('x')\n", "eq = Eq(4*x - 7, 5)\n", "result = solve(eq, x)\n", "print (result[0])" ], "metadata": { "colab": { "base_uri": "[Link] }, "id": "1MmE2Wo3sfli", "outputId": "247b93bf-9f38-4bdb-cde5-1e6d036734a4" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "3\n" ] } ] } ]}