# solve

Equations and systems solver

## Syntax

## Description

uses additional options specified by one or more `S`

= solve(`eqn`

,`var`

,`Name,Value`

)`Name,Value`

pair
arguments.

solves the system of equations `Y`

= solve(`eqns`

,`vars`

)`eqns`

for the variables
`vars`

and returns a structure that contains the solutions. If you do
not specify `vars`

, `solve`

uses `symvar`

to find the variables to solve for. In this case, the number of
variables that `symvar`

finds is equal to the number of equations
`eqns`

.

uses additional options specified by one or more `Y`

= solve(`eqns`

,`vars`

,`Name,Value`

)`Name,Value`

pair
arguments.

`[`

solves the system of equations `y1,...,yN`

] = solve(`eqns`

,`vars`

)`eqns`

for the variables
`vars`

. The solutions are assigned to the variables
`y1,...,yN`

. If you do not specify the variables,
`solve`

uses `symvar`

to find the variables to
solve for. In this case, the number of variables that `symvar`

finds is
equal to the number of output arguments `N`

.

`[`

uses additional options specified by one or more `y1,...,yN`

] = solve(`eqns`

,`vars`

,`Name,Value`

)`Name,Value`

pair
arguments.

`[`

returns the additional arguments `y1,...,yN`

,`parameters`

,`conditions`

]
= solve(`eqns`

,`vars`

,'`ReturnConditions`

',true)`parameters`

and
`conditions`

that specify the parameters in the solution and the
conditions on the solution.

## Examples

## Input Arguments

## Output Arguments

## Tips

If

`solve`

cannot find a solution and`ReturnConditions`

is`false`

, the`solve`

function internally calls the numeric solver`vpasolve`

that tries to find a numeric solution. For polynomial equations and systems without symbolic parameters, the numeric solver returns all solutions. For nonpolynomial equations and systems without symbolic parameters, the numeric solver returns only one solution (if a solution exists).If

`solve`

cannot find a solution and`ReturnConditions`

is`true`

,`solve`

returns an empty solution with a warning. If no solutions exist,`solve`

returns an empty solution without a warning.If the solution contains parameters and

`ReturnConditions`

is`true`

,`solve`

returns the parameters in the solution and the conditions under which the solutions are true. If`ReturnConditions`

is`false`

, the`solve`

function either chooses values of the parameters and returns the corresponding results, or returns parameterized solutions without choosing particular values. In the latter case,`solve`

also issues a warning indicating the values of parameters in the returned solutions.If a parameter does not appear in any condition, it means the parameter can take any complex value.

The output of

`solve`

can contain parameters from the input equations in addition to parameters introduced by`solve`

.Parameters introduced by

`solve`

do not appear in the MATLAB workspace. They must be accessed using the output argument that contains them. Alternatively, to use the parameters in the MATLAB workspace use`syms`

to initialize the parameter. For example, if the parameter is`k`

, use`syms k`

.The variable names

`parameters`

and`conditions`

are not allowed as inputs to`solve`

.To solve differential equations, use the

`dsolve`

function.When solving a system of equations, always assign the result to output arguments. Output arguments let you access the values of the solutions of a system.

`MaxDegree`

only accepts positive integers smaller than 5 because, in general, there are no explicit expressions for the roots of polynomials of degrees higher than 4.The output variables

`y1,...,yN`

do not specify the variables for which`solve`

solves equations or systems. If`y1,...,yN`

are the variables that appear in`eqns`

, then there is no guarantee that`solve(eqns)`

will assign the solutions to`y1,...,yN`

using the correct order. Thus, when you run`[b,a] = solve(eqns)`

, you might get the solutions for`a`

assigned to`b`

and vice versa.To ensure the order of the returned solutions, specify the variables

`vars`

. For example, the call`[b,a] = solve(eqns,b,a)`

assigns the solutions for`a`

to`a`

and the solutions for`b`

to`b`

.

## Algorithms

When you use `IgnoreAnalyticConstraints`

, the solver applies some of
these rules to the expressions on both sides of an equation.

log(

*a*) + log(*b*) = log(*a*·*b*) for all values of*a*and*b*. In particular, the following equality is valid for all values of*a*,*b*, and*c*:(

*a*·*b*)^{c}=*a*^{c}·*b*^{c}.log(

*a*^{b}) =*b*·log(*a*) for all values of*a*and*b*. In particular, the following equality is valid for all values of*a*,*b*, and*c*:(

*a*^{b})^{c}=*a*^{b·c}.If

*f*and*g*are standard mathematical functions and*f*(*g*(*x*)) =*x*for all small positive numbers,*f*(*g*(*x*)) =*x*is assumed to be valid for all complex values*x*. In particular:log(

*e*^{x}) =*x*asin(sin(

*x*)) =*x*, acos(cos(*x*)) =*x*, atan(tan(*x*)) =*x*asinh(sinh(

*x*)) =*x*, acosh(cosh(*x*)) =*x*, atanh(tanh(*x*)) =*x*W

_{k}(*x*·*e*^{x}) =*x*for all branch indices*k*of the Lambert W function.

The solver can multiply both sides of an equation by any expression except

`0`

.The solutions of polynomial equations must be complete.

## Version History

**Introduced before R2006a**