Knowledge base dedicated to Linux and applied mathematics.
Accueil > Python > Sympy > Sympy comment définir une variable de fonction, d’intégrale ou de polynome
Toutes les versions de cet article : <English> <français>
Sympy comment définir une variable de fonction, d’intégrale ou de polynome
from sympy import *
x,y,z,t,a,b,c,n,m,p,k = symbols('x y z t a b c n m p k')
sin(x)*exp(x)
$\displaystyle e^{x} \sin{\left(x \right)}$
sin(v)*exp(v)
Puisque v n’est pas définie, nous avons l’erreur suivante :
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-3-e79911d4ea2b> in <module>
----> 1 sin(v)*exp(v)
NameError: name 'v' is not defined
x**4-3*x**2 +15*x -1
$\displaystyle x^{4} - 3 x^{2} + 15 x - 1$
x^^2
Oups ... Vous avez une erreur ...
File "<ipython-input-5-5d18a81177b2>", line 1
x^^2
^
SyntaxError: invalid syntax
Rappelez vous que ^ est un opérateur logique binaire :
alpha,beta=1,10;
print(bin(alpha),bin(beta))
print(alpha^beta == (0b1)^(0b1010));
print(alpha^beta, bin(alpha^beta))
0b1 0b1010
True
11 0b1011
def f(x):
return x**2 + 1
Vérifions la valeur f(3) :
f(3)
10
g = x**2+1
Vérifions la valeur g(3) :
g.subs(x,3)
10
integrate(x**2 + x + 1, x)
$\displaystyle \frac{x^{3}}{3} + \frac{x^{2}}{2} + x$
integrate(t**2 * exp(t) * cos(t))
$\displaystyle \frac{t^{2} e^{t} \sin{\left(t \right)}}{2} + \frac{t^{2} e^{t} \cos{\left(t \right)}}{2} - t e^{t} \sin{\left(t \right)} + \frac{e^{t} \sin{\left(t \right)}}{2} - \frac{e^{t} \cos{\left(t \right)}}{2}$
integrate(f(x))
$\displaystyle \frac{x^{3}}{3} + x$
integrate(g(t))
Rappelerez vous comment g a été définie !!!!
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-14-3849471c42ec> in <module>
----> 1 integrate(g(t))
TypeError: 'Add' object is not callable
Voici la bonne méthode pour intégrer g telle qu’elle a été définie :
integrate(g)
$\displaystyle \frac{x^{3}}{3} + x$
Voila, en espérant que cela vous a aidé !!! Ci-dessous, le notebook jupyter.