# Sympy : Symbolic Mathematics in Python

http://www.scipy-lectures.org/packages/sympy.html




```python
from sympy import *
x = Symbol('x')
y = Symbol('y')
```

# Integration


```python
integrate(x**3, (x, -1, 1))
```




    0




```python
integrate( 1/x )
```




    log(x)




```python
integrate( 1/(1 +2*x) )
```




    log(2*x + 1)/2




```python
integrate( 1/(1 - 2*x) )
```




    -log(2*x - 1)/2



# Equation solving


```python
solve([x + 5*y - 2, -3*x + 6*y - 15], [x, y])
```




    {x: -3, y: 1}



# Differential Equations


```python
f, g = symbols('f g', cls=Function)
```


```python
f(x).diff(x, x) + f(x)
```




    f(x) + Derivative(f(x), x, x)




```python
dsolve(f(x).diff(x, x) + f(x), f(x))
```




    Eq(f(x), C1*sin(x) + C2*cos(x))




```python
dsolve(sin(x)*cos(f(x)) + cos(x)*sin(f(x))*f(x).diff(x), f(x), hint='separable')
```




    [Eq(f(x), -asin(sqrt(C1/(sin(x)**2 - 1) + 1)) + pi),
     Eq(f(x), asin(sqrt(C1/(sin(x)**2 - 1) + 1)) + pi),
     Eq(f(x), -asin(sqrt(C1/(sin(x)**2 - 1) + 1))),
     Eq(f(x), asin(sqrt(C1/(sin(x)**2 - 1) + 1)))]




```python
diff(x, x)
```




    1




```python
diff(1/x, x)
```




    -1/x**2




```python
diff(1/(2*y), y)
```




    -1/(2*y**2)




```python
diff(1/x, x) - diff(1/(2*y), y)
```




    1/(2*y**2) - 1/x**2




```python
from __future__ import division
from sympy import *
x, y, z, t = symbols('x y z t')
k, m, n = symbols('k m n', integer=True)
f, g, h = symbols('f g h', cls=Function)

```


```python
eq = (Eq(Derivative(x(t),t), 12*t*x(t) + 8*y(t)), Eq(Derivative(y(t),t), 21*x(t) + 7*t*y(t)))
eq
```




    (Eq(Derivative(x(t), t), 12*t*x(t) + 8*y(t)),
     Eq(Derivative(y(t), t), 7*t*y(t) + 21*x(t)))




```python
dsolve(eq)
```




    [Eq(x(t), C1*x0 + C2*x0*Integral(8*exp(Integral(7*t, t))*exp(Integral(12*t, t))/x0**2, t)),
     Eq(y(t), C1*y0 + C2(y0*Integral(8*exp(Integral(7*t, t))*exp(Integral(12*t, t))/x0**2, t) + exp(Integral(7*t, t))*exp(Integral(12*t, t))/x0))]




```python
eq1 = (Eq(Derivative(x(t),t), 12*t*x(t) + 8*y(t)))
eq1
```




    Eq(Derivative(x(t), t), 12*t*x(t) + 8*y(t))




```python
dsolve(eq1)
```




    Eq(-4*Integral(2*y(t)*exp(-6*t**2), t) - 4*Integral(3*t*x(t)*exp(-6*t**2), t), C1)




```python
eq1 = (Eq(Derivative(1/x,x)- Derivative((2*y)**(-1), y)))
eq1
```




    Eq(Derivative(1/x, x) - Derivative(1/(2*y), y), 0)




```python
dsolve(eq1)
```


```python

```

0a374f67d939eb7e5abbc4eff954b39739c39b7a
ipynb
Jupyter Notebook
code/tba/sympy.ipynb
nju-teaching/computational-communication
b95bca72bcfbe412fef15df9f3f057e398be7e34
MIT
2017-04-06T01:00:19.000Z
2020-11-16T15:30:30.000Z
code/tba/sympy.ipynb
nju-teaching/computational-communication
b95bca72bcfbe412fef15df9f3f057e398be7e34
MIT
2017-05-12T10:09:06.000Z
2019-09-17T13:13:22.000Z
code/tba/sympy.ipynb
nju-teaching/computational-communication
b95bca72bcfbe412fef15df9f3f057e398be7e34
MIT
2017-03-22T02:58:34.000Z
2020-11-16T03:08:47.000Z
Qwen/Qwen-72B
1. YES
2. YES