How to | Solve an Equation

The Wolfram Language has many powerful features that enable you to solve many kinds of equations.

You can solve an equation using Solve. Remember to use "==" in an equation, not just "=":

The result is a Rule inside a doubly nested list. The outer list holds all of the solutions and each inner list holds a single solution. Here there are three solutions:

To solve a system of equations, use a list in the first argument:

Here there are two solutions to a simultaneous system of equations; each solution set is wrapped in its own list:

Here the solution expresses one variable in terms of another:

To use one of these solutions (here the first one is shown), use [[...]] (the short form of Part) to extract it from the list of solutions and use /. (the short form of ReplaceAll) to apply the rule:

For example, here is a plot of x^2 y^2 for different values of y, assuming that the first solution holds:

In a system of equations with multiple variables, you can solve for some or all of the variables by using a list in the second argument:

If the system is underspecified, the Wolfram Language will give an answer in terms of the remaining variables:

Solve finds what are known as "generic" solutions to equations. These are solutions that do not depend on the variables not specified in the second argument. For example:

No matter what y is, putting in 0 for x solves the equation. But there is another solution that does depend on y: namely, setting y to 0. Adding y in the second argument makes this solution show up:

There are other cases in which Solve does not find every solution. For example:

You can also solve radical equations:

Note that in radical equations, Solve discards parasite solutions. To see all candidate solutions, including parasites, set the VerifySolutions option to False:

This checks the solutions:

You can also solve equations by using Reduce:

The output of Reduce is different from the output of Solve: Reduce outputs a logical expression that is equivalent to the original equation, so it never omits a solution:

    

The Wolfram Language also allows you to get numeric solutions for equations.

For example, you can use N on the output of Solve to get a numeric approximation for the symbolic solution:

You can also get the numeric solution directly by using NSolve, which is faster than combining N and Solve:

Use NSolve to solve a more complicated polynomial equation:

You can also use NSolve to solve systems of equations numerically. Use the same syntax as you would with Solve:

If your equations involve only linear functions or polynomials, then you can use NSolve to get numerical approximations to all the solutions. However, when your equations involve more complicated functions, there is, in general, no systematic procedure for finding all solutions, even numerically. In such cases, you can use FindRoot to search for solutions.

Use FindRoot to search for numerical solutions for x, starting at 1:

  • Solving Equations
  • How to: Do Algebraic Calculations
  • How to: Work with Differential Equations
  • Solve  Part  ReplaceAll  Rule  Equal

  • Equation Solving
  • "How to" Topics