diff --git "a/Chapitre 1 - Systemes equations lineaires/.ipynb_checkpoints/1.1. Introduction et d\303\251finition-checkpoint.ipynb" "b/Chapitre 1 - Systemes equations lineaires/.ipynb_checkpoints/1.1. Introduction et d\303\251finition-checkpoint.ipynb" new file mode 100644 index 0000000..06b07af --- /dev/null +++ "b/Chapitre 1 - Systemes equations lineaires/.ipynb_checkpoints/1.1. Introduction et d\303\251finition-checkpoint.ipynb" @@ -0,0 +1,207 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\bf{Concept(s)-clé(s)}$\n", + "\n", + "DÉFINITION 1 :\n", + "\n", + "Une équation linéaire aux inconnues $x_1,\\ldots,x_n$ à coefficients réels est une équation de la forme $$a_1x_1+a_2x_2+\\cdots+a_nx_n=b,$$ où $a_1,a_2,\\ldots,a_n,b\\in \\mathbb{R}.$\n", + "\n", + "DÉFINITION 2 :\n", + "\n", + "On appelle système d'équations linéaires (ou simplement système linéaire) une famille d'équations linéaires aux inconnues $x_1,\\ldots,x_n$ à coefficients réels de la forme \n", + "$$S=\\left\\{\\begin{array}{ccccccc}\n", + "a_{11}x_1 &+a_{12}x_2 & + &\\cdots &+a_{1n}x_n &= &b_1 \\\\\n", + "a_{21}x_1 &+a_{22}x_2 & + &\\cdots &+a_{2n}x_n &= &b_2 \\\\\n", + "\\vdots & & & &\\vdots & \\vdots &\\vdots \\\\\n", + "a_{m1}x_1 &+a_{m2}x_2 & + &\\cdots &+a_{mn}x_n &= &b_m\n", + "\\end{array},\\right. $$\n", + "où $a_{ij},b_i\\in \\mathbb{R}$ pour tout $1\\leq i\\leq m$ et tout $1\\leq j\\leq n.$ Aussi, on dit qu'une suite ordonnée de $n$ nombres réels $\\alpha=(\\alpha_1,\\ldots,\\alpha_n)$ est une solution du système linéaire $S$ si toutes les égalités du système sont vérifiées lorsque l'on remplace $x_j$ par $\\alpha_j,$ ceci pout tout $1\\leq j\\leq n.$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "EXERCICE 1:\n", + "\n", + "Dans ce premier exericce nous nous familiarisons avec les équations et les ensembles de solutions. \n", + "La partie ci-dessous vous demande de rentrer équation en suivant les notations de la définition 1. \n", + "\n", + "Essayer, par exemple, de entrer l'équation \n", + "$$3x_1 + x_2=7$$\n", + "\n", + "Donner ensuite une solution $$ \\alpha=(\\alpha_1, \\ldots , \\alpha_n)$$ à l'équation entrée." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Entrez le nombre variables n=\n", + "2\n", + "Votre équation est de la forme\n" + ] + }, + { + "data": { + "text/latex": [ + "$a_1x_1 + a_2x_2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Entrez les 2 coefficients de l'équations sous le format a1, a2, ..., b\n", + "3,1,7\n", + "Votre equation est\n" + ] + }, + { + "data": { + "text/latex": [ + "$3x_1 + 1x_2=7$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "import numpy as np\n", + "from IPython.display import display, Math, Latex\n", + "\n", + "\n", + "def printEq(n,coeff):\n", + " textEq='$'\n", + " if coeff=='': # equation is a1x1+ ...+anxn\n", + " if n==1:\n", + " textEq=textEq + 'a_1x_1'\n", + " elif n==2:\n", + " textEq=textEq + 'a_1x_1 + a_2x_2'\n", + " else:\n", + " textEq=textEq + 'a_1x_1 + \\ldots + ' + 'a_' + str(n) + 'x_'+ str(n) + '=b'\n", + " else :\n", + " for i in range(0,n-1):\n", + " textEq=textEq + str(coeff[i]) + 'x_' + str(i+1) +' + '\n", + " textEq=textEq + str(coeff[len(coeff)-2]) + 'x_' + str(n) + '=' + str(coeff[len(coeff)-1]) \n", + " texEq =textEq+ '$'\n", + " # print(texEq)\n", + " display(Latex(texEq))\n", + " \n", + " \n", + "\n", + "print(\"Entrez le nombre variables n=\")\n", + "n=input()\n", + "while type(n)!=int:\n", + " try:\n", + " n=int(n)\n", + " if n<=0:\n", + " print(\"Le nombre de variable ne peut pas être négatif!\") \n", + " print(\"Entrez le nombre variables n=\")\n", + " n=input()\n", + " except:\n", + " print(\"Ce n'est pas un entier!\")\n", + " print(\"Entrez le nombre variables n=\")\n", + " n=input()\n", + "\n", + "n=int(n)\n", + "print(\"Votre équation est de la forme\")\n", + "\n", + "printEq(n, '')\n", + "\n", + "coeff=''\n", + "while type(coeff)!=list and len(coeff)!=n+1:\n", + " print(\"Entrez les \", n+1,\" coefficients de l'équations sous le format a1, a2, ..., b\")\n", + " entry=input()\n", + " try: \n", + " coeff=[int(x) for x in entry.split(',')] \n", + " except:\n", + " print(\"Les coefficients ne sont pas dans le bon format ou vous n'avez pas entré le bon nombre de coefficients!\")\n", + " \n", + " \n", + "print(\"Votre equation est\")\n", + "printEq(n, coeff)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Entrez la solution sous la forme d'une suite de 2 nombres réels\n", + "2,1\n", + "La suite entrée est une solution de votre équation!\n" + ] + } + ], + "source": [ + "\n", + "sol=''\n", + "while type(sol)!=list and len(sol)!=n:\n", + " print(\"Entrez la solution sous la forme d'une suite de \", n,\" nombres réels\")\n", + " entry=input()\n", + " try: \n", + " sol=[int(x) for x in entry.split(',')] \n", + " except:\n", + " print(\"La suite n'est pas dans le bon format ou n'est pas de la bonne longueur!\")\n", + "\n", + "sol=np.asarray(sol[0:len(sol)])\n", + "A = np.asarray(coeff[0:len(coeff)-1])\n", + "\n", + "if np.dot(A,sol)==coeff[len(coeff)-1]:\n", + " print(\"La suite entrée est une solution de votre équation!\")\n", + "else:\n", + " print(\"La suite entrée n'est pas une solution de votre équation!\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "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.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/Chapitre 1 - Systemes equations lineaires/1.1. Introduction et d\303\251finition.ipynb" "b/Chapitre 1 - Systemes equations lineaires/1.1. Introduction et d\303\251finition.ipynb" new file mode 100644 index 0000000..06b07af --- /dev/null +++ "b/Chapitre 1 - Systemes equations lineaires/1.1. Introduction et d\303\251finition.ipynb" @@ -0,0 +1,207 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\bf{Concept(s)-clé(s)}$\n", + "\n", + "DÉFINITION 1 :\n", + "\n", + "Une équation linéaire aux inconnues $x_1,\\ldots,x_n$ à coefficients réels est une équation de la forme $$a_1x_1+a_2x_2+\\cdots+a_nx_n=b,$$ où $a_1,a_2,\\ldots,a_n,b\\in \\mathbb{R}.$\n", + "\n", + "DÉFINITION 2 :\n", + "\n", + "On appelle système d'équations linéaires (ou simplement système linéaire) une famille d'équations linéaires aux inconnues $x_1,\\ldots,x_n$ à coefficients réels de la forme \n", + "$$S=\\left\\{\\begin{array}{ccccccc}\n", + "a_{11}x_1 &+a_{12}x_2 & + &\\cdots &+a_{1n}x_n &= &b_1 \\\\\n", + "a_{21}x_1 &+a_{22}x_2 & + &\\cdots &+a_{2n}x_n &= &b_2 \\\\\n", + "\\vdots & & & &\\vdots & \\vdots &\\vdots \\\\\n", + "a_{m1}x_1 &+a_{m2}x_2 & + &\\cdots &+a_{mn}x_n &= &b_m\n", + "\\end{array},\\right. $$\n", + "où $a_{ij},b_i\\in \\mathbb{R}$ pour tout $1\\leq i\\leq m$ et tout $1\\leq j\\leq n.$ Aussi, on dit qu'une suite ordonnée de $n$ nombres réels $\\alpha=(\\alpha_1,\\ldots,\\alpha_n)$ est une solution du système linéaire $S$ si toutes les égalités du système sont vérifiées lorsque l'on remplace $x_j$ par $\\alpha_j,$ ceci pout tout $1\\leq j\\leq n.$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "EXERCICE 1:\n", + "\n", + "Dans ce premier exericce nous nous familiarisons avec les équations et les ensembles de solutions. \n", + "La partie ci-dessous vous demande de rentrer équation en suivant les notations de la définition 1. \n", + "\n", + "Essayer, par exemple, de entrer l'équation \n", + "$$3x_1 + x_2=7$$\n", + "\n", + "Donner ensuite une solution $$ \\alpha=(\\alpha_1, \\ldots , \\alpha_n)$$ à l'équation entrée." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Entrez le nombre variables n=\n", + "2\n", + "Votre équation est de la forme\n" + ] + }, + { + "data": { + "text/latex": [ + "$a_1x_1 + a_2x_2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Entrez les 2 coefficients de l'équations sous le format a1, a2, ..., b\n", + "3,1,7\n", + "Votre equation est\n" + ] + }, + { + "data": { + "text/latex": [ + "$3x_1 + 1x_2=7$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "import numpy as np\n", + "from IPython.display import display, Math, Latex\n", + "\n", + "\n", + "def printEq(n,coeff):\n", + " textEq='$'\n", + " if coeff=='': # equation is a1x1+ ...+anxn\n", + " if n==1:\n", + " textEq=textEq + 'a_1x_1'\n", + " elif n==2:\n", + " textEq=textEq + 'a_1x_1 + a_2x_2'\n", + " else:\n", + " textEq=textEq + 'a_1x_1 + \\ldots + ' + 'a_' + str(n) + 'x_'+ str(n) + '=b'\n", + " else :\n", + " for i in range(0,n-1):\n", + " textEq=textEq + str(coeff[i]) + 'x_' + str(i+1) +' + '\n", + " textEq=textEq + str(coeff[len(coeff)-2]) + 'x_' + str(n) + '=' + str(coeff[len(coeff)-1]) \n", + " texEq =textEq+ '$'\n", + " # print(texEq)\n", + " display(Latex(texEq))\n", + " \n", + " \n", + "\n", + "print(\"Entrez le nombre variables n=\")\n", + "n=input()\n", + "while type(n)!=int:\n", + " try:\n", + " n=int(n)\n", + " if n<=0:\n", + " print(\"Le nombre de variable ne peut pas être négatif!\") \n", + " print(\"Entrez le nombre variables n=\")\n", + " n=input()\n", + " except:\n", + " print(\"Ce n'est pas un entier!\")\n", + " print(\"Entrez le nombre variables n=\")\n", + " n=input()\n", + "\n", + "n=int(n)\n", + "print(\"Votre équation est de la forme\")\n", + "\n", + "printEq(n, '')\n", + "\n", + "coeff=''\n", + "while type(coeff)!=list and len(coeff)!=n+1:\n", + " print(\"Entrez les \", n+1,\" coefficients de l'équations sous le format a1, a2, ..., b\")\n", + " entry=input()\n", + " try: \n", + " coeff=[int(x) for x in entry.split(',')] \n", + " except:\n", + " print(\"Les coefficients ne sont pas dans le bon format ou vous n'avez pas entré le bon nombre de coefficients!\")\n", + " \n", + " \n", + "print(\"Votre equation est\")\n", + "printEq(n, coeff)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Entrez la solution sous la forme d'une suite de 2 nombres réels\n", + "2,1\n", + "La suite entrée est une solution de votre équation!\n" + ] + } + ], + "source": [ + "\n", + "sol=''\n", + "while type(sol)!=list and len(sol)!=n:\n", + " print(\"Entrez la solution sous la forme d'une suite de \", n,\" nombres réels\")\n", + " entry=input()\n", + " try: \n", + " sol=[int(x) for x in entry.split(',')] \n", + " except:\n", + " print(\"La suite n'est pas dans le bon format ou n'est pas de la bonne longueur!\")\n", + "\n", + "sol=np.asarray(sol[0:len(sol)])\n", + "A = np.asarray(coeff[0:len(coeff)-1])\n", + "\n", + "if np.dot(A,sol)==coeff[len(coeff)-1]:\n", + " print(\"La suite entrée est une solution de votre équation!\")\n", + "else:\n", + " print(\"La suite entrée n'est pas une solution de votre équation!\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "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.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Chapitre 1 - Systemes equations lineaires/matrice.py b/Chapitre 1 - Systemes equations lineaires/matrice.py new file mode 100644 index 0000000..983b858 --- /dev/null +++ b/Chapitre 1 - Systemes equations lineaires/matrice.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Mar 13 11:01:03 2019 + +@author: jecker +""" + +import numpy as np + +def printA(A) : + texApre = '$\\left(\\begin{array}{' + texA = '' + for i in np.asarray(A) : + texALigne = '' + texALigne = texALigne + str(i[0]) + if texA == '' : + texApre = texApre + 'c' + for j in i[1:] : + if texA == '' : + texApre = texApre + 'c' + texALigne = texALigne + ' & ' + str(j) + texALigne = texALigne + ' \\\\' + texA = texA + texALigne + texA = texApre + '} ' + texA[:-2] + ' \\end{array}\\right)$' + + # print(texA) + display(Latex(texA)) +# done printing + + +A_array = np.array([[1, 2, 3], [3, 4, 5]]) +A = np.asmatrix(A_array) +del A_array + +#printA(A+A) +#printA(np.matmul(np.transpose(A),A)) + +printA(A) \ No newline at end of file diff --git a/Chapitre 1 - Systemes equations lineaires/test1.py b/Chapitre 1 - Systemes equations lineaires/test1.py new file mode 100644 index 0000000..f96e1f8 --- /dev/null +++ b/Chapitre 1 - Systemes equations lineaires/test1.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon Mar 11 10:13:39 2019 + +@author: jecker +""" +import numpy as np + +def printEq(n,coeff): + textEq='$' + if coeff=='': # equation is a1x1+ ...+anxn + if n==1: + textEq=textEq + 'a_1x_1' + elif n==2: + textEq=textEq + 'a_1x_1 + a_2x_2' + else: + textEq=textEq + 'a_1x_1 + \ldots + ' + 'a_' + str(n) + 'x_'+ str(n) + '=b' + else : + for i in range(0,n-1): + textEq=textEq + str(coeff[i]) + 'x_' + str(i+1) +' + ' + textEq=textEq + str(coeff[len(coeff)-2]) + 'x_' + str(n) + '=' + str(coeff[len(coeff)-1]) + texEq =textEq+ '$' + # print(texEq) + display(Latex(texEq)) + + + +print("Entrez le nombre variables n=") +n=input() +while type(n)!=int: + try: + n=int(n) + if n<=0: + print("Le nombre de variable ne peut pas être négatif!") + print("Entrez le nombre variables n=") + n=input() + except: + print("Ce n'est pas un entier!") + print("Entrez le nombre variables n=") + n=input() + +n=int(n) +print("Votre équation est de la forme") + +printEq(n, '') + +coeff='' +while type(coeff)!=list and len(coeff)!=n+1: + print("Entrez les ", n," coefficients de l'équations sous le format a1, a2, ..., b") + entry=input() + try: + coeff=[int(x) for x in entry.split(',')] + except: + print("Les coefficients ne sont pas dans le bon format ou vous n'avez pas entré le bon nombre de coefficients!") + + +print("Votre equation est") +printEq(n, coeff) + +#%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +sol='' +while type(sol)!=list and len(sol)!=n: + print("Entrez la solution sous la forme d'une suite de ", n," nombres réels") + entry=input() + try: + sol=[int(x) for x in entry.split(',')] + except: + print("La suite n'est pas dans le bon format ou n'est pas de la bonne longueur!") + +sol=np.asarray(sol[0:len(sol)]) +A = np.asarray(coeff[0:len(coeff)-1]) + +if np.dot(A,sol)==coeff[len(coeff)-1]: + print("La suite entrée est une solution de votre équation!") +else: + print("La suite entrée n'est pas une solution de votre équation!") + + + + + + + + +