In [ ]:
%matplotlib inline
import sympy as sp
import numpy as np
import matplotlib.pyplot as plt
In [ ]:
sp.init_printing() # Turns on pretty printing
In [ ]:
np.sqrt(8)
In [ ]:
sp.sqrt(8)
In [ ]:
x, y, z = sp.symbols('x y z')
In [ ]:
my_equation = 2 * x + y
my_equation
In [ ]:
my_equation + 3
In [ ]:
my_equation - x
In [ ]:
my_equation / x
In [ ]:
sp.simplify(my_equation / x)
In [ ]:
another_equation = (x + 2) * (x - 3)
another_equation
In [ ]:
sp.expand(another_equation)
In [ ]:
yet_another_equation = 2 * x**2 + 5 * x + 3
sp.factor(yet_another_equation)
In [ ]:
sp.solve(yet_another_equation,x)
In [ ]:
long_equation = 2*y*x**3 + 12*x**2 - x + 3 - 8*x**2 + 4*x + x**3 + 5 + 2*y*x**2 + x*y
long_equation
In [ ]:
sp.collect(long_equation,x)
In [ ]:
sp.collect(long_equation,y)
In [ ]:
yet_another_equation
In [ ]:
sp.diff(yet_another_equation,x)
In [ ]:
sp.diff(yet_another_equation,x,2)
In [ ]:
sp.integrate(yet_another_equation,x)
In [ ]:
sp.integrate(yet_another_equation,(x,0,5)) # limits x = 0 to 5
In [ ]:
AA = sp.Matrix([[1,3,5],[2,5,1],[2,3,8]])
bb = sp.Matrix([[10],[8],[3]])
print(AA**-1)
print(AA**-1 * bb)
SymPy
can do so much more. It really is magic. Complete documentation can be found here
In [ ]:
plt.style.use('ggplot')
x = np.linspace(0,2*np.pi,100)
y = np.sin(5*x) * np.exp(-x)
plt.plot(x,y)
plt.title("The function $y\ =\ \sin(5x)\ e^{-x}$")
plt.xlabel("This is in units of 2$\pi$")
plt.text(2.0, 0.4, '$\Delta t = \gamma\, \Delta t$', color='green', fontsize=36)
In [ ]:
a = 1/( ( z + 2 ) * ( z + 1 ) )
print(sp.latex(a))
In [ ]:
print(sp.latex(sp.Integral(z**2,z)))
In [ ]:
from astropy.io import ascii
from astropy.table import QTable
In [ ]:
my_table = QTable.read('Zodiac.csv', format='ascii.csv')
In [ ]:
my_table[0:3]
In [ ]:
ascii.write(my_table, format='latex')
In [ ]:
t = np.linspace(0,12*np.pi,2000)
fig,ax = plt.subplots(1,1) # One window
fig.set_size_inches(11,8.5) # (width,height) - letter paper landscape
fig.tight_layout() # Make better use of space on plot