Solving Equations
Explore how to use SymPy's solve() function to find solutions to single and multivariable equations, including linear, non-linear, trigonometric, and interval problems. Understand how symbolic and numeric solutions differ and apply these methods to scientific computations.
SymPy has equation solvers that can handle linear and non-linear algebraic equations as well as linear and non-linear multivariate equations. Depending upon the input equation, the answer returned can be symbolic or numeric. The most commonly used one is solve(). It uses the following syntax:
solve(f(x), x)
The output type of solve() varies with input, sometimes it returns a Python list and sometimes a Python dictionary. Usually, for single variable equations, it returns a list and for multivariable equations, it returns a dictionary.
Let’s explore different cases in the examples below:
Solving for a single variable
Single solution
Let’s solve the following equation that has a single solution:
The solve() function returns a list with the only solution.
Multiple solutions
Let’s solve the following equation, which has multiple solutions:
The solve() function returns a list with all the solutions. Let’s solve an equation with complex roots:
...