---
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
```

If your equation has just one variable, simply call `solve` on it.
Note that you may get a list of more than one solution.


```python
var( 'x' )
equation = Eq( x**2 + 3*x, -x + 9 )
solve( equation )
```




$\displaystyle \left[ -2 + \sqrt{13}, \  - \sqrt{13} - 2\right]$



Sometimes you get no solutions, which is shown as a Python empty list.


```python
solve( Eq( x+1, x+2 ) )
```




$\displaystyle \left[ \right]$



Sometimes the answers include complex numbers.


```python
solve( Eq( x**3, -1 ) )
```




$\displaystyle \left[ -1, \  \frac{1}{2} - \frac{\sqrt{3} i}{2}, \  \frac{1}{2} + \frac{\sqrt{3} i}{2}\right]$



To restrict the solution to the real numbers, use `solveset` instead,
and specify the real numbers as the domain.


```python
solveset( Eq( x**3, -1 ), domain=S.Reals )
```




$\displaystyle \left\{-1\right\}$



You can solve systems of equations by calling `solve` on them.


```python
var( 'x y' )
system = [
    Eq( x + 2*y, 1 ),
    Eq( x - 9*y, 5 )
]
solve( system )
```




$\displaystyle \left\{ x : \frac{19}{11}, \  y : - \frac{4}{11}\right\}$



8d92093649ff00ff34fd291cf5e3a5ab984970da
ipynb
Jupyter Notebook
database/tasks/How to solve symbolic equations/Python, using SymPy.ipynb
nathancarter/how2data
7d4f2838661f7ce98deb1b8081470cec5671b03a
MIT
database/tasks/How to solve symbolic equations/Python, using SymPy.ipynb
nathancarter/how2data
7d4f2838661f7ce98deb1b8081470cec5671b03a
MIT
database/tasks/How to solve symbolic equations/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