# SymPy Tutorial

*Arthur Ryman* <br/>
*Last Updated: 2020-04-14*


This notebook contains the examples from the 
[SymPy Tutorial](https://docs.sympy.org/latest/tutorial/index.html).

## Calculus


```python
from sympy import *
x, y, z = symbols('x y z')
init_printing(use_unicode=True)
```

### Derivatives


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


```python
diff(exp(x**2), x)
```


```python
diff(x**4, x, x, x)
```


```python
diff(x**4, x, 3)
```


```python
expr = exp(x*y*z)
diff(expr, x, y, y, z, z, z, z)
```


```python
diff(expr, x, y, 2, z, 4)
```


```python
diff(expr, x, y, y, z, 4)
```


```python
expr.diff(x, y, y, z, 4)
```


```python
deriv = Derivative(expr, x, y, y, z, 4)
deriv
```


```python
deriv.doit()
```


```python
m, n, a, b = symbols('m n a b')
expr = (a*x + b)**m
expr.diff((x,n))
```

### Integrals


```python
integrate(cos(x), x)
```


```python
integrate(exp(-x), (x, 0, oo))
```


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


```python
expr = integrate(x**x, x)
print(expr)
expr
```


```python
expr = Integral(log(x)**2, x)
expr
```


```python
expr.doit()
```


```python
integ = Integral((x**4 + x**2*exp(x) - x**2 - 2*x*exp(x) - 2*x -
                 exp(x))*exp(x)/((x - 1)**2*(x + 1)**2*(exp(x) + 1)), x)
integ
```


```python
integ.doit()
```


```python
integ = Integral(sin(x**2), x)
integ
```


```python
integ.doit()
```


```python
integ = Integral(x**y*exp(-x), (x, 0, oo))
integ
```


```python
integ.doit()
```

### Limits


```python
limit(sin(x)/x, x, 0)
```


```python
expr = x**2/exp(x)
expr.subs(x, oo)
```


```python
limit(expr, x, oo)
```


```python
expr = Limit((cos(x) - 1)/x, x, 0)
expr
```


```python
expr.doit()
```


```python
limit(1/x, x, 0, '+')
```


```python
limit(1/x, x, 0, '-')
```

### Series Expansion


```python
expr = exp(sin(x))
expr.series(x, 0, 4)
```


```python
x + x**3 + x**6 + O(x**4)
```


```python
x*O(1)
```


```python
expr.series(x, 0, 4).removeO()
```


```python
exp(x - 6).series(x, x0=6)
```

### Finite Differences


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


```python
differentiate_finite(f(x)*g(x), evaluate=True)
```


```python
f = Function('f')
dfdx = f(x).diff(x)
dfdx.as_finite_difference()
```


```python
f = Function('f')
d2fdx2 = f(x).diff(x, 2)
h = Symbol('h')
d2fdx2.as_finite_difference([-3*h,-h,2*h])
```


```python
finite_diff_weights(2, [-3, -1, 2], 0)[-1][-1]
```


```python
x_list = [-3, 1, 2]
y_list = symbols('a b c')
apply_finite_diff(1, x_list, y_list, 0)
```

80e9477761bfedf48ed0f0e66b02f8fb43951eda
ipynb
Jupyter Notebook
notes/docs.sympy.org/tutorial/calculus.ipynb
agryman/acmpy
9566a0abce51cb610ec6c79eaea2e2b26b707419
MIT
notes/docs.sympy.org/tutorial/calculus.ipynb
agryman/acmpy
9566a0abce51cb610ec6c79eaea2e2b26b707419
MIT
2022-01-21T22:17:28.000Z
2022-01-21T22:17:28.000Z
notes/docs.sympy.org/tutorial/calculus.ipynb
agryman/acmpy
9566a0abce51cb610ec6c79eaea2e2b26b707419
MIT
Qwen/Qwen-72B
1. YES
2. YES