0% found this document useful (0 votes)
27 views3 pages

Para Una Mejor Visualización de Ecuaciones: From Import

This document discusses various mathematical operations in Python using the Sympy library. It shows how to: 1) Symbolically expand and simplify expressions, substitute values into expressions, and collect similar terms together. 2) Solve equations symbolically, including systems of linear and nonlinear equations. 3) Perform derivatives and integrals of functions symbolically.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

Para Una Mejor Visualización de Ecuaciones: From Import

This document discusses various mathematical operations in Python using the Sympy library. It shows how to: 1) Symbolically expand and simplify expressions, substitute values into expressions, and collect similar terms together. 2) Solve equations symbolically, including systems of linear and nonlinear equations. 3) Perform derivatives and integrals of functions symbolically.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Para una mejor visualizacin de ecuaciones

>>> from sympy import init_printing


>>> init_printing(use_unicode=False, wrap_line=False, no_global=True)
Importar simbolos
>>> from sympy import Symbol
>>> x = Symbol(x)
>>> y = Symbol(y)
>>> a, b, c = symbols(a,b,c)

Expandir
>>> ((x+y)**2).expand()
x**2 + 2*x*y + y**2
Sustituir
>>> ((x+y)**2).subs(x, y)
4*y**2
>>> ((x+y)**2).subs(x, 1-y)
1
Apartar
>>> 1/( (x+2)*(x+1) )
1
--------------(x + 1)*(x + 2)
>>> apart(1/( (x+2)*(x+1) ), x)
11
- ----- + ----x+2x+1
>>> (x+1)/(x-1)
x+1
----x-1
>>> apart((x+1)/(x-1), x)
2
1 + ----x1

Juntar
>>> from sympy import together
>>> together(1/x + 1/y + 1/z)
x*y + x*z + y*z
--------------x*y*z
>>> together(apart((x+1)/(x-1), x), x)
x+1
----x-1
>>> together(apart(1/( (x+2)*(x+1) ), x), x)
1
---------------

Resolver sistemas de ecuaciones

>>> from sympy.solvers import solve


>>> from sympy import Symbol
>>> x = Symbol('x')
>>> solve(x**2 - 1, x)
[-1, 1]
>>> from sympy import solve, symbols
>>> x, y = symbols(x,y)
>>> solve(x**4 - 1, x)
[-1, 1, -I, I]
>>> solve([x + 5*y - 2, -3*x + 6*y - 15], [x, y])
{x: -3, y: 1}
>>> from sympy.solvers import solve
>>> from sympy import Symbol
>>> x = Symbol(x)
>>> solve(x**2 - 1, x)
[-1, 1]

Resolver sistemas lineales con matriz LU


>>> A = matrix([[1, 2], [3, 4]])
>>> b = matrix([-10, 10])
>>> x = lu_solve(A, b)
>>> x
matrix(
[[30.0],
[-20.0]])

>>> from sympy import Matrix, solve_linear_system


>>> from sympy.abc import x, y

Solve the following system:


x + 4 y == 2
-2 x + y == 14
>>> system = Matrix(( (1, 4, 2), (-2, 1, 14)))
>>> solve_linear_system(system, x, y)
{x: -6, y: 2}

sympy.solvers.solvers.
>>> from sympy import Matrix
>>> from sympy.abc import x, y, z
>>> from sympy.solvers.solvers import solve_linear_system_LU
>>> solve_linear_system_LU(Matrix([
... [1, 2, 0, 1],
... [3, 2, 2, 1],
... [2, 0, 0, 1]]), [x, y, z])
{x: 1/2, y: 1/4, z: -1/2}

Resolver sistemas de ecuaciones no lienales

>>> from sympy import roots, solve_poly_system


>>> solve(x**3 + 2*x + 3, x)
____ ____
1 \/ 11 *I 1 \/ 11 *I
[-1, - - --------, - + --------]
2222
>>> p = Symbol(p)
>>> q = Symbol(q)
>>> sorted(solve(x**2 + p*x + q, x))
__________ __________
/2/2
p \/ p - 4*q p \/ p - 4*q
[- - + -------------, - - - -------------]
2222
>>> solve_poly_system([y - x, x - 5], x, y)
[(5, 5)]
>>> solve_poly_system([y**2 - x**3 + 1, y*x], x, y)
___ ___
1 \/ 3 *I 1 \/ 3 *I
[(0, I), (0, -I), (1, 0), (- - + -------, 0), (- - - -------, 0)]
2222

Derivadas
>>> from sympy import diff, Symbol, sin, tan
>>> x = Symbol(x)
>>> diff(sin(x), x)
cos(x)
>>> diff(sin(2*x), x)
2*cos(2*x)
>>> diff(tan(x), x)
2
tan (x) + 1

Integrales
>>> from sympy import integrate, erf, exp, sin, log, oo, pi, sinh, symbols
>>> x, y = symbols(x,y)

You can integrate elementary functions:


>>> integrate(6*x**5, x)
6
x
>>> integrate(sin(x), x)
-cos(x)
>>> integrate(log(x), x)
x*log(x) - x
>>> integrate(2*x + sinh(x), x)
2
x + cosh(x)

Also special functions are handled easily:


>>> integrate(exp(-x**2)*erf(x), x)
____ 2
\/ pi *erf (x)
-------------4

You might also like