solve
Solve equations and inequalities
MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
For the solve
function in MATLAB^{®},
see solve
.
solve(eq
,x
,options
) solve(eq
,x = a .. b
,options
) solve(eq
,vars
,options
) solve(eq
,options
) solve(eqs
,x
,options
) solve(eqs
,vars
,options
) solve(eqs
,options
) solve(ODE
) solve(REC
)
solve(eq, x)
returns the set of all complex
solutions of an equation or inequality eq
with
respect to x
.
solve(eq, x = a..b)
returns the set of all
solutions in the closed interval Dom::Interval([a, b])
.
solve(eq, vars)
solves an equation for the
variables vars
.
solve(eqs, x)
solves a system eqs
for
the variable x
.
solve(eqs, vars)
solves a system eqs
of
equations for the variables vars
.
The solve
function provides a unified interface
to a variety of specialized solvers. See Choosing a Solver.
If you do not specify indeterminates for which you want to solve an equation, inequality or system, the solver uses a set of all indeterminates. Indeterminates must be identifiers or indexed identifiers. You cannot use mathematical constants, such as PI, EULER, and so on, as indeterminates. The solver discards indeterminates that appear only inside function names or indices. See Example 12.
If you specify a list of indeterminates for which you want to solve an equation, an inequality, or a system, the solver sorts the components of the resulting solution vectors according to the order of the indeterminates that you used. If you specify indeterminates as a set, MuPAD^{®} can change the order of the indeterminates.
solve(eq, vars)
is equivalent to solve([eq],
vars)
.
The solver can return the following types of sets:
Finite sets (type DOM_SET
).
Symbolic calls to solve
.
Zero sets of polynomials (type RootOf
). The solver
returns a set of this type if it cannot solve an equation explicitly
in terms of radicals. The solver also can return this type of set
when you use the MaxDegree
option.
Settheoretic expressions, such as "_union"
, "_intersect"
,
and "_minus"
.
Symbolic calls to solvelib::Union
. These calls represent
unions over parametrized systems of sets.
The ℂ, ℝ, ℚ,
and ℤ (type solvelib::BasicSet
) sets.
Intervals (type Dom::Interval
).
Image sets of functions (type Dom::ImageSet
).
Piecewise objects in which every branch defines a
set of one of the valid types (type piecewise
).
MuPAD can use sets of these types, excluding intervals
and basic sets, to represent sets of vectors (for solutions of systems).
When solving a system, MuPAD also can return a solution in the
form S^{n} (the nfold
cartesian power of the set S of
scalars). Here S is
a set of any type returned by solve
.
For returned solution sets, you can use the settheoretic operations,
such as intersect
, union
, and minus
. Also, you can
use pointwisedefined arithmetical operations, such as +
, *
, and
so on. To extract elements of a set, use the solvelib::getElement
function. To test
whether the solution set returned by solve
is finite,
use the function solvelib::isFinite
.
See Example 2
For systems, the solver returns a set of vectors or a set of
lists of equations. To specify that the solver must return a set of
vectors, use the VectorFormat
option. See Example 10.
By default, solve(eq, x)
returns only the
solutions consistent with the properties of x
.
To ignore the properties of x
, use the IgnoreProperties
option.
This option is helpful when you solve a system of equations for more
than one variable. See Example 13.
An inequality a <= b
or a <
b
holds only when both sides represent real numbers. In
particular, a = b
does not imply that a
<= b
for complex numbers.
You can write custom domains for equations of special types,
and then overload solve
for these domains. MuPAD uses
this feature for differential and recurrence equations. See the ode
, ode::solve
, and rec
help pages.
The solve
function is a symbolic solver.
If you want to use numeric methods, see the numeric::solve
help page for available
options and examples.
If the input contains floatingpoint numbers, the solver replaces
them by approximate rational values. The accuracy of these approximate
values depends on the environment variable DIGITS
. If solve
finds
a solution, MuPAD internally calls the float
function for that solution, and
then returns the result. If the symbolic solver returns unevaluated
, MuPAD calls numeric::solve
. See Example 16.
If a numerator contains a factored polynomial with the multiplicities greater than 1, the solver does not check the multiple roots for zeros in the denominator. See Example 17.
solve
reacts to properties of
identifiers.
Solve the following equation. Typically, for equations with
a finite number of solutions, the solver returns a set of the DOM_SET
type:
S := solve(x^4  5*x^2 + 6*x = 2, x)
Assign individual solutions to variables by indexing into S
:
sol1 := S[1]
The solver can also return an infinite discrete set of solutions:
S := solve(sin(x*PI/7) = 0, x)
To select the solutions in a particular finite interval, find the intersection of the solution set with the interval:
S intersect Dom::Interval(22, 22)
Alternatively, specify the interval when calling the solver. For example, compute the solutions in the interval [ 22, 22]:
solve(sin(x*PI/7) = 0, x = 22..22)
delete S:
Use the solve
function to solve inequalities.
Typically, the solution set of an inequality is an interval or a union of intervals:
solve(x^2 > 5, x)
Solve the following inequality. The solution includes the set of all complex numbers, excluding and :
solve(x^2 <> 7, x)
The solver can return a solution as a union of an infinite family
of sets. The solvelib::Union
function
represents such infinite unions in MuPAD:
solve(sin(x)*cos(x) > 1/4, x, Real)
If an equation contains symbolic parameters, the solver returns a piecewise solution. For example, solve the quadratic equation ax^{2} + bx + c = 0:
S := solve(a*x^2 + b*x + c, x)
Now, evaluate the solution assuming that a
is
not equal to 0:
assume(a <> 0): S
delete S: unassume(a):
By default, the solver tries to find all possible solutions. The following inequality has both real and complex solutions. For example, is one of the solutions. The solver cannot find a closedform representation of all possible solutions:
solve(x + 1/x > 0, x)
With the Real
option, the solver computes
only real solutions. The closedform representation of all real solutions
of that equation is an interval of all real numbers from 0 to infinity:
solve(x + 1/x > 0, x, Real)
Solve this equation. By default, the solver returns a complete, but rather long and complicated solution:
solve(x^(7/2) + 1/x^(7/2) = 1, x)
Using IgnoreAnalyticConstraints
, you often
can get simpler results:
solve(x^(7/2) + 1/x^(7/2) = 1, x, IgnoreAnalyticConstraints)
Using this option, you also can get wrong results:
solve(arcsin(x) = C, x, IgnoreAnalyticConstraints) assuming C > 10
Always check the results obtained with this option:
testeq(arcsin(sin(C)), C)
The IgnoreAnalyticConstraints
option also
can lead to incomplete results:
solve(x^(5/2) = 1, x)
solve(x^(5/2) = 1, x, IgnoreAnalyticConstraints)
With the IgnoreAnalyticConstraints
option,
the solver can multiply both sides of an equation by any expression,
except 0
. In the following example, the solver
multiplies both sides of the equation by .
The solver does not consider the special case x = y = 0
:
solve(1/sqrt(x) = 1/sqrt(y), IgnoreAnalyticConstraints)
The result is not valid for x = y = 0
.
When you solve a system of equations, MuPAD tries to represent the solutions as a set of lists of substitutions:
solve([x^2 + y = 1, x + y^2 = 1], [x, y])
If you use the VectorFormat
option, MuPAD returns
a solution as a set of vectors:
solve([x^2 + y = 1, x + y^2 = 1], [x, y], VectorFormat)
Right sides of the returned substitutions can contain generated identifiers. In this case, substituting each of these identifiers with a complex number gives a solution of the system. You can obtain all solutions by substituting generated identifiers with all complex numbers:
sys:= [x + y + z = 2, x + y^2 + z^2 = 4]: solve(sys, [x, y, z])
If you use the VectorFormat
option, the solver
returns a solution as an infinite set of vectors, in the usual mathematical
notation:
solve(sys, [x, y, z], VectorFormat); delete sys:
You can specify the variable, for which you want to solve an equation, as a list of one entry. In this case, the solver returns the solution using the output format typically used for systems:
solve(x = x, x), solve(x = x, [x])
If you do not specify indeterminates (the variables for which you want to solve an equation), the solver uses the set of all indeterminates that it can find in that equation:
solve(x^2 = 3)
The solver does not regard operators and indices as indeterminates.
Therefore, the solver does not treat f
and y
as
indeterminates in the following equation:
solve(f(x[y]) = 7)
If you set an assumption on the variable for which you want
to solve an equation, the solver returns only the results compatible
with that assumption. For example, assume that x
represents
a real positive number. Then, solve the following equation:
assume(x, Type::Positive): solve(x^4 = 1, x)
Without that assumption, the solver returns all complex solutions:
unassume(x): solve(x^4 = 1, x)
To obtain the multiplicities of the roots of a polynomial, use
the Multiple
option. For example, the polynomial x^{3} +
2 x^{2} + x has
two roots. The multiplicity of x =
 1 is 2. The multiplicity of x =
