# Solve Equations#

The Python package SymPy can symbolically solve equations, differential equations, linear equations, nonlinear equations, matrix problems, inequalities, Diophantine equations, and evaluate integrals. SymPy can also solve numerically.

The Solving Guidance page provides recommendations applicable to many types of solving tasks.

Learn how to use SymPy computer algebra system to:

Description

Example

Solution

Solve an equation algebraically

$$x^2 = y$$

$$x \in \{-\sqrt{y},\sqrt{y}\}$$

Solve a system of equations algebraically

$$x^2 + y = 2z, y = -4z$$

$$\{(x = -\sqrt{6z}, y = -4z),$$ $${(x = \sqrt{6z}, y = -4z)\}}$$

Solve one or a system of equations numerically

$$\cos(x) = x$$

$$x \approx 0.739085133215161$$

Solve an ordinary differential equation algebraically

$$y''(x) + 9y(x)=0$$

$$y(x)=C_{1} \sin(3x)+ C_{2} \cos(3x)$$

Find the roots of a polynomial algebraically or numerically

$$ax^2 + bx + c = 0$$

$$x = \frac{-b\pm\sqrt{b^2 - 4ac}}{2a}$$

Solve a matrix equation algebraically

$$\left[\begin{array}{cc} c & d\\1 & -e\end{array}\right] \left[\begin{array}{cc} x\\y\end{array}\right] = \left[\begin{array}{cc} 2\\0\end{array}\right]$$

$$\left[\begin{array}{cc} x\\y\end{array}\right] = \left[\begin{array}{cc} \frac{2e}{ce+d}\\\frac{2}{ce+d}\end{array}\right]$$

Reduce one or a system of inequalities for a single variable algebraically

$$x^2 < \pi, x > 0$$

$$0 < x < \sqrt{\pi}$$

Solve a Diophantine equation algebraically

$$a^2 + b^2 = c^2$$

$$(a=2pq, b=p^2-q^2, c=p^2+q^2)$$

Notes:

• SymPy has a function called solve() which is designed to find the solutions of an equation or system of equations, or the roots of a function. SymPy solve() may or may not be what you need for a particular problem, so we recommend you use the links on this page to learn how to “solve” your problem.

• While a common, colloquial expression is, for example, “solve an integral,” in SymPy’s terminology it would be “evaluate an integral.” This page does not provide guidance for such tasks. Please search the documentation for the type of expression you want to evaluate.