## Calculus
### limits

Note: for interactive work it is useful to run `init_session()`, which defines some basic symbols


```python
from sympy import *
init_session()
%matplotlib inline
```

    IPython console for SymPy 1.3 (Python 3.6.6-64-bit) (ground types: python)
    
    These commands were executed:
    >>> 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)
    >>> init_printing()
    
    Documentation can be found at http://docs.sympy.org/1.3/
    



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


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

Limits are from the right by default. It can be changed with `dir` argument:


```python
limit(1/x, x, 0, dir="-")
```


```python
limit(1/x, x, 0, dir="+-")
```

We may also create an expression with the limit without evaluating it


```python
Limit(1/x, x, 0, dir="+")
```

and evaluate later if needed


```python
_.doit()
```

#### Differentiation


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

Multiple and multivariate derivatives are possible


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


```python
diff(sin(x)/x, x, 2)
```


```python
diff(sin(x)/y, x, 2, y, 2)
```

Unevaluated derivatives are useful for expressing differential equations


```python
Derivative(sin(x)/y, x, 2, y, 2)
```

#### Series expansion


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


```python
expr = exp(sin(x**2+pi))
expr.series(x)
```


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

Lets compare the original function with its series expansion visually

### Plotting side-note $\to$


```python
p1 = plot(expr, expr.series(x, 1, 7).removeO(), (x, -4, 7),
    ylim = (-1,3),
    show = False,
    legend = True
)
p1[1].line_color="r"
p1[1].label="series(6)"
p1.show()
```

### ODE solving


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


```python
eqn = Eq(f(x).diff(x, x) - 2*f(x).diff(x) + f(x), sin(x))
eqn
```


```python
sol = dsolve(eqn, f(x))
sol
```

We can test that the solution is valid


```python
eqn.subs(f(x), sol.args[1]).doit()
```

Systems of equations are also supported


```python
alpha = symbols("alpha", positive=True)
eqn = Eq(f(x).diff(x), alpha*g(x)), Eq(g(x).diff(x), -alpha*g(x))
eqn
```


```python
dsolve(eqn, (f(x), g(x)))
```

6b596d7d34963223f1b01b881b176c69213806d2
ipynb
Jupyter Notebook
notebooks/02 Calculus.ipynb
rouckas/sympy-slides
c2777f0eddedd19c4bf094d40489f49c1ef8ad28
BSD-3-Clause
2018-10-22T19:52:48.000Z
2018-12-01T16:59:45.000Z
notebooks/02 Calculus.ipynb
rouckas/sympy-slides
c2777f0eddedd19c4bf094d40489f49c1ef8ad28
BSD-3-Clause
notebooks/02 Calculus.ipynb
rouckas/sympy-slides
c2777f0eddedd19c4bf094d40489f49c1ef8ad28
BSD-3-Clause
Qwen/Qwen-72B
1. YES
2. YES