# Some Random SymPy Stuff


```python
import sympy as sp
sp.init_printing()

# for older SymPy versions:
#%load_ext sympy.interactive.ipythonprinting

# for even older IPython/SymPy versions:
#%load_ext sympyprinting
```


```python
x, y = sp.symbols("x y")
```


```python
(sp.pi + x) ** 2
```


```python
expr = ((x + y)**2 * (x + 1))
expr
```


```python
sp.expand(expr)
```


```python
sp.diff(sp.cos(x**2)**2 / (1 + x), x)
```


```python
x = sp.symbols('x', positive=True)
x > 0
```


```python
sp.sqrt(x ** 2)
```


```python
sp.sqrt(y ** 2)
```


```python
sp.exp(sp.I * sp.pi)
```


```python
sp.oo
```


```python
a, b, c = sp.symbols("a, b, c")
```


```python
sp.expand(sp.sin(a + b))
```


```python
sp.expand(sp.sin(a + b), trig=True)
```


```python
sp.simplify(sp.sin(x)**2 + sp.cos(x)**2)
```


```python
sp.factor(x**3 + 6 * x**2 + 11*x + 6)
```


```python
sp.simplify(sp.cos(x) / sp.sin(x))
```


```python
expr1 = 1 / ((a + 1) * (a + 2))
expr1
```


```python
expr1.is_rational_function()
```




    True




```python
sp.apart(expr1)
```


```python
z = sp.symbols('z')
```


```python
f = sp.sin(x * y) + sp.cos(y * z)
f
```


```python
sp.integrate(f, x)
```


```python
sp.integrate(f, y)
```


```python
sp.integrate(sp.exp(-x**2), x)
```


```python
sp.integrate(sp.exp(-x**2), (x, -sp.oo, sp.oo))
```


```python
sp.integrate(x + sp.sinh(x), x)
```


```python
sp.diff(_, x)
```


```python
sp.limit(sp.sin(sp.pi * x) / x, x, 0)
```


```python
4 * sp.atan(1)
```


```python
n = sp.symbols('n')
```


```python
expr = (-1)**n / (2 * n + 1)
expr
```


```python
sp.summation(expr, (n, 0, sp.oo))
```


```python
sp.series(sp.atan(x), x, n=13)
```


```python
expr = 1 / (x + y)
expr
```


```python
expr.series(x)
```


```python
sp.series(sp.exp(x), x)
```


```python
sp.summation(1 / sp.factorial(n), (n, 0, sp.oo))
```


```python
expr = (1 + 1/n) ** n
expr
```


```python
sp.limit(expr, n, sp.oo)
```


```python
sp.pi.evalf(100)
```


```python
sp.solve(x**4 - x**2 - 1, x)
```


```python
sp.solve([x + y - 1, x - y - 1], [x,y])
```


```python
sp.solve([x + y - a, x - y - c], [x,y])
```


```python
sp.symbols('m:q')
```


```python
sp.symbols('r:5')
```


```python
m = sp.symbols('m')
M = sp.Matrix([[1, m], [3, 4]])
M
```


```python
M.inv()
```


```python
A = sp.Matrix(sp.symbols("m:2:2")).reshape(2, 2)
A
```


```python
A[1, 0]
```


```python
b = sp.Matrix(sp.symbols("b:2"))
b
```


```python
A**2
```


```python
A * b
```


```python
A.det()
```


```python
A.inv()
```

from https://github.com/sympy/sympy/wiki/Matrices-eigenvalues


```python
M = sp.Matrix(4, 4, lambda i, j: i * j + 1)
M
```


```python
M.eigenvals()
```


```python
M = sp.Matrix(4, 4, lambda i, j: i * j + 2)
M
```


```python
M.eigenvals()
```


```python
M = sp.Matrix(4, 4, lambda i, j: i * j + 3)
M
```


```python
M.eigenvals()
```


```python
x = sp.symbols('x')
M = sp.Matrix(4, 4, lambda i, j: i * j + x)
M
```


```python
M.eigenvals()
```

from https://groups.google.com/forum/#!topic/sympy/mISLFQcEUIM


```python
f = sp.Piecewise((0, x <= -1), (sp.Rational(1, 2), x < 1), (0, True))
f
```


```python
#sp.integrate(f.subs(x, x - y) * f(x), y)
```


```python
sp.integrate(sp.Heaviside(x + 1) / 2 - sp.Heaviside(x - 1) / 2, (x, -10, -5))
```


```python
q = sp.Piecewise((0, x < 0), (x, x < 1), (0, True))
q
```


```python
q.args
```

from https://groups.google.com/forum/#!topic/sympy/tt8IA3y2sfQ


```python
f = sp.Lambda(x, sp.exp(-x**2))
f
```


```python
conv = sp.Integral(f(x-y)*f(y), (y, -sp.oo, sp.oo))
conv
```


