Calcul formel avec sympy

In [1]:
from sympy import *
a = Symbol("a")
b = Symbol("b")

Développer

In [2]:
expand((a+b)**2)
Out[2]:
a**2 + 2*a*b + b**2

Factoriser

In [3]:
factor(a**3-1)
Out[3]:
(a - 1)*(a**2 + a + 1)

Racines carrées

Simplifier $\sqrt{75} + \sqrt{48}$

In [4]:
radsimp(sqrt(75)+sqrt(48))
Out[4]:
9*sqrt(3)

Enlever les racines carrées du dénominateur de $\dfrac{5}{1+\sqrt{2}}$

In [5]:
radsimp(5/(1 + sqrt(2))
Out[5]:
-5 + 5*sqrt(2)

Représentation graphique de fonction

In [6]:
x = Symbol("x")
plot(x**2,(x,-4,4))
Out[6]:
<sympy.plotting.plot.Plot at 0x7fec4d31fcc0>

Intégration

Primitive de $x \mapsto x^2$

In [7]:
integrate(x**2, x)
Out[7]:
x**3/3

Calcul de $\displaystyle\int_2^7 x^2 ~dx$

In [31]:
print(integrate(x**2, (x,2,7)))
335/3

Dérivation

In [9]:
diff(x**5,x)
Out[9]:
5*x**4
In [41]:
diff(x*ln(x) - x , x)
Out[41]:
log(x)
In [10]:
diff(ln(a*x)+exp(b*x),x)
Out[10]:
b*exp(b*x) + 1/x
In [19]:
diff(ln(a*x)+exp(b*x),a)
Out[19]:
1/a

Limites

In [21]:
limit(exp(x)/x, x, 00)
Out[21]:
oo

Equations

Résolution de $x^2 = 3$

In [22]:
solveset(Eq(x**2 , 3), x)
Out[22]:
{-sqrt(3), sqrt(3)}

Résolution de $ax^2+bx+c = 0$

In [26]:
c = Symbol("c")
solveset(Eq(a*x**2 + b*x + c , 0) , x)
Out[26]:
{-c/(2*a) - sqrt(-c*(4*a - c))/(2*a), -c/(2*a) + sqrt(-c*(4*a - c))/(2*a)}

Divers

Simplification de $\ln(8) + \ln(45) + \ln(100)$

In [27]:
simplify(ln(8) + ln(45)+ln(100))
Out[27]:
log(36000)

Simplification de $\dfrac{1}{x} + \dfrac{1}{x+1} + \dfrac{1}{(x+1)^2}$

In [30]:
ratsimp(1/x + 1/(x+1) + 1/(x+1)**2)
Out[30]:
(2*x**2 + 4*x + 1)/(x**3 + 2*x**2 + x)

Problèmes

In [38]:
factor(x**2 - 0.25)
Out[38]:
1.0*(0.5*x - 0.25)*(0.5*x + 0.25)
In [39]:
factor(x**2 - 1/4)
Out[39]:
1.0*(0.5*x - 0.25)*(0.5*x + 0.25)
In [40]:
factor(x**2 - Rational(1/4))
Out[40]:
(2*x - 1)*(2*x + 1)/4
In [ ]: