#!/usr/bin/env python # coding: utf-8 # # 1. Introduction # # - Installation à la maison: # - Windows, Mac ou Linux? # - installer la suite Anaconda OU SageMath (www.sagemath.org) # - Faire le "User Interface Tour" # - Parler de la méthode expérimentale # # 2. Calculatrice et arithmétique avec Python # 2.1 Opérations de base en Python # 2.2 Exposant # 2.3 Racine n-ième # 2.4 Reste et quotient de la division # 2.5 Fonctions et constantes mathématiques en Python # 2.6 Accéder à la documentation d'une fonction # 2.7 Parenthèses et priorité des opérations # 2.8 Variables et affectation # In[12]: lage_de_quelqun3 = 3 # In[13]: lage_de_quelqun3 + 1 # In[5]: x + 2 # 2.9 Opérateurs de comparaison et d'égalités # In[15]: 2 + 3 == 5 # In[19]: 2 + 3 <= 5 # In[21]: 4 + 5 >= 3 # In[22]: 23 != 34 # # 3. Calculatrice et arithmétique avec SymPy # # - http://www.sympy.org/ # - En ligne: http://gamma.sympy.org/, http://live.sympy.org/ # - Aperçu des fonctionalités: http://www.sympy.org/en/features.html # - Documentation complète (anglais): http://docs.sympy.org/ # 3.1 Nombres rationels # In[24]: from sympy import Rational # In[26]: Rational(1324, 1232) # In[29]: Rational(1, 124) + 23 # In[30]: Rational(4,5) # 3.2 Nombres complexes # In[31]: from sympy import I # In[33]: I ** 2 # In[36]: a = 2 + 8*I # In[38]: a # In[39]: a.conjugate() # In[40]: abs(a) # In[ ]: # In[ ]: # In[ ]: # In[ ]: # In[ ]: # 3.3 Calculer une valeur numérique # In[41]: from sympy import pi,E # In[48]: pi.evalf(100) # In[ ]: # In[ ]: # In[ ]: # 3.4 Factoriser un nombre entier # In[49]: from sympy import factor # In[50]: factor(3247856343789135) # In[53]: get_ipython().run_line_magic('pinfo', 'factor(24)') # In[54]: from sympy import factorint # In[57]: factorint(3247856343789135) # In[58]: factorint(3247856343789135,visual=True) # In[59]: from sympy import init_printing init_printing(pretty_print=True) # In[60]: factorint(3247856343789135,visual=True) # In[61]: factorint(3247856343789135) # In[ ]: # 3.5 Accéder à la documentation et au code source d'une fonction # In[62]: from sympy import simplify # In[63]: get_ipython().run_line_magic('pinfo2', 'simplify') # # 4 Calcul symbolique # In[64]: from math import sqrt # In[66]: sqrt(4) # In[68]: sqrt(3) # In[80]: from sympy import sqrt init_printing(pretty_print=True) # In[70]: sqrt(4) # In[73]: sqrt(3) # 4.1 Variable symbolique # In[82]: from sympy import Symbol a = Symbol('a') b = Symbol('b') # In[84]: (a + a + 1) ** (a + b) # In[85]: from sympy.abc import a,b # In[86]: a + b # In[87]: from sympy.abc import a,b,delta # In[88]: delta + a # In[ ]: # In[ ]: # In[ ]: # 4.2 Affichage automatique des résultats en LaTeX # In[ ]: # 4.3 Expressions symboliques # In[90]: from sympy import sin,cos sin(a)**2 + cos(a)**2 # In[91]: simplify(_) # In[92]: _, __, ___ # In[96]: Out[90] # In[98]: In[90] # In[99]: from math import sin # In[100]: sin(a) # 4.4 Représentation interne # 4.5 Substitutions # In[101]: expression = (a+b)**2 # In[103]: expression.subs(a, 8) # In[104]: expression.subs({a: 8, b: 34}) # In[ ]: # In[ ]: # In[ ]: # 4.6 Constantes symboliques # 4.7 Simplifier une expression # 4.8 Développer une expression # In[107]: expression = (a+b)**10 expression # In[108]: from sympy import expand expand(expression) # In[ ]: # In[ ]: # In[ ]: # 4.9 Annuler les facteurs communs d'une fraction # 4.10 Factoriser un polynôme # 4.11 Rassembler les termes d'une expression # 4.12 Réduire au même dénominateur # In[110]: from sympy.abc import x,y,z expression = 1/x + (3-x)/z + y/(1-x) expression # In[113]: from sympy import ratsimp,together # In[112]: ratsimp(expression) # In[125]: result = together(expression) result # In[ ]: # In[ ]: # 4.13 Décomposition en fractions partielles # In[122]: facile = 1 /( (x-1) * (x-2)) facile # In[120]: from sympy import apart # In[123]: apart(facile) # In[124]: apart(result, x) # # 5 Résolution d'équations, trouver les racines d'une fonction # 5.1 Définir une équation # 5.2 Résoudre une équation # 5.3 Résoudre un système d'équations # 5.4 Syntaxe abrégée # 5.5 Trouver les racines d'une fonction # # 6 Tracer une fonction # 6.1 Dessin 2d # 6.2 Dessin 3d # In[ ]: