Programación

“Primero resuelve el problema. Entonces, escribe el código.” — John Johnson

martes, 20 de marzo de 2018

Libreria de matemáticas

En Raspberry
Linux : using your package mana ger
      sudo apt-get install python3-matplotlib
por si se borro el sympy
      sudo pip3 install sympy

En windows
Installing an official release
Se puede descargar desde http://matplotlib.sourceforge.net/.
Matplotlib and most of its dependencies are all available as wheel packages for macOS, Windows and Linux distributions:
python -mpip install -U pip
python -mpip install -U matplotlib

Puede ser que ya este instalado, de no ser así instale.
pip install numpy

+++++++++++++++++++++++++

Algera1.py
from sympy import I, simplify
print(simplify ((1 + I) /(1 + 2*I)))

++++++++++++++++++++++++++

from sympy import arg , conjugate ,sqrt ,I
#from math import *
#no resuleve  la operación la deja solo simplificada 
#sin comentario de math entonces da un resultado #numérico
a= sqrt (3)+I
print(conjugate (a))

print(abs(a))
print(arg(a))

+++++++++++++++++++++++++

Si necesitamos el valor real de alguna de las operaciones efectuadas con
SymPy, podemos usar el método evalf


c=arg(a). evalf ()
print(c)

+++++++++++++++++++++++++++
from sympy import Symbol ,E,I,re
x= Symbol ('x', real = True )
a=E **(I*x)
b=a. expand ( complex = True )
print(b)
c=a **3
d=c. expand ( complex = True ). expand ( trig = True )
print(d)

+++++++++++++++++++++++++++
print(re(d))
f=c. expand ( complex = True )
print(re(f))
res=(re(f)-re(d)). expand ( trig = True )
print(res)

++++++++++++++++++++++++++
#algebra 4
from sympy import Symbol , solve
x= Symbol ('x ')
print(solve (x**4 -1 ,x))

++++++++++++++++++++++++
Si el resultado esperado es amplio podemos guardarlo en una lista.
from sympy import Symbol , solve,I
x= Symbol ('x ')
print(solve (x**4 -1 ,x))
#es diferete
a= solve (x**4 -I,x)
print(a)

++++++++++++++++++++++++
y luego podemos usar un bucle para, por ejemplo, obtener los valores num_ericos
de cada una de las soluciones:
from sympy import Symbol , solve,I
x= Symbol ('x ')
print(solve (x**4 -1 ,x))
#es diferete
a= solve (x**4 -I,x)
#print(a)
for b in a:
print(b. evalf ())

++++++++++++++++++++
from pylab import *
lista1 = [11,2,3,15,8,13,21,34]
plt.plot(lista1)
plt.show()