solve
Equations and systems solver
Syntax
Description
uses additional options specified by one or more S
= solve(eqn
,var
,Name=Value
)Name=Value
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
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
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 andReturnConditions
isfalse
, thesolve
function internally calls the numeric solvervpasolve
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 andReturnConditions
istrue
,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
istrue
,solve
returns the parameters in the solution and the conditions under which the solutions are true. IfReturnConditions
isfalse
, thesolve
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 bysolve
.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 usesyms
to initialize the parameter. For example, if the parameter isk
, usesyms k
.The variable names
parameters
andconditions
are not allowed as inputs tosolve
.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 whichsolve
solves equations or systems. Ify1,...,yN
are the variables that appear ineqns
, then there is no guarantee thatsolve(eqns)
will assign the solutions toy1,...,yN
using the correct order. Thus, when you run[b,a] = solve(eqns)
, you might get the solutions fora
assigned tob
and vice versa. To ensure the order of the returned solutions, specify the variablesvars
. For example, the call[b,a] = solve(eqns,b,a)
assigns the solutions fora
toa
and the solutions forb
tob
.
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 = ac·bc.
log(ab) = 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:
(ab)c = ab·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(ex) = 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
Wk(x·ex) = 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.