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


Out[13]:
4

In [5]:
x + 2


Out[5]:
5

2.9 Opérateurs de comparaison et d'égalités


In [15]:
2 + 3 == 5


Out[15]:
True

In [19]:
2 + 3 <= 5


Out[19]:
True

In [21]:
4 + 5 >= 3


Out[21]:
True

In [22]:
23 != 34


Out[22]:
True

3. Calculatrice et arithmétique avec SymPy

3.1 Nombres rationels


In [24]:
from sympy import Rational

In [26]:
Rational(1324, 1232)


Out[26]:
331/308

In [29]:
Rational(1, 124) + 23


Out[29]:
2853/124

In [30]:
Rational(4,5)


Out[30]:
4/5

3.2 Nombres complexes


In [31]:
from sympy import I

In [33]:
I ** 2


Out[33]:
-1

In [36]:
a = 2 + 8*I

In [38]:
a


Out[38]:
2 + 8*I

In [39]:
a.conjugate()


Out[39]:
2 - 8*I

In [40]:
abs(a)


Out[40]:
2*sqrt(17)

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:

3.3 Calculer une valeur numérique


In [41]:
from sympy import pi,E

In [48]:
pi.evalf(100)


Out[48]:
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068

In [ ]:


In [ ]:


In [ ]:

3.4 Factoriser un nombre entier


In [49]:
from sympy import factor

In [50]:
factor(3247856343789135)


Out[50]:
3247856343789135

In [53]:
?factor(24)

In [54]:
from sympy import factorint

In [57]:
factorint(3247856343789135)


Out[57]:
{3: 1, 5: 1, 13: 1, 389: 1, 4987: 1, 8585651: 1}

In [58]:
factorint(3247856343789135,visual=True)


Out[58]:
13**1*3**1*389**1*4987**1*5**1*8585651**1

In [59]:
from sympy import init_printing
init_printing(pretty_print=True)

In [60]:
factorint(3247856343789135,visual=True)


Out[60]:
$$13^{1} \cdot 3^{1} \cdot 389^{1} \cdot 4987^{1} \cdot 5^{1} \cdot 8585651^{1}$$

In [61]:
factorint(3247856343789135)


Out[61]:
$$\left \{ 3 : 1, \quad 5 : 1, \quad 13 : 1, \quad 389 : 1, \quad 4987 : 1, \quad 8585651 : 1\right \}$$

In [ ]:

3.5 Accéder à la documentation et au code source d'une fonction


In [62]:
from sympy import simplify

In [63]:
simplify??

4 Calcul symbolique


In [64]:
from math import sqrt

In [66]:
sqrt(4)


Out[66]:
$$2.0$$

In [68]:
sqrt(3)


Out[68]:
$$1.73205080757$$

In [80]:
from sympy import sqrt
init_printing(pretty_print=True)

In [70]:
sqrt(4)


Out[70]:
$$2$$

In [73]:
sqrt(3)


Out[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)


Out[84]:
$$\left(2 a + 1\right)^{a + b}$$

In [85]:
from sympy.abc import a,b

In [86]:
a + b


Out[86]:
$$a + b$$

In [87]:
from sympy.abc import a,b,delta

In [88]:
delta + a


Out[88]:
$$a + \delta$$

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


Out[90]:
$$\sin^{2}{\left (a \right )} + \cos^{2}{\left (a \right )}$$

In [91]:
simplify(_)


Out[91]:
$$1$$

In [92]:
_, __, ___


Out[92]:
$$\left ( 1, \quad \sin^{2}{\left (a \right )} + \cos^{2}{\left (a \right )}, \quad \sin{\left (a \right )}\right )$$

In [96]:
Out[90]


Out[96]:
$$\sin^{2}{\left (a \right )} + \cos^{2}{\left (a \right )}$$

In [98]:
In[90]


Out[98]:
u'from sympy import sin,cos\nsin(a)**2 + cos(a)**2'

In [99]:
from math import sin

In [100]:
sin(a)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-100-66bf5e82d1e2> in <module>()
----> 1 sin(a)

/Users/slabbe/Applications/sage-git/local/lib/python2.7/site-packages/sympy/core/expr.pyc in __float__(self)
    223         if result.is_number and result.as_real_imag()[1]:
    224             raise TypeError("can't convert complex to float")
--> 225         raise TypeError("can't convert expression to float")
    226 
    227     def __complex__(self):

TypeError: can't convert expression to float

4.4 Représentation interne

4.5 Substitutions


In [101]:
expression = (a+b)**2

In [103]:
expression.subs(a, 8)


Out[103]:
$$\left(b + 8\right)^{2}$$

In [104]:
expression.subs({a: 8, b: 34})


Out[104]:
$$1764$$

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


Out[107]:
$$\left(a + b\right)^{10}$$

In [108]:
from sympy import expand
expand(expression)


Out[108]:
$$a^{10} + 10 a^{9} b + 45 a^{8} b^{2} + 120 a^{7} b^{3} + 210 a^{6} b^{4} + 252 a^{5} b^{5} + 210 a^{4} b^{6} + 120 a^{3} b^{7} + 45 a^{2} b^{8} + 10 a b^{9} + b^{10}$$

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


Out[110]:
$$\frac{y}{- x + 1} + \frac{1}{z} \left(- x + 3\right) + \frac{1}{x}$$

In [113]:
from sympy import ratsimp,together

In [112]:
ratsimp(expression)


Out[112]:
$$- \frac{1}{x^{2} z - x z} \left(x^{3} - 4 x^{2} + x y z - x z + 3 x + z\right)$$

In [125]:
result = together(expression)
result


Out[125]:
$$\frac{1}{x z \left(- x + 1\right)} \left(x y z + x \left(- x + 1\right) \left(- x + 3\right) + z \left(- x + 1\right)\right)$$

In [ ]:


In [ ]:

4.13 Décomposition en fractions partielles


In [122]:
facile = 1 /( (x-1) * (x-2))
facile


Out[122]:
$$\frac{1}{\left(x - 2\right) \left(x - 1\right)}$$

In [120]:
from sympy import apart

In [123]:
apart(facile)


Out[123]:
$$- \frac{1}{x - 1} + \frac{1}{x - 2}$$

In [124]:
apart(result, x)


Out[124]:
$$- \frac{x}{z} - \frac{y}{x - 1} + \frac{3}{z} + \frac{1}{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 [ ]: