Documentation

# `numeric`::`solve`

Numerical solution of equations (the float attribute of solve)

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.

## Syntax

```numeric::solve(`eqs`, <`vars`>, `options`)
float(holdsolve(`eqs`, <`vars`>, `options`))
float(freezesolve(`eqs`, <`vars`>, `options`))
```

## Description

`numeric::solve` computes numerical solutions of equations. For polynomial equations, all solutions are returned. For non-polynomial equations, only one solution, if any, is returned unless the option `AllRealRoots` is used.

### Note

Note that only for polynomial/rational equations all solutions are searched for. For non-polynomial/non-rational equations, only one solution, if any, is returned unless the option `AllRealRoots` is used.

If the equations contain non-polynomial expressions, it is in general not possible to isolate all roots numerically. Think of equations such as that have infinitely many real solutions around the origin! If a complete set of all real solutions of a single non-polynomial/non-rational equation in one unknown is desired, you may try the opton `AllRealRoots`. With this option, a heuristics tries to isolate all real solutions of the equation. This, however, is purely heuristical: there is no rigor in the algorithm and it is not guaranteed that all solutions are found. Alternatively, you may also use the routine `numeric::realroots` to isolate the intervals in which solutions may exist.

`numeric::solve` is a simple interface function unifying the functionality of the numerical solvers `numeric::fsolve`, `numeric::linsolve`, `numeric::polyroots`, and `numeric::polysysroots`. The return format of these routines is changed to make it consistent with the return values of the symbolic solver `solve`.

You may call the specialized numerical solvers directly. However, note the return types specific to each of these solvers.

`numeric::solve` classifies the equations as follows:

• If `eqs` is a single univariate polynomial equation, then it is directly passed to `numeric::polyroots`. Cf. Example 2. The roots are returned as a set or as a `Dom::Multiset` if `Multiple` is used.

• If `eqs` is a multivariate polynomial equation or a list or set of such equations, then the equations and the appropriate optional arguments are passed to either `numeric::linsolve` or `numeric::polysysroots`. Cf. Example 3. The roots are returned as a set or as a `Dom::Multiset` if `Multiple` is used.

• A rational equation or a set or list of rational equations is replaced by its/their numerator(s). Such equations are processed like polynomial equations.

• If `eqs` is a non-polynomial/non-rational equation or a set or list containing such an equation, then the equations and the appropriate optional arguments are passed to the numerical solver `numeric::fsolve`.

### Note

For non-polynomial equations, only a single numerical root is returned, unless `AllRealRoots` is specified! Cf. Example 4.

### Note

For non-polynomial equations, there must not be more equations than unknowns!

Using `Multiple` for non-polynomial equations leads to an error, unless the option `AllRealRoots` is specified, too!

### Note

For systems of multivariate non-polynomial equations, MuPAD® uses a Newton search. It must be able to evaluate the partial derivatives of the equations with respect to the variables to be solved for.

For a single univariate equation, first a bisectioning scheme with quadratic interpolation is used that does not require any differentiation of the equation. If this is not successful, a Newton search is started that requires the derivative of the functions involved.

For convenience, also polynomials of domain type `DOM_POLY` are accepted, wherever an equation is expected.

### Note

In contrast to the symbolic solver `solve`, the numerical solver does not react to properties of identifiers set via `assume`. The only exception where `numeric::solve` reacts to properties of identifiers is for systems of polynomial equations (only where there is more than one variable).

To react to properties of identifiers, instead call ```float ( hold( solve )(arguments))```.

If the user does not specify indeterminates to be solved for, then the indeterminates are internally chosen by `numeric::indets``(eqs)`.

Starting points such as `x = a` or search ranges such as `x = a..b` specified in `vars` are ignored if `eqs` is a polynomial equation or a system of polynomial equations.

## Environment Interactions

The function is sensitive to the environment variable `DIGITS`, which determines the numerical working precision.

## Examples

### Example 1

The following three solver calls are equivalent:

```eqs := {x^2 = sin(y), y^2 = cos(x)}: numeric::solve(eqs, {x, y}), float(hold(solve)(eqs, {x, y})), float(freeze(solve)(eqs, {x,y}))```

`delete eqs:`

### Example 2

We demonstrate the root search for univariate polynomials:

`numeric::solve(x^6 - PI*x^2 = sin(3), x)`

Polynomials of type `DOM_POLY` can be used as input:

`numeric::solve(poly((x - 1/3)^3, [x]), x)`

With `Multiple`, a `Dom::Multiset` is returned, indicating the multiplicity of the root:

`numeric::solve(x^3 - x^2 + x/3 -1/27, x, Multiple)`

### Example 3

We demonstrate the root search for polynomial systems. Note that the symbolic solver `solve` is involved if the system is nonlinear. Symbolic parameters are accepted:

`numeric::solve({x^2 + y^2 = 1, x^2 - y^2 = exp(z)}, {x, y})`

### Example 4

We demonstrate the root search for non-polynomial equations. Without the option `AllRealRoots`, only one solution is searched for:

```eq := exp(-x) - 10*x^2: numeric::solve(eq, x)```

Since `numeric::solve` just calls the root finder `numeric::fsolve`, one may also use this routine directly. Note the different output format:

`numeric::fsolve(eq, x)`

