La branche étudiante de l'IEEE propose, ce jeudi 25 février de 13 h 30 à 17 h 30, une formation à Mathematica pour donner les bases de ce logiciel. L'inscription est nécessaire. http://ieee.aees.be/fr/accueil/25-francais/activites/conferences/151-formation-mathematica
Pour que la division soit comme en Python 3:
from __future__ import division
Importer toutes les fonctions et quelques variables de Sympy:
from sympy import *
from sympy.abc import a,b,c,k,n,t,u,v,w,x,y,z
init_printing(pretty_print=True, use_latex='mathjax')
Calculer le pgcd de $$p(x)=x^5 - 20x^4 + 140x^3 - 430x^2 + 579x - 270$$ et $$q(x)=x^6 - 25x^5 + 243x^4 - 1163x^3 + 2852x^2 - 3348x + 1440$$
p = x**5 - 20*x**4 + 140*x**3 - 430*x**2 + 579*x - 270
q = x**6 - 25*x**5 + 243*x**4 - 1163*x**3 + 2852*x**2 - 3348*x + 1440
gcd(4,6)
gcd(p,q)
from sympy.abc import x
limit(1/x, x, 0, dir='+')
oo
limit(1/x, x, oo)
Calculer la somme des nombres 134,245,325,412,57.
sum([134, 245, 325, 412, 57])
sum([134, 245, 325, 412, 57, x])
sum([134, 245, 325, 412, 57, x, []])
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-11-86a5c62c0901> in <module>() ----> 1 sum([134, 245, 325, 412, 57, x, []]) TypeError: unsupported operand type(s) for +: 'Add' and 'list'
Caluler la somme $$\sum_{i=0}^n i$$
from sympy.abc import i
summation(i, (i,0,n))
summation(i**2, (i,0,2016))
Calculer la somme $$\sum_{k=1}^\infty {1 \over k^6}$$
summation(1/k**6, (k, 1, oo))
Calculer le produit $$\prod_{n=1}^{2016} 2n+1$$
product(2*n+1, (n,1,2016))
Calculer la dérivée de $$x^5+bx$$
b,x
diff(x**5+b*x, b)
diff(x**5+b*x, x)
Calculer la dérivée de $$\arcsin(x)$$
diff(asin(x), x)
Calculer l'intégrale $$\int\log(x)\, dx$$
integrate(log(x), x)
Calculer l'intégrale $$\int a^x\, dx$$
integrate(a**x, x)
Calculer l'intégrale $$\int x^a\, dx$$
integrate(x**a, x)
log(100, 10)
log?
Calculer l'intégrale $$\int \sec^2(x)\,dx$$
integrate(sec(x)**2, x)
integrate(integrate(x**2*y, x), y)
integrate(x**2*y, (x,0,2), (y,0,5))
A = Sum(1/k**6, (k,1,oo))
B = Product(2*n+1, (n,1,21))
C = Derivative(asin(x), x)
D = Integral(log(x), x)
Eq(A, A.doit())
Eq(B, B.doit())
Eq(C, C.doit())
Eq(D, D.doit())
Calculer la série de Taylor de $\tan(x)$ en $x_0=0$ d'ordre 14.
series(tan(x), x, 0, 14)
series(sin(x), x, 0, 10)
from sympy import E
A = Derivative(E**x, x)
Eq(A, A.doit())
Trouver une fonction $f(x)$ telle que ${d\over dx} f(x) = f(x)$
f = Function('f')
f(x)
eq = Eq(Derivative(f(x),x), f(x))
dsolve(eq)
Trouver une fonction $f(x)$ telle que ${d^2\over dx^2} f(x) = -f(x)$
eq2 = Eq(Derivative(f(x),x,x), -f(x))
dsolve(eq2)
Derivative(f(x),x,x,x,x,x)
Derivative(f(x),x,5)
f(x).diff(x,5)
Résoudre$$y''-4y'+5y=0$$.
from sympy.abc import x,y
eq = Eq(y(x).diff(x,x)-4*y(x).diff(x)+5*y(x),0)
dsolve(eq, y(x))
Définir la matrice $$M=\begin{bmatrix} 2& 9& 3\\ 4& 5& 10\\ 2& 0& 3 \end{bmatrix}$$
Matrix([[2, 9, 3], [4, 5, 10], [2, 0, 3]])
M = Matrix(3,3,[2, 9, 3, 4, 5, 10, 2, 0, 3])
Définir la matrice $$N=\begin{bmatrix} 2& 9& 3\\ 4& 5& 10\\ -6& -1& -17 \end{bmatrix}$$
N = Matrix(3,3,[2,9,3,4,5,10,-6,-1,-17]); N
Définir le vecteur $$v=\begin{bmatrix} 5\\ 2\\ 1 \end{bmatrix}$$
v = Matrix([5,2,1]); v
M, N
M + N
M * 3
M * N
M * v
M ** -1
N ** -1
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-82-086bca9c1aa4> in <module>() ----> 1 N ** -1 /Users/slabbe/Applications/sage-git/local/lib/python2.7/site-packages/sympy/core/decorators.pyc in binary_op_wrapper(self, other) 116 else: 117 return f(self) --> 118 return func(self, other) 119 return binary_op_wrapper 120 return priority_decorator /Users/slabbe/Applications/sage-git/local/lib/python2.7/site-packages/sympy/matrices/dense.pyc in __pow__(self, other) 561 @call_highest_priority('__rpow__') 562 def __pow__(self, other): --> 563 return super(DenseMatrix, self).__pow__(other) 564 565 @call_highest_priority('__pow__') /Users/slabbe/Applications/sage-git/local/lib/python2.7/site-packages/sympy/matrices/matrices.pyc in __pow__(self, num) 537 n = int(num) 538 if n < 0: --> 539 return self.inv()**-n # A**-2 = (A**-1)**2 540 a = eye(self.cols) 541 s = self /Users/slabbe/Applications/sage-git/local/lib/python2.7/site-packages/sympy/matrices/matrices.pyc in inv(self, method, **kwargs) 307 if method is not None: 308 kwargs['method'] = method --> 309 return self._eval_inverse(**kwargs) 310 311 def inv_mod(self, m): /Users/slabbe/Applications/sage-git/local/lib/python2.7/site-packages/sympy/matrices/dense.pyc in _eval_inverse(self, **kwargs) 304 M = self.as_mutable() 305 if method == "GE": --> 306 rv = M.inverse_GE(iszerofunc=iszerofunc) 307 elif method == "LU": 308 rv = M.inverse_LU(iszerofunc=iszerofunc) /Users/slabbe/Applications/sage-git/local/lib/python2.7/site-packages/sympy/matrices/matrices.pyc in inverse_GE(self, iszerofunc) 2629 red = big.rref(iszerofunc=iszerofunc, simplify=True)[0] 2630 if any(iszerofunc(red[j, j]) for j in range(red.rows)): -> 2631 raise ValueError("Matrix det == 0; not invertible.") 2632 2633 return self._new(red[:, big.rows:]) ValueError: Matrix det == 0; not invertible.
M.transpose()
M
M[1,1]
M[2,1]
M.row(0)
M.col(1)
M
M[0,0] = pi
zeros(4,6)
ones(3,8)
eye(5)
diag(3,4,5)
diag(3,4,5,M)
Calculer la forme échelonnée réduite de $M$ et $N$.
M
M.rref()
N
N.rref()
Calculer le noyau des matrices $M$ et $N$.
M.nullspace()
N.nullspace()
Calculer le déterminant des matrices $M$ et $N$.
M.det()
N.det()
Calculer le polynôme caractérisque de la matrice $M$ et de $N$.
from sympy.abc import x
M.charpoly(x)
M.charpoly(x).as_expr()
N.charpoly(x).as_expr()
Calculer les valeurs propres et vecteurs propres de $$K=\begin{bmatrix} 93& 27& -57\\ -40& 180& -140\\ -15& 27& 51 \end{bmatrix}$$
K = Matrix(3,3,[93,27,-57,-40,180,-140,-15,27,51])
K
K.eigenvals()
K.eigenvects()
En général, les racines peuvent être plus compliquées:
M.eigenvals()