Previous Page Next Page Contents

numeric::realroot -- numerical search for a real root of a real univariate function

Introduction

numeric::realroot(f(x), x=a..b, ..) computes a numerical real root of f(x) in the interval [a,b].

Call(s)

numeric::realroot(f(x), x = a..b <, SearchLevel = s>)

Parameters

f(x) - an arithmetical expression in one unknown x. Alternatively, an equation f1(x)=f2(x) equivalent to the expression f1(x)-f2(x).
x - an identifier or an indexed identifier
a, b - finite real numerical values

Options

SearchLevel = s - s is a small non-zero integer. It controls the internal refinement of the search.

Returns

a single numerical real root of domain type DOM_FLOAT. If no solution is found, then FAIL is returned.

Side Effects

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

Related Functions

numeric::fsolve, numeric::polyroots, numeric::realroots, polylib::realroots, solve

Details

Option: SearchLevel= s

Example 1

The following functions assume different signs at the boundaries, so the searches are bound to succeed:

>> numeric::realroot(x^3 - exp(3), x = -PI..10)
                                2.718281829
>> numeric::realroot(exp(-x[1]) = x[1], x[1] = 0..1)
                               0.5671432904

Example 2

The following function cannot be evaluated for non-numerical x. So one has to delay evaluation via hold:

>> f := proc(x) begin 
         if x<0 then 1 - x else exp(x) - 10*x end_if
        end_proc:
>> numeric::realroot(hold(f)(x), x = -10..10) 
                               0.1118325592
>> delete f:

Example 3

numeric::realroot approximates a point, where f(x) changes its sign. For the following function this happens at the discontinuity x=1:

>> f := proc(x) begin if x<1 then -1 else x end_if end_proc:
>> numeric::realroot(hold(f)(x), x = 0..3)
                                    1.0
>> delete f:

Example 4

The following function does not have a real root. Consequently, numeric::realroot fails:

>> numeric::realroot(x^2 + 1, x = -2..2)
                                   FAIL

The following function does not have a real root in the search interval:

>> numeric::realroot(x^2 - 1, x =  2..3)
                                   FAIL

Example 5

The following function is complex valued for x^2 <3.5. An error occurs, when the internal search hits such a point:

>> numeric::realroot(ln(x^2 - 3.5), x = -2..3)
      Error: Complex arguments are not allowed in comparisons;
      during evaluation of 'numeric::BrentFindRoot'

The singularity at x=2 does not cause any problem in the following call:

>> numeric::realroot((x-1)/(x-2), x = -10..PI)
                                    1.0

However, the singularity may be hit accidentally in the internal search:

>> numeric::realroot((x-1)/(x-2), x = -10..14)
      Error: Division by zero [_power];
      during evaluation of 'f'

Example 6

The following function has a root close to 1.0, which is difficult to detect. With the default search level s=1 this root is not found:

>> f := 2 - exp(-100*(x - 2)^2) - 2*exp(-1000*(x - 1)^2):
>> numeric::realroot(f, x = 0..5)
                                   FAIL

The root is detected with an increased search level:

>> numeric::realroot(f, x = 0..5, SearchLevel = 3)
                                    1.0
>> delete f:

Background

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000