The input syntax of `numeric::solve` and `numeric::fsolve` are identical, i.e., starting points, search ranges and options may be used. E.g., another solution of the previous equation is found by a restricted search over the interval :

`numeric::solve(eq, x = -1..0, RestrictedSearch)`

We use the option `AllRealRoots` to isolate all real solutions of the equation:

`numeric::solve(eq, x, AllRealRoots)`

With the following call we restrict the search to the negative semi-axis:

`numeric::solve(eq, x = -infinity..0, AllRealRoots)`

### Example 5

For the following system, `numeric::solve` finds the solution with positive y:

```eqs := [exp(x) = 2*y^2, sin(y) = y*x^3]: numeric::solve(eqs, [x, y])```

Another solution with negative y is found with an appropriate search range:

`numeric::solve(eqs, [x = 1, y = -infinity..0])`

`delete eq, eqs:`

## Parameters

 `eqs` An equation, a list, set, `array`, or `matrix` (`Cat::Matrix`) of equations. Also arithmetical expressions are accepted and interpreted as homogeneous equations. `vars` An unknown, a list of unknowns or a set of unknowns. Unknowns may be identifiers or indexed identifiers. Also equations of the form `x=a` or `x=a..b` are accepted wherever an unknown `x` is expected. This way, starting points and search ranges are specified for the numerical search. They must be numerical; infinite search ranges are accepted.

## Options

`AllRealRoots`

Only to be used if `eqs` is a single equation in one unknown. With this option, a heuristics is used to find all real solutions of the equation.

### Note

Note that there is no guarantee that all real solutions will be found.

### Note

Interval arithmetic is used to isolate search intervals for the solutions. The expressions in `eqs` must be suitable for such arithmetic. Internally, the procedure `numeric::realroots` is called. See the help page of `numeric::realroots` for restrictions on the expressions in `eqs`.

### Note

The equation must be suitable for evaluation with interval arithmetic. See `numeric::realroots` for restrictions on the expressions in the equation.

With `AllRealRoots`, only the additonal options `Multiple` and `NoWarning` have an effect. All other options such as `UnrestrictedSearch` etc. are ignored.

It is highly recommend to specify a search interval by a call such as `numeric::solve(f(x), x = a..b, AllRealRoots)`. In this case, only the real solutions between `a` and `b` are searched for.

The search for all real solutions may be very time consuming!

`Multiple`

Only to be used if `eqs` is a polynomial equation or a system of polynomial equations or in conjunction with the option `AllRealRoots`. With this option, information on the multiplicity of degenerate polynomial roots is returned.

It changes the return type from `DOM_SET` to `Dom::Multiset`.

`FixedPrecision`

Only to be used if `eqs` is a single univariate polynomial. It launches a quick numerical search with fixed internal precision.

It is passed to `numeric::polyroots`, which uses a numerical search with fixed internal precision. This is fast, but degenerate roots may be returned with a restricted precision. See the help page of `numeric::polyroots` for details.

`SquareFree`

Only to be used if `eqs` is a single univariate polynomial. Symbolic square free factorization is applied, before the numerical search starts.

It is passed to `numeric::polyroots`, which preprocesses the polynomial by a symbolic square free factorization. See the help page of `numeric::polyroots` for details.

`Factor`

Only to be used if `eqs` is a single univariate polynomial. Symbolic factorization is applied, before the numerical search starts.

It is passed to `numeric::polyroots`, which preprocesses the polynomial by a symbolic factorization. See the help page of `numeric::polyroots` for details.

`RestrictedSearch`

The numerical search is restricted to the search ranges specified in `vars`.

This option is passed to `numeric::fsolve`, which uses a corresponding search strategy when looking for roots in the search range specified in `vars`. It must be used only in conjunction with search range and only for non-polynomial equations.

See `numeric::fsolve` for details.

`UnrestrictedSearch`

The numerical search may return results outside the search ranges specified in `vars`.

This option is passed to `numeric::fsolve`, which uses a corresponding search strategy when looking for roots in the search range specified in `vars`. It must be use only in conjunction with search ranges and only for non-polynomial equations.

See `numeric::fsolve` for details.

`MultiSolutions`

Only to be used for non-polynomial equations in conjunction with `RestrictedSearch`. Several roots may be returned.

It is passed to `numeric::fsolve`, which returns a sequence of all roots found in the internal search. See the help page of `numeric::fsolve` for details.

`Random`

Only to be used for non-polynomial equations. With this option, several calls to `numeric::solve` may lead to different solutions of the equation(s).

It is passed to `numeric::fsolve` which switches to a random search strategy. See the help page of `numeric::fsolve` for details.

`NoWarning`

This option only has an effect when it is used for polynomial equations in conjunction with `AllRealRoots`. When you use `AllRealRoots`, warnings are issued if interval arithmetic indicates technical difficulties such as serious overestimation (for example, when encountering multiple roots). With this option, the warnings are suppressed.

### Note

This option has an effect if `eqs` is a multivariate polynomial system or a univariate polynomial with a symbolic parameter.

In such a case, this option is passed to `numeric::polysysroots`.

## Return Values

Set of numerical solutions. With the option `Multiple`, a set of domain type `Dom::Multiset` is returned.

#### Mathematical Modeling with Symbolic Math Toolbox

Get examples and videos