z = fzero('function',x0)
z = fzero('function',x0,tol)
z = fzero('function',x0,tol,trace)
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.
To find a zero of the functionCalculate pi by finding the zero of the sine function near 3.
x = fzero('sin',3)
x =
3.1416
write an M-file called f
.m
.
To find the zero near 2function y = f(x)
y = x.^3-2*x-5;
Since this function is actually a polynomial, the statementz = fzero('f',2)
z =
2.0946
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
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].
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.
eps
,fmin
,roots
[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.