fzero

Purpose

Zero of a function of one variable.

Synopsis

z = fzero('function',x0)
z = fzero('function',x0,tol)
z = fzero('function',x0,tol,trace)

Description

fzero('function',x0) finds a zero of the function function(x) that is near x0. fzero identifies only points where the function actually crosses the x-axis. Points where the function touches the x-axis, but does not cross it, are not considered zeros.

fzero('function',x0,tol) returns an answer accurate to within a relative error of tol. The default value for tol is eps.

z = fzero('function',x0,tol,trace) displays information at each iteration if trace is nonzero.

Examples

Calculate pi by finding the zero of the sine function near 3.
x = fzero('sin',3)
          
x =
    3.1416
To find a zero of the function

write an M-file called f.m.

function y = f(x)
y = x.^3-2*x-5;
To find the zero near 2

z = fzero('f',2)
z =
    2.0946
Since this function is actually a polynomial, the statement

roots([1 0 -2 -5])
finds the same real zero, and a complex conjugate pair of zeros.

    2.0946 
   -1.0473 + 1.1359i
   -1.0473 - 1.1359i

Algorithm

fzero is an M-file. The algorithm, which was originated by T. Dekker, uses a combination of bisection, secant, and inverse quadratic interpolation methods. An Algol 60 version, with some improvements, is given in [1]. A FORTRAN version, upon which the fzero M-file is based, is in [2].

Limitations

fzero defines a zero as a point where the function crosses the x-axis. Points where the function touches, but does not cross, the x-axis are not valid zeros. For example, y = x.^2 is a parabola that touches the x-axis at (0,0). Since the function never crosses the x-axis, however, no zero is found. For functions with no valid zeros, fzero executes until you terminate it.

See Also

eps, fmin, roots

References

[1] R. Brent, Algorithms for Minimization Without Derivatives, Prentice-Hall, 1973.

[2] G. E. Forsythe, M. A. Malcolm, and C. B. Moler, Computer Methods for Mathematical Computations, Prentice-Hall, 1976.

(c) Copyright 1994 by The MathWorks, Inc.