### Sympy, General


```python
import sympy as sp

sp.sqrt(8)
```




$\displaystyle 2 \sqrt{2}$




```python
r1 = sp.Rational(4, 5)
r2 = sp.Rational(5, 4)
print(r1 + r2)
print(r1 / r2)
```

    41/20
    16/25



```python
x, y = sp.symbols("x y")
e1 = y + 2 * x
e2 = 2 * x + y
print(e1)
print(e2)
print(e1 - x)
print(e2 + 1)
print(x * e1)
print(sp.expand(x * e1))
print(sp.factor(x * e1))
```

    2*x + y
    2*x + y
    x + y
    2*x + y + 1
    x*(2*x + y)
    2*x**2 + x*y
    x*(2*x + y)


### Derivatives


```python
import sympy as sp
import numpy as np
from scipy.misc import derivative

x = sp.Symbol('x')
print(sp.diff(3*x**2+1, x))

def f(x):
    return 3*x**2 + 1

def d(x):
    return derivative(f, x)

print(derivative(f, 2.0))

%matplotlib inline
import matplotlib.pyplot as plt

y = np.linspace(-3, 3)
print(y)
plt.plot(y, f(y))
plt.plot(y, d(y))
```

### Integrals


```python
print(sp.integrate(3.0*x**2 + 1, x))

from scipy.integrate import quad
def f(x):
    return 3.0 * x**2 + 1

i = quad(f, 0, 2)
print(i[0])
```

    1.0*x**3 + 1.0*x
    10.000000000000002



```python

```

3a7c3c01d14581c3a85590019a93d4c284e452f5
ipynb
Jupyter Notebook
notebooks/sympy-samples.ipynb
dror27/dror-ddj-notebooks
4cdce9e17fbad2dff64bbba8e37f137fb343e9af
CC-BY-4.0
2020-07-02T13:27:22.000Z
2021-03-20T11:51:23.000Z
notebooks/sympy-samples.ipynb
biafarrugia/dror-ddj-notebooks
989a572c4b85538e3e2ca5baf7777b7266152c37
CC-BY-4.0
2021-03-11T06:23:54.000Z
2021-03-11T06:23:54.000Z
notebooks/sympy-samples.ipynb
biafarrugia/dror-ddj-notebooks
989a572c4b85538e3e2ca5baf7777b7266152c37
CC-BY-4.0
2021-03-18T21:54:15.000Z
2021-03-19T19:49:54.000Z
Qwen/Qwen-72B
1. YES
2. YES