Toggle Sidebar

Sympy notebook demo

A demonstration of the output of converting a notebook with demonsration of SymPy into a markdown file

from sympy import *


init_session(quiet=True)

IPython console for SymPy 0.7.6 (Python 2.7.10-32-bit) (ground types: python)



Integral(sqrt(1/x))
$$\int \sqrt{\frac{1}{x}}\, dx$$
x = symbols('x')


a = Integral(cos(x)*exp(x), x)


Eq(a, a.doit())
$$\int e^{x} \cos{\left (x \right )}\, dx = \frac{e^{x}}{2} \sin{\left (x \right )} + \frac{e^{x}}{2} \cos{\left (x \right )}$$
import numpy as np


np.sqrt(9)
$$3.0$$
np.sqrt(8)
$$2.82842712475$$
sqrt(8)
$$2 \sqrt{2}$$
x, y = symbols('x y')


expr = 2*x + x*y


x*expr
$$x \left(x y + 2 x\right)$$
expand(x*expr)
$$x^{2} y + 2 x^{2}$$
x, t, z, nu = symbols('x t z nu')


init_printing(use_unicode=True)


nu
$$\nu$$
diff(sin(x)*exp(x),x)
$$e^{x} \sin{\left (x \right )} + e^{x} \cos{\left (x \right )}$$
integrate(exp(x)*sin(x)+exp(x)*cos(x))
$$e^{x} \sin{\left (x \right )}$$
integrate(sin(x**2), (x, -infty, infty))


---------------------------------------------------------------------------

NameError                                 Traceback (most recent call last)

<ipython-input-22-2181c5406759> in <module>()
----> 1 integrate(sin(x**2), (x, -infty, infty))


NameError: name 'infty' is not defined



integrate(sin(x**2), (x, -oo, oo))
$$\frac{\sqrt{2} \sqrt{\pi}}{2}$$
y = Function('y')


dsolve(Eq(y(t).diff(t,t) - y(t), exp(t)), y(t))
$$y{\left (t \right )} = C_{2} e^{- t} + \left(C_{1} + \frac{t}{2}\right) e^{t}$$
Matrix([[1, 2], [2, 2]]).eigenvals()
$$\left \{ \frac{3}{2} + \frac{\sqrt{17}}{2} : 1, \quad - \frac{\sqrt{17}}{2} + \frac{3}{2} : 1\right \}$$
besselj(nu, z).rewrite(jn)
$$\frac{\sqrt{2} \sqrt{z}}{\sqrt{\pi}} j_{\nu - \frac{1}{2}}\left(z\right)$$
print(latex(Integral(cos(x)**2, (x, 0, pi))))

\int_{0}^{\pi} \cos^{2}{\left (x \right )}\, dx



expr = sin(2*x) + cos(2*x)
expr.subs(sin(2*x), expand_trig(sin(2*x)))
$$2 \sin{\left (x \right )} \cos{\left (x \right )} + \cos{\left (2 x \right )}$$
x,y,z, = symbols('x y z')


expr2 = x**3 + 4*x*y - z
expr3 = expr2.subs([(x, sin(x)), (y, 4), (z, 0)])


expr4 = expr2.evalf(subs={x: 2.4})
print expr3

sin(x)**3 + 16*sin(x)



import numpy as np
f = lambdify(x, expr3, "numpy")
a = np.linspace(0,1,100)


%matplotlib inline


import matplotlib.pyplot as plt
plt.plot(a,f(a))




[<matplotlib.lines.Line2D at 0xcbcd828>]

png

from sympy.abc import x, y, mu, r, tau
print(latex((2*tau)**Rational(7,2)))

8 \sqrt{2} \tau^{\frac{7}{2}}