Documentation

# 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.

## Syntax

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)

## Description

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.

• Set-theoretic 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 Sn (the n-fold 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 set-theoretic operations, such as intersect, union, and minus. Also, you can use pointwise-defined 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 floating-point 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.

## Environment Interactions

solve reacts to properties of identifiers.

## Examples

### Example 1

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]

### Example 2

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:

### Example 3

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)

### Example 4

Solve the following inequality. The solution includes the set of all complex numbers, excluding and :

solve(x^2 <> 7, x)

### Example 5

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)

### Example 6

If an equation contains symbolic parameters, the solver returns a piecewise solution. For example, solve the quadratic equation ax2 + 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):

### Example 7

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 closed-form representation of all possible solutions:

solve(x + 1/x > 0, x)

With the Real option, the solver computes only real solutions. The closed-form 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)

### Example 8

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)

### Example 9

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.

### Example 10

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:

### Example 11

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])

### Example 12

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)

### Example 13

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)

### Example 14

To obtain the multiplicities of the roots of a polynomial, use the Multiple option. For example, the polynomial x3 + 2 x2 + 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)

### Example 15

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)

### Example 16

If the input contains floating-point 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.

### Example 17

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)

### Example 18

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_)

### Example 19

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)

### Example 20

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 floating-point value using float:

float(%)

## Parameters

 eq A single equation or an inequality of type "_equal", "_less", "_leequal", or "_unequal", or an equation in the form of membership (_in). Alternatively, any Boolean expression composed of equations or inequalities by the operators "_and", "_or", and "_not". Also, the solver accepts an arithmetical expression and regards such expression as an equation without the right side. (Internally, the solver assumes that the right side is equal to 0.) x The indeterminate for which you solve an equation, an inequality of a system: an identifier or an indexed identifier a, b Arithmetical expressions vars A nonempty set or list of indeterminates for which you solve an equation, an inequality, or a system eqs 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.) ODE An ordinary differential equation: an object of the ode type. REC A recurrence equation: an object of the rec type.

## Return Values

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.