nag_zero_cont_func_bd_1 (c05sdc) (PDF version)
c05 Chapter Contents
c05 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_zero_cont_func_bd_1 (c05sdc)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_zero_cont_func_bd_1 (c05sdc) locates a zero of a continuous function in a given interval by a combination of the methods of linear interpolation, extrapolation and bisection.

2  Specification

#include <nag.h>
#include <nagc05.h>
void  nag_zero_cont_func_bd_1 (double a, double b, double *x,
double (*f)(double x, Nag_User *comm),
double xtol, double ftol, Nag_User *comm, NagError *fail)

3  Description

nag_zero_cont_func_bd_1 (c05sdc) attempts to obtain an approximation to a simple zero of the function f x  given an initial interval a,b  such that f a × f b 0 . The zero is found by a modified version of procedure ‘zeroin’ given by Bus and Dekker (1975). The approximation x to the zero α is determined so that one or both of the following criteria are satisfied:
(i) x-α < xtol ,
(ii) fx < ftol .
The function combines the methods of bisection, linear interpolation and linear extrapolation (see Dahlquist and Björck (1974)), to find a sequence of sub-intervals of the initial interval such that the final interval x,y  contains the zero and is small enough to satisfy the tolerance specified by xtol. Note that, since the intervals x,y  are determined only so that they contain a change of sign of f , it is possible that the final interval may contain a discontinuity or a pole of f  (violating the requirement that f  be continuous). If the sign change is likely to correspond to a pole of f  then the function gives an error return.

4  References

Bus J C P and Dekker T J (1975) Two efficient algorithms with guaranteed convergence for finding a zero of a function ACM Trans. Math. Software 1 330–345
Dahlquist G and Björck Å (1974) Numerical Methods Prentice–Hall

5  Arguments

1:     adoubleInput
On entry: the lower bound of the interval, a .
2:     bdoubleInput
On entry: the upper bound of the interval, b .
Constraint: ba .
3:     xdouble *Output
On exit: the approximation to the zero.
4:     ffunction, supplied by the userExternal Function
f must evaluate the function f whose zero is to be determined.
The specification of f is:
double  f (double x, Nag_User *comm)
1:     xdoubleInput
On entry: the point x  at which the function must be evaluated.
2:     commNag_User *
Pointer to a structure of type Nag_User with the following member:
pPointer 
On entry/exit: the pointer commp should be cast to the required type, e.g., struct user *s = (struct user *)comm → p, to obtain the original object's address with appropriate type. (See the argument comm below.)
5:     xtoldoubleInput
On entry: the absolute tolerance to which the zero is required (see Section 3).
Constraint: xtol>0.0 .
6:     ftoldoubleInput
On entry: a value such that if f x < ftol , x  is accepted as the zero. ftol may be specified as 0.0 (see Section 9).
7:     commNag_User *
Pointer to a structure of type Nag_User with the following member:
pPointer 
On entry/exit: the pointer commp, of type Pointer, allows you to communicate information to and from f(). You must declare an object of the required type, e.g., a structure, and its address assigned to the pointer commp by means of a cast to Pointer in the calling program, e.g., comm.p = (Pointer)&s. The type pointer will be void * with a C compiler that defines void * and char * otherwise.
8:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

NE_2_REAL_ARG_EQ
On entry, a=value  while b=value . These arguments must satisfy ab .
NE_FUNC_END_VAL
On entry, f(value) and f(value) have the same sign, with f(value) 0.0 .
NE_PROBABLE_POLE
Indicates that the function values in the interval a,b  might contain a pole rather than a zero. Reducing xtol may help in distinguishing between a pole and a zero.
NE_REAL_ARG_LE
On entry, xtol must not be less than or equal to 0.0: xtol=value .
NE_XTOL_TOO_SMALL
No further improvement in the solution is possible. xtol is too small: xtol=value .

7  Accuracy

This depends on the value of xtol and ftol. If full machine accuracy is required, they may be set very small, resulting in an error exit with error exit of NE_XTOL_TOO_SMALL, although this may involve many more iterations than a lesser accuracy. You are recommended to set ftol=0.0  and to use xtol to control the accuracy, unless you have considerable knowledge of the size of fx  for values of x near the zero.

8  Parallelism and Performance

Not applicable.

9  Further Comments

The time taken by nag_zero_cont_func_bd_1 (c05sdc) depends primarily on the time spent evaluating f (see Section 5).

10  Example

This example calculates the zero of e-x - x  within the interval 0,1  to approximately five decimal places.

10.1  Program Text

Program Text (c05sdce.c)

10.2  Program Data

None.

10.3  Program Results

Program Results (c05sdce.r)


nag_zero_cont_func_bd_1 (c05sdc) (PDF version)
c05 Chapter Contents
c05 Chapter Introduction
NAG Library Manual

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