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
Name-Value Arguments
Output Arguments
Tips
If
solvecannot find a solution andReturnConditionsisfalse, thesolvefunction internally calls the numeric solvervpasolvethat 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
solvecannot find a solution andReturnConditionsistrue,solvereturns an empty solution with a warning. If no solutions exist,solvereturns an empty solution without a warning.If the solution contains parameters and
ReturnConditionsistrue,solvereturns the parameters in the solution and the conditions under which the solutions are true. IfReturnConditionsisfalse, thesolvefunction either chooses values of the parameters and returns the corresponding results, or returns parameterized solutions without choosing particular values. In the latter case,solvealso 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
solvecan contain parameters from the input equations in addition to parameters introduced bysolve.Parameters introduced by
solvedo 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 usesymsto initialize the parameter. For example, if the parameter isk, usesyms k.The variable names
parametersandconditionsare not allowed as inputs tosolve.To solve differential equations, use the
dsolvefunction.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.
MaxDegreeonly 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,...,yNdo not specify the variables for whichsolvesolves equations or systems. Ify1,...,yNare the variables that appear ineqns, then there is no guarantee thatsolve(eqns)will assign the solutions toy1,...,yNusing the correct order. Thus, when you run[b,a] = solve(eqns), you might get the solutions foraassigned toband 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 foratoaand the solutions forbtob.
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.
