sympy.ipynb
267 lines
| 36.2 KiB
| text/plain
|
TextLexer
SymPy: Open Source Symbolic Mathematics
In [1]:
%load_ext sympyprinting
In [2]:
from __future__ import division
from sympy import *
x, y, z = symbols("x y z")
k, m, n = symbols("k m n", integer=True)
f, g, h = map(Function, 'fgh')
Elementary operations
In [3]:
Rational(3,2)*pi + exp(I*x) / (x**2 + y)
Out[3]:
In [4]:
exp(I*x).subs(x,pi).evalf()
Out[4]:
In [5]:
e = x + 2*y
In [6]:
srepr(e)
Out[6]:
In [7]:
exp(pi * sqrt(163)).evalf(50)
Out[7]:
Algebra
In [8]:
((x+y)**2 * (x+1)).expand()
Out[8]:
In [9]:
a = 1/x + (x*sin(x) - 1)/x
display(a)
simplify(a)
Out[9]:
In [10]:
solve(Eq(x**3 + 2*x**2 + 4*x + 8, 0), x)
Out[10]:
In [11]:
a, b = symbols('a b')
Sum(6*n**2 + 2**n, (n, a, b))
Out[11]:
Calculus
In [12]:
limit((sin(x)-x)/x**3, x, 0)
Out[12]:
In [13]:
(1/cos(x)).series(x, 0, 6)
Out[13]:
In [14]:
diff(cos(x**2)**2 / (1+x), x)
Out[14]:
In [15]:
integrate(x**2 * cos(x), (x, 0, pi/2))
Out[15]:
In [16]:
eqn = Eq(Derivative(f(x),x,x) + 9*f(x), 1)
display(eqn)
dsolve(eqn, f(x))
Out[16]: