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:

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`
` `

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

## Options

 `MaxDegree` Option, specified as `MaxDegree = n` Do not use explicit formulas that involve radicals when solving polynomial equations of degree larger than `n`. Here `n` is a positive integer. By default, `n = 2`. 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 `n` refers to the factors of the polynomials, not to the input polynomial. When you solve a fifth- or higher-order 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 `MaxDegree` option to 4 or a higher value makes no difference. `BackSubstitution` Option, specified as `BackSubstitution = b` Enable or disable backward substitutions when solving algebraic systems. The value `b` must be `TRUE` or `FALSE`. By default, `b = TRUE`. `BackSubstitution` only affects the results returned as sets of lists. `Multiple` With this option, `solve` returns a set of type `Dom::Multiset`, indicating the multiplicity of polynomial roots. The solver ignores this option if the input is not a polynomial expression or equation, or if the solution is of the `RootOf` type. `VectorFormat` Return a set of vectors when solving a system of equations for a list of variables. `PrincipalValue` 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 `solve`. For example, if the set of solutions is a piecewise function, and there are no elements that belongs to all cases, the solver cannot find a solution. 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. `Domain` Option, specified as `Domain = d` Return the set of all solutions that are elements of `d`. Here `d` must represent a subset of the complex numbers (for example, real numbers `Dom::Real` or integers `Dom::Integer`). Alternatively, `d` can be a domain over which you can factor polynomials (for example, `d` can be a finite field). In this case, you can use this option only when solving polynomial equations. Without this option, the solver returns all solutions in the set of complex numbers. You can solve an equation or a system over the following domains: Subsets of the set of complex numbers `C_`.Domains over which you can factor polynomials. You can use these domains only when solving polynomial equations. A subset of `C_` is any kind of set returned by `solve`. Instead of `C_`, `R_`, `Q_`, and `Z_`, you also can use the corresponding domains of the domains package `Dom::Complex`, `Dom::Real`, `Dom::Rational`, and `Dom::Integer`. You can overload the solver for your custom domains by adding the `domsolve` method to those domains. If this method does not exist, MuPAD uses the `solve_eq` method to solve equations. The `solve_eq` method does not accept systems as arguments. Finally, if the `solve_eq` method does not exist, MuPAD uses the `solve_poly` method to solve polynomials. The `solve_poly` method accepts only polynomials as first arguments. This method regards any first argument of `solve` that cannot be converted to a polynomial as illegal. The calling syntax for the `domsolve`, `solve_eq`, and `solve_poly` methods is ```domsolve(eq, var, options)```. Here `var` is the same argument as in `solve`, and `options` is a table of options. For the `domsolve` method, `eq` is also the same as in `solve`. For the `solve_eq` method, `eq` must be an arithmetical expression. For `solve_poly`, `eq` must be a polynomial. You cannot solve equations and systems in more than one variable over domains. `IgnoreProperties` Include solutions that are not consistent with the properties of the variable `x`. `Real` Return only the solutions for which every subexpression of `eq` represents a real number. Also, assume that every subexpression independent of `x` represents a real number. With this option, the solver assumes that every subexpression independent of `x` represents a real number. In particular, the solver assumes that all symbolic parameters are real. When you use `Real`, the solver returns only the solutions for which every subexpression of `eq` is real. See Example 7. 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 `x`, the input is defined over the real numbers. This option is particularly useful for solving inequalities. Inequalities hold only when both sides represent real values. This option does not affect some systems. `IgnoreSpecialCases` 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 `FALSE`. For example, if the property mechanism cannot prove that a denominator is equal to zero, MuPAD regards this denominator as nonzero. This option can significantly reduce the number of piecewise objects in a solution. `IgnoreAnalyticConstraints` 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: ln(a) + ln(b) = ln(a b) for all values of a and b. In particular: for all values of a, b, and c.ln(ab) = b ln(a) for all values of a and b. In particular: for all values of a, b, and 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 x. In particular: .arcsin(sin(x)) = x, arccos(cos(x)) = x, arctan(tan(x)) = x.arcsinh(sinh(x)) = x, arccosh(cosh(x)) = x, arctanh(tanh(x)) = x. for all values of k.The solver can multiply both sides of an equation by any expression except `0`.The solutions of polynomial equations must be complete. 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. `DontRewriteBySystem` 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 `DontRewriteBySystem`, the solver cannot solve some of the equations that it can solve without this option. `NoWarning` Suppress all warning messages.

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

`eq`