0 is 1:
solve(x^3 + 2*x^2 + x, x, Multiple)
Suppose, you want to solve the following system of equations
for two variables, x
and y
.
Suppose, you want to avoid backward substitutions while solving this
system. To disable backward substitutions, use the option BackSubstitution
= FALSE
. Specify the list of variables so that x
appears
to the right of y
. Now, the solution for the variable y
can
contain the variable x
:
solve({x^2 + y = 1, x  y = 2}, [y, x], BackSubstitution = FALSE)
solve({x^2 + y = 1, x  y = 2}, {x, y})
If MuPAD cannot express the result as a set of lists, then BackSubstitution
has
no effect:
solve({x^2 + y = 1, x  y = 2}, [y, x], BackSubstitution = FALSE, MaxDegree = 1)
If the input contains floatingpoint numbers, MuPAD uses
the symbolic solver solve
, and then calls the float
function for the
obtained solution:
solve(x^3 + 3.0*x + 1, x)
If the symbolic solver fails to solve such equation or system, MuPAD calls
the numeric solver numeric::solve
:
solve({sin(x) + 1/2*cos(sqrt(2)*y) = 1, cos(x) + sin(y) = 0.1}, {x, y})
The numeric solver can return an incomplete set of solutions.
For details, see the numeric::solve
help
page.
If a numerator contains a factored polynomial with the multiplicities greater than 1, the solutions might give zeros in a denominator:
solve((x  1)^2/(x  1) = 0, x)
To eliminate these solutions, expand a numerator:
f := expand((x  1)^2): solve(f/(x  1) = 0, x)
You can use the solve
function to solve Diophantine
equations. For example, solve the following linear Diophantine equation:
S := solve(30*x + 56*y = 2, [x, y], Domain = Z_)
You can use the solve
function to solve equation
given in the form of memberships. For example, solve the following
equation:
solve(x^2 in Z_, x)
You can solve an equation with symbolic parameters, thus finding its general solution. Then you can evaluate the solution for any particular values of parameters or plot the solution with respect to the parameter values.
Solve this equation:
S := solve(x^5 + a = 1, x, Real)
Plot the result for the values 10 < a < 10
:
plot(S, a = 10..10)
Evaluate the result for a = 5
using the operator 
or
its functional form evalAt
:
S  a = 5
Approximate the result with a floatingpoint value using float
:
float(%)

