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.
numeric::solve(eqs
, <vars
>,options
) float(holdsolve(eqs
, <vars
>,options
)) float(freezesolve(eqs
, <vars
>,options
))
numeric::solve
computes numerical solutions
of equations. For polynomial equations, all solutions
are returned. For nonpolynomial equations, only one solution,
if any, is returned unless the option AllRealRoots
is
used.
Note that only for polynomial/rational equations all solutions
are searched for. For nonpolynomial/nonrational equations, only
one solution, if any, is returned unless the option AllRealRoots
is
used.
If the equations contain nonpolynomial 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 nonpolynomial/nonrational
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 nonpolynomial/nonrational
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
.
For nonpolynomial equations, only a single numerical root is
returned, unless AllRealRoots
is specified! Cf. Example 4.
For nonpolynomial equations, there must not be more equations than unknowns!
Using Multiple
for nonpolynomial equations
leads to an error, unless the option AllRealRoots
is
specified, too!
For systems of multivariate nonpolynomial 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.
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.
The function is sensitive to the environment variable DIGITS
,
which determines the numerical working precision.
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:
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)
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})
We demonstrate the root search for nonpolynomial 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 semiaxis:
numeric::solve(eq, x = infinity..0, AllRealRoots)
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:

An equation, a list, set, 

An unknown, a list of unknowns or a set of unknowns. Unknowns
may be identifiers or indexed identifiers. Also equations of the
form 

Only to be used if NoteNote 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 NoteThe equation must be suitable for evaluation with interval arithmetic. See With It is highly recommend to specify a search interval by a call
such as The search for all real solutions may be very time consuming! 

Only to be used if It changes the return type from 

Only to be used if It is passed to 

Only to be used if It is passed to 

Only to be used if It is passed to 

The numerical search is restricted to the search ranges specified
in This option is passed to See 

The numerical search may return results outside the search ranges
specified in This option is passed to See 

Only to be used for nonpolynomial equations in conjunction
with It is passed to 

Only to be used for nonpolynomial equations. With this option,
several calls to It is passed to 

This option only has an effect when it is used for polynomial
equations in conjunction with NoteThis option has an effect if In such a case, this option is passed to 
Set of numerical solutions. With the option Multiple
,
a set of domain type Dom::Multiset
is
returned.