diff --git a/Chapitre 1 - Systemes equations lineaires/AL_newFct.py b/Chapitre 1 - Systemes equations lineaires/AL_newFct.py new file mode 100644 index 0000000..24b60e5 --- /dev/null +++ b/Chapitre 1 - Systemes equations lineaires/AL_newFct.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Mar 13 16:42:29 2019 + +@author: jecker +""" + +def printEq(n,coeff):# Latex Print of one equation in format a1x1+ ...+anxn or with coefficients. + textEq='$' + if coeff=='': + if n==1: + textEq=textEq + 'a_1x_1 = b' + elif n==2: + textEq=textEq + 'a_1x_1 + a_2x_2 = b' + else: + textEq=textEq + 'a_1x_1 + \ldots + ' + 'a_' + str(n) + 'x_'+ str(n) + '=b' + else : + textEq=textEq + str(coeff[0] if coeff[0] % 1 else int(coeff[0]))+ 'x_'+str(1) + for i in range(1,n-1): + textEq=textEq + ' + ' + str(coeff[i] if coeff[i] %1 else int(coeff[i])) + 'x_' + str(i+1) + textEq=textEq + ' + ' +str(coeff[len(coeff)-2] if coeff[len(coeff)-2] % 1 else int(coeff[len(coeff)-2])) + 'x_' + str(n) + '=' + str(coeff[len(coeff)-1] if coeff[len(coeff)-1] % 1 else int(coeff[len(coeff)-1])) + texEq =textEq+ '$' + # print(texEq) + display(Latex(texEq)) + + + +def EnterInt(n): #function enter integer. + while type(n)!=int: + try: + n=int(n) + if n<=0: + print("Le nombre ne peut pas être négatif!") + print("Entrez à nouveau : ") + n=input() + except: + print("Ce n'est pas un entier!") + print("Entrez à nouveau :") + n=input() + n=int(n) + return n + +def EnterListReal(n,coeff): #function enter list of real numbers. + while type(coeff)!=list: + try: + coeff=[float(x) for x in coeff.split(',')] + if len(coeff)!=n+1: + print("Vous n'avez pas entré le bon nombre de réels!") + print("Entrez à nouveau : ") + coeff=input() + except: + print("Ce n'est pas le bon format!") + print("Entrez à nouveau") + coeff=input() + return coeff + +def SolOfEq(sol,coeff): #Verify if sol is the solution of the equation with coefficients coeff + 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!") diff --git a/Chapitre 1 - Systemes equations lineaires/Intro_1_1.py b/Chapitre 1 - Systemes equations lineaires/Intro_1_1.py new file mode 100644 index 0000000..5aaed19 --- /dev/null +++ b/Chapitre 1 - Systemes equations lineaires/Intro_1_1.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon Mar 11 10:13:39 2019 + +@author: jecker +""" +import numpy as np + +import AL_newFct as al + +print("Entrez le nombre de variables n=") #function EnterInt but we might need to specify what int we want: variable, nbr equation,.. +n=input() +n=al.EnterInt(n) + +print("Votre équation est de la forme") +al.printEq(n, '') + +print("Entrez les ", n+1," coefficients de l'équations sous le format a1, a2, ..., b") +entry=input() +coeff=al.EnterListReal(n,entry) + +print("Votre equation est") +al.printEq(n, coeff) + +#%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +print("Entrez la solution sous la forme d'une suite de ", n," nombres réels") +entry=input() +sol=al.EnterListReal(n-1,entry) + +sol=np.asarray(sol[0:len(sol)]) +al.SolOfEq(sol, coeff) +#%%%%%%%%%% + + + + + + + + diff --git a/Chapitre 1 - Systemes equations lineaires/__pycache__/AL_newFct.cpython-37.pyc b/Chapitre 1 - Systemes equations lineaires/__pycache__/AL_newFct.cpython-37.pyc new file mode 100644 index 0000000..dcfcabc Binary files /dev/null and b/Chapitre 1 - Systemes equations lineaires/__pycache__/AL_newFct.cpython-37.pyc differ diff --git a/Chapitre 1 - Systemes equations lineaires/test1.py b/Chapitre 1 - Systemes equations lineaires/test1.py deleted file mode 100644 index f96e1f8..0000000 --- a/Chapitre 1 - Systemes equations lineaires/test1.py +++ /dev/null @@ -1,87 +0,0 @@ -#!/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!") - - - - - - - - -