A single equation or an inequality of type 

The indeterminate for which you solve an equation, an inequality of a system: an identifier or an indexed identifier 
 

A nonempty set or list of indeterminates for which you solve an equation, an inequality, or a system 

A set, list, array, or table of equations, inequalities, arithmetical expressions, or any combination of these objects. The solver regards expressions as equations without the right side. (Internally, the solver assumes that the right side is equal to 0.) 

An ordinary differential equation: an object of the 

A recurrence equation: an object of the 

Option, specified as Do not use explicit formulas that involve radicals when solving
polynomial equations of degree larger than This option enables and disables the use of explicit formulas
for the roots of polynomials. This option does not affect other methods,
such as factorization. For polynomial equations, the given maximal
degree When you solve a fifth or higherorder polynomial equation,
the solver might be unable to return the solution explicitly. In general,
there are no explicit expressions for the roots of polynomials of
degrees higher than 4. Setting the 

Option, specified as Enable or disable backward substitutions when solving algebraic
systems. The value


With this option, The solver ignores this option if the input is not a polynomial
expression or equation, or if the solution is of the 

Return a set of vectors when solving a system of equations for a list of variables. 

With this option, the solver returns only one solution. The solver returns this solution as a set with one element. If an equation does not have a solution, the solver returns an empty set. If the solver cannot find any solution and cannot prove that
solutions do not exist, it returns an unresolved symbolic call to You also can use this option to solve equations for more than one variable. In this case, the solver returns a set that contains one list. This nested structure represents a solution vector. 

Option, specified as Return the set of all solutions that are elements of You can solve an equation or a system over the following domains:
A subset of You can overload the solver for your custom domains by adding
the The calling syntax for the You cannot solve equations and systems in more than one variable over domains. 

Include solutions that are not consistent with the properties
of the variable 

Return only the solutions for which every subexpression of With this option, the solver assumes that every subexpression
independent of When you use this option, MuPAD restricts the domain of
every function to real numbers. For example, it does not support the
logarithms of negative numbers. For all returned solutions This option is particularly useful for solving inequalities. Inequalities hold only when both sides represent real values. This option does not affect some systems. 

If a solution requires case analysis, ignore cases for which one or more parameters in the equation are supposed to be an element of a comparatively small set (for example, with this option, MuPAD can ignore a membership in a fixed finite set or a set of integers ). With this option, the solver tries to reduce the number of branches
in piecewise objects. MuPAD finds
equations and memberships in comparatively small sets. First, MuPAD tries
to prove such equations and memberships by using the property mechanism.
If the property mechanism proves an equation or a membership is true, MuPAD keeps
that statement. Otherwise, MuPAD can replace that statement with
the value 

Apply purely algebraic simplifications to expressions and equations. With this option, the solver applies the following rules to the expressions on both sides of an equation:
Using this option, you can get simpler solutions for equations for which the direct call of the solver returns complicated results. Note that with this option the solver does not verify the correctness and completeness of the result. See Example 8 and Example 9. 

Do not transform an equation to an equivalent system of equations. This option decreases the running time. With this option, the solver cannot solve some equations. This option does not allow the solver to replace an equation
with the equivalent system of equations. Typically, MuPAD replaces
an equation by an equivalent system of equations when solving equations
with nested roots. Solving the resulting system can be slow. Use this
option to improve performance of the solver. When you use 

Suppress all warning messages. 
If x
is an identifier, solve(eq,
x)
returns an object that represents a mathematical set
(see the “Details” section). If x
is
a set or a list, or if you omit x
, a call to solve
returns
a set of lists. Each list consists of equations. The left side of
each equation is one of the variables for which you solve an equation,
an inequality of a system. In this case, solve
also
can return an expression of the form x in S
, where x
is
a list of variables, and S
is a set of vectors.
When you solve a system providing the list of variables and the VectorFormat
option,
the solver returns a set of vectors.
eq