nag_interval_zero_cont_func (c05avc) (PDF version)
c05 Chapter Contents
c05 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_interval_zero_cont_func (c05avc)

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_interval_zero_cont_func (c05avc) attempts to locate an interval containing a simple zero of a continuous function using a binary search. It uses reverse communication for evaluating the function.

2  Specification

#include <nag.h>
#include <nagc05.h>
void  nag_interval_zero_cont_func (double *x, double fx, double *h, double boundl, double boundu, double *y, double c[], Integer *ind, NagError *fail)

3  Description

You must supply an initial point x and a step h. nag_interval_zero_cont_func (c05avc) attempts to locate a short interval x,y boundl,boundu  containing a simple zero of fx .
(On exit we may have x>y ; x is determined as the first point encountered in a binary search where the sign of fx  differs from the sign of fx  at the initial input point x.) The function attempts to locate a zero of fx  using h, 0.1×h , 0.01×h  and 0.001×h  in turn as its basic step before quitting with an error exit if unsuccessful.
nag_interval_zero_cont_func (c05avc) returns to the calling program for each evaluation of fx . On each return you should set fx=fx  and call nag_interval_zero_cont_func (c05avc) again.

4  References

None.

5  Arguments

Note: this function uses reverse communication. Its use involves an initial entry, intermediate exits and re-entries, and a final exit, as indicated by the argument ind. Between intermediate exits and re-entries, all arguments other than fx must remain unchanged.
1:     x double *Input/Output
On initial entry: the best available approximation to the zero.
Constraint: x must lie in the closed interval boundl,boundu  (see below).
On intermediate exit: contains the point at which f must be evaluated before re-entry to the function.
On final exit: contains one end of an interval containing the zero, the other end being in y, unless an error has occurred. If fail.code= NE_ZERO_NOT_FOUND, x and y are the end points of the largest interval searched. If a zero is located exactly, its value is returned in x (and in y).
2:     fx doubleInput
On initial entry: if ind=1, fx need not be set.
If ind=-1, fx must contain fx  for the initial value of x.
On intermediate re-entry: must contain fx  for the current value of x.
3:     h double *Input/Output
On initial entry: a basic step size which is used in the binary search for an interval containing a zero. The basic step sizes h,0.1×h , 0.01×h  and 0.001×h  are used in turn when searching for the zero.
Constraint: either x+h  or x-h  must lie inside the closed interval boundl,boundu .
h must be sufficiently large that x+hx  on the computer.
On final exit: is undefined.
4:     boundl doubleInput
5:     boundu doubleInput
On initial entry: boundl and boundu must contain respectively lower and upper bounds for the interval of search for the zero.
Constraint: boundl<boundu .
6:     y double *Input/Output
On initial entry: need not be set.
On final exit: contains the closest point found to the final value of x, such that fx × fy0.0 . If a value x is found such that fx=0 , then y=x . On final exit with fail.code= NE_ZERO_NOT_FOUND, x and y are the end points of the largest interval searched.
7:     c[11] doubleCommunication Array
On initial entry: need not be set.
On final exit: if fail.code= NE_NOERROR or NE_ZERO_NOT_FOUND, c[0]  contains fy .
8:     ind Integer *Input/Output
On initial entry: must be set to 1 or -1 .
ind=1
fx need not be set.
ind=-1
fx must contain fx .
On intermediate exit: contains 2 or 3. The calling program must evaluate f at x, storing the result in fx, and re-enter nag_interval_zero_cont_func (c05avc) with all other arguments unchanged.
On final exit: contains 0.
Constraint: on entry ind=-1, 1, 2 or 3.
9:     fail NagError *Input/Output
The NAG error argument (see Section 2.7 in How to Use the NAG Library and its Documentation).

