---
author: Nathan Carter (ncarter@bentley.edu)
---

This answer assumes you have imported SymPy as follows.


```python
from sympy import *                   # load all math functions
init_printing( use_latex='mathjax' )  # use pretty math output
```

Here we define a simple mathematical formula, $\frac{x^2-x-2}{x-2}$,
and compute the limit as $x$ approaches 2.  We use SymPy's built-in
`limit` function, which takes the formula $f(x)$, the variable $x$,
and the value $a$.


```python
var( 'x' )
formula = ( x**2 - x - 2 ) / ( x - 2 )
limit( formula, x, 2 )
```




$\displaystyle 3$



You can also compute one-sided limits.  For instance,
the limit of $\frac{\vert x\vert}{x}$ is $1$ as $x$ approaches 0 from the right,
but it is $-1$ as $x$ approaches 0 from the left.


```python
limit( abs(x)/x, x, 0, "-" )  # "-" means from the left
```




$\displaystyle -1$




```python
limit( abs(x)/x, x, 0, "+" )  # "+" means from the right
```




$\displaystyle 1$



7c499a94e5596a14a3bad95127ac63b621ac038c
ipynb
Jupyter Notebook
database/tasks/How to compute the limit of a function/Python, using SymPy.ipynb
nathancarter/how2data
7d4f2838661f7ce98deb1b8081470cec5671b03a
MIT
database/tasks/How to compute the limit of a function/Python, using SymPy.ipynb
nathancarter/how2data
7d4f2838661f7ce98deb1b8081470cec5671b03a
MIT
database/tasks/How to compute the limit of a function/Python, using SymPy.ipynb
nathancarter/how2data
7d4f2838661f7ce98deb1b8081470cec5671b03a
MIT
2021-07-18T19:01:29.000Z
2022-03-29T06:47:11.000Z
Qwen/Qwen-72B
1. YES
2. YES