numeric
::realroots
Isolate intervals containing real roots of a univariate function
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::realroots(f(x
), <x = a .. b
>, <eps
>, <Merge = c
>)
numeric::realroots(f(x), x = a..b)
searches
for real roots of f(x) in
the interval .
It returns a list of subintervals in which real roots of f(x) may
exist. It is guaranteed that there are no real roots in the interval
lying
outside the union of the returned subintervals.
With Merge = FALSE
, all intervals returned
by numeric::realroots
have length bi - ai < eps with
a default value eps = 0.01.
The absolute precision of the root isolation may be redefined using
the optional parameter eps
.
The intervals returned by numeric::realroots
define
a subset of that
may contain real roots. For polynomial expressions f(x),
each of the subintervals of
returned
by
numeric::realroots
is guaranteed to contain
exactly one root. For non-polynomial expressions f(x),
however, some of the subintervals may contain no root! Cf. Example 6.
In any case, the complement of
the subintervals
returned
by
numeric::realroots
is guaranteed to contain
no real roots. In particular, from the return value [],
one may positively conclude that no root exists in the search interval .
Cf. Example 2.
Symbolic parameters in f(x) are
not allowed: float(f(x))
must evaluate to a floating
point number for all x from
the interval .
Infinite intervals of the form x = -infinity..b
are
not refined if b ≤ -
105.
Infinite intervals of the form x = a..infinity
are
not refined if a ≥ 105.
Such intervals are returned directly if numeric::realroots
thinks
that they may contain roots. Cf. Example 5.
f(x) may
contain complex expressions. Only the search parameter x is
assumed to be real. For complex expressions f(x)
,
the intervals are returned where both the real and the imaginary part
of the expression vanish simultaneously.
The expression f(x)
must be suitable for interval arithmetic. In particular, MuPAD® must
be able to evaluate f(a...b)
. Note that not all MuPAD functions
support this kind of arithmetic.
Presently, the following special functions support interval
arithmetic: abs
, arccos
, arccosh
, arccoth
, arccot
, arccsc
, arccsch
, arcsec
, arcsech
, arcsin
, arcsinh
, arctan
, arctanh
, arg
, beta
, ceil
, cos
, cosh
, cot
, coth
, csc
, csch
, dirac
, exp
, floor
, gamma
, Im
, ln
, Re
, round
, sec
, sech
, sin
, sinh
, sqrt
, tan
, tanh
, trunc
. Real roots can be searched for
any expression that is built from these functions using the standard
arithmetical operations +
, -
, *
, /
, ^
.
The default value is eps =
0.01. User defined precision goals must satisfy .
The function is sensitive to the environment variable DIGITS
,
which determines the numerical working precision.
The following expression has integer zeros. The solutions in the specified interval are approximated to the default precision 0.01:
numeric::realroots(sin(PI*x), x = -2..sqrt(2))
The following equation is solved with an absolute precision of 7 digits:
numeric::realroots(x*sin(x) = exp(-x), x = -1..1, 10^(-7))
The following expression does not have a real root:
numeric::realroots(exp(x) + x^2, x = -100..100)
We demonstrate the option Merge
. If interval
arithmetic can not isolate roots to the desired precision eps (default
0.01), then adjacent intervals are produced, each of length smaller
than eps.
This happens in the following example:
numeric::realroots(ln(x^2 -2*x + 2) = 0, x = -10..10, Merge = FALSE)
With Merge = TRUE
, these intervals are combined
to a single larger interval. Since Merge = TRUE
is
the default setting for non-polynomial functions, it suffices to omit
the option Merge = FALSE
:
numeric::realroots(ln(x^2 -2*x + 2) = 0, x = -10..10)
The following expression has infinitely many solutions with n =
1, 2, … in the search interval [0,
1]:
numeric::realroots(sin(PI/x), x = 0..1, 0.1, Merge = FALSE)
Omitting Merge = FALSE
, adjacent intevals
are merged to larger intervals. The first of the following intervals
contains infinitely many roots:
numeric::realroots(sin(PI/x), x = 0..1, 0.1)
If no search interval is specified, the entire real line is considered:
numeric::realroots(x^3 = exp(x))
Apart from two finite intervals, numeric::realroots
tells
us that there may be a root close to infinity (but that there is positively
no root close to -infinity). Analytically, it is clear that the subinterval cannot
contain a root, since
grows
much faster than x3 as x goes
to infinity. If a finite upper limit for the search interval is specified,
this fact is detected:
numeric::realroots(x^3 = exp(x), x = -infinity .. 10^100)
We isolate the two finite roots more closely by specifying a
precision goal of :
numeric::realroots(x^3 = exp(x), x = -infinity .. 10^100, 10^(-DIGITS))
The following equation has no root close to 0. However, interval
arithmetic does not produce realistic values of for
small intervals containing x =
0, so an isolating interval around 0 is returned:
numeric::realroots(sin(PI*x)/x = 0, x = -1..1.2)
A similar phenomenon occurs with in
a neighbourhood of x = 0.
An isolating interval around 0 is returned, although no solution exists
there:
numeric::realroots(x^x*cos(PI*x) = tan(x), x = 0..1)
This cannot be cured by increasing the precision goal:
numeric::realroots(x^x*cos(PI*x) = tan(x), x = 0..1, 10^(-DIGITS))
|
An expression in one indeterminate |
|
An identifier or an indexed identifier |
|
Real numbers or numerical expressions satisfying a < b.
Also |
|
A (small) positive real numerical value defining the precision goal. The default value is 0.01. |
|
Option, specified as
The default setting is
With With The default setting is |
List [[a1, b1],
[a2, b2],
…] of disjoint floating-point intervals which
may contain roots of f(x).
The empty list is returned if no root exists in the search interval [a, b].
Let X be
a subset of the real numbers. Interval arithmetic produces a set F(X) such
that the set of image values is
contained in F(X).
The MuPAD domain
DOM_INTERVAL
facilitates this kind of arithmetic.
The routine numeric::realroots
computes for
various subintervals
of
.
If F does
not contain zero, then this subinterval is eliminated from the search
interval. Otherwise, the subinterval is returned as a candidate for
containing zeros of f(x).
However, one cannot conclude that F does
indeed contain at least one zero, since F is
usually larger than the true image set
(‘overestimation’).
For polynomials f(x),
the routine polylib::realroots
is
called. Its results are intersected with the search interval .
No interval arithmetic is used for polynomial expressions. For polynomial
equations, each isolating interval returned by
numeric::realroots
is
guaranteed to contain at least one root if Merge = TRUE
is
specified. With the default setting of Merge = FALSE
for
polynomials, each isolating interval is guaranteed to contain exactly
one root.