6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INT
On entry, ind=value.
Constraint: ind=-1, 1, 2 or 3.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
An unexpected error has been triggered by this function. Please contact NAG.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_REAL_2
On entry, boundl=value and boundu=value.
Constraint: boundl<boundu.
On entry, h is too small for use as a perturbation of x: x=value and h=value.
NE_REAL_3
On entry, x=value, boundl=value and boundu=value.
Constraint: boundlxboundu.
NE_REAL_4
On entry, x+h and x-h both lie outside the interval boundl,boundu: x=value, h=value, boundl=value and boundu=value.
NE_ZERO_NOT_FOUND
An interval containing the zero could not be found.

7  Accuracy

nag_interval_zero_cont_func (c05avc) is not intended to be used to obtain accurate approximations to the zero of fx  but rather to locate an interval containing a zero. This interval can then be used as input to an accurate rootfinder such as nag_zero_cont_func_brent (c05ayc) or nag_zero_cont_func_brent_rcomm (c05azc). The size of the interval determined depends somewhat unpredictably on the choice of x and h. The closer x is to the root and the smaller the initial value of h, then, in general, the smaller (more accurate) the interval determined; however, the accuracy of this statement depends to some extent on the behaviour of fx  near x=x  and on the size of h.

8  Parallelism and Performance

nag_interval_zero_cont_func (c05avc) is not threaded in any implementation.

9  Further Comments

For most problems, the time taken on each call to nag_interval_zero_cont_func (c05avc) will be negligible compared with the time spent evaluating fx  between calls to nag_interval_zero_cont_func (c05avc). However, the initial value of x and h will clearly affect the timing. The closer x is to the root, and the larger the initial value of h then the less time taken. (However taking a large h can affect the accuracy and reliability of the function, see below.)
You are expected to choose boundl and boundu as physically (or mathematically) realistic limits on the interval of search. For example, it may be known, from physical arguments, that no zero of fx  of interest will lie outside boundl,boundu . Alternatively, fx  may be more expensive to evaluate for some values of x than for others and such expensive evaluations can sometimes be avoided by careful choice of boundl and boundu.
The choice of boundl and boundu affects the search only in that these values provide physical limitations on the search values and that the search is terminated if it seems, from the available information about fx , that the zero lies outside boundl,boundu . In this case (fail.code= NE_ZERO_NOT_FOUND on exit), only one of fboundl  and fboundu  may have been evaluated and a zero close to the other end of the interval could be missed. The actual interval searched is returned in the arguments x and y and you can call nag_interval_zero_cont_func (c05avc) again to search the remainder of the original interval.
Though nag_interval_zero_cont_func (c05avc) is intended primarily for determining an interval containing a zero of fx , it may be used to shorten a known interval. This could be useful if, for example, a large interval containing the zero is known and it is also known that the root lies close to one end of the interval; by setting x to this end of the interval and h small, a short interval will usually be determined. However, it is worth noting that once any interval containing a zero has been determined, a call to nag_zero_cont_func_brent_rcomm (c05azc) will usually be the most efficient way to calculate an interval of specified length containing the zero. To assist in this determination, the information in fx and in x, y and c[0]  on successful exit from nag_interval_zero_cont_func (c05avc) is in the correct form for a call to function nag_zero_cont_func_brent_rcomm (c05azc) with ind=-1 .
If the calculation terminates because fx=0.0 , then on return y is set to x. (In fact, y=x  on return only in this case.) In this case, there is no guarantee that the value in x corresponds to a simple zero and you should check whether it does.
One way to check this is to compute the derivative of f at the point x, preferably analytically, or, if this is not possible, numerically, perhaps by using a central difference estimate. If fx=0.0 , then x must correspond to a multiple zero of f rather than a simple zero.

10  Example

This example finds a sub-interval of 0.0,4.0  containing a simple zero of x2 - 3x+2 . The zero nearest to 3.0 is required and so we set x=3.0  initially.

10.1  Program Text

Program Text (c05avce.c)

10.2  Program Data

None.

10.3  Program Results

Program Results (c05avce.r)


nag_interval_zero_cont_func (c05avc) (PDF version)
c05 Chapter Contents
c05 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2016