```python
conv.subs(x, 0)
```


```python
l = sp.lambdify(x, sp.Integral(f(x), (x, -sp.oo, sp.oo)))
#l(3) # doesn't work!
l
```




    <function numpy.<lambda>>




```python
l = sp.lambdify(x, sp.Integral(f(x), (x, -sp.oo, sp.oo)), "sympy")
l
```




    <function <lambda>>




```python
l(x)
```

from http://www.mare.ee/indrek/misc/convolution.pdf


```python
# Convolute two "one-piece" functions. Arguments F and G
# are tuples in form (h(x) , a_h, b_h), where h(x) is
# the function and [a_h, b_h) is the range where the functions
# are non-zero.
def convolute_onepiece(x, F, G):
    f, a_f, b_f = F
    g, a_g, b_g = G
    f = sp.S(f)
    g = sp.S(g)
    # make sure ranges are in order, swap values if necessary
    if b_f - a_f > b_g - a_g:
        f, a_f, b_f, g, a_g, b_g = g, a_g, b_g, f, a_f, b_f
    y = sp.Dummy('y')
    i = sp.integrate(f.subs(x, y) * g.subs(x, x-y), y)
    return [
        (i.subs(y, x-a_g) - i.subs(y, a_f), a_f+a_g, b_f+a_g),
        (i.subs(y, b_f) - i.subs(y, a_f), b_f+a_g, a_f+b_g),
        (i.subs(y, b_f) - i.subs(y, x-b_g), a_f+b_g, b_f+b_g) ]
```


```python
# Two "flat" functions, uniform centered PDFs
F = 0.5, -1, 1
G = 0.05, -10, 10
convolute_onepiece(sp.abc.x, F, G)
```

from https://github.com/fperez/sympy/blob/master/sympy/solvers/tests/test_pde.py


```python
from sympy import Derivative as D
```


```python
x, y, z, t = sp.symbols("x y z t")
c = sp.symbols("c", real=True)
Phi = sp.Function('Phi')
F, R, T, X, Y, Z, u = map(sp.Function, 'FRTXYZu')
r, theta, z = sp.symbols('r theta z')
```


```python
eq = sp.Eq(D(F(x, y, z), x) + D(F(x, y, z), y) + D(F(x, y, z), z))
eq
```


```python
sp.pde_separate_mul(eq, F(x, y, z), [Y(y), u(x, z)])
```


```python
sp.pde_separate_mul(eq, F(x, y, z), [X(x), Y(y), Z(z)])
```


```python
# wave equation
wave = sp.Eq(D(u(x, t), t, t), c**2*D(u(x, t), x, x))
wave
```


```python
sp.pde_separate_mul(wave, u(x, t), [X(x), T(t)])
```


```python
# Laplace equation in cylindrical coords
eq = sp.Eq(1/r * D(Phi(r, theta, z), r) + D(Phi(r, theta, z), r, 2) +
           1/r**2 * D(Phi(r, theta, z), theta, 2) + D(Phi(r, theta, z), z, 2))
eq
```


```python
# Separate z
sp.pde_separate_mul(eq, Phi(r, theta, z), [Z(z), u(theta, r)])
```


```python
# Lets use the result to create a new equation...
eq = sp.Eq(_[1], c)
eq
```


```python
# ...and separate theta...
sp.pde_separate_mul(eq, u(theta, r), [T(theta), R(r)])
```


```python
# ...or r...
sp.pde_separate_mul(eq, u(theta, r), [R(r), T(theta)])
```


```python

```

<p xmlns:dct="http://purl.org/dc/terms/">
  <a rel="license"
     href="http://creativecommons.org/publicdomain/zero/1.0/">
    
  </a>
  <br />
  To the extent possible under law,
  <span rel="dct:publisher" resource="[_:publisher]">the person who associated CC0</span>
  with this work has waived all copyright and related or neighboring
  rights to this work.
</p>

10a4a5628a4042910872e590d1e3fe5ea25fd93a
ipynb
Jupyter Notebook
sympy/sympy.ipynb
mgeier/python-audio
70d4d62b148c08c50ec0057f8d4fd9876ce67a13
CC0-1.0
2015-04-14T20:13:25.000Z
2022-03-26T20:00:27.000Z
sympy/sympy.ipynb
mgeier/python-audio
70d4d62b148c08c50ec0057f8d4fd9876ce67a13
CC0-1.0
2017-05-02T13:22:41.000Z
2017-05-03T13:17:15.000Z
sympy/sympy.ipynb
mgeier/python-audio
70d4d62b148c08c50ec0057f8d4fd9876ce67a13
CC0-1.0
2015-04-19T14:08:37.000Z
2021-04-21T14:24:37.000Z
Qwen/Qwen-72B
1. YES
2. YES