|MATLAB Function Reference|
Find zero of a function of one variable
x = fzero(fun,x0)
tries to find a zero of
x0 is a scalar.
fun is a function handle. See Function Handles in the MATLAB Programming documentation for more information. The value
x returned by
fzero is near a point where
fun changes sign, or
NaN if the search fails. In this case, the search terminates when the search interval is expanded until an
NaN, or complex value is found.
Parameterizing Functions Called by Function Functions, in the MATLAB mathematics documentation, explains how to provide additional parameters to the function
fun, if necessary.
x0 is a vector of length two,
x0 is an interval where the sign of
fun(x0(1)) differs from the sign of
fun(x0(2)). An error occurs if this is not true. Calling
fzero with such an interval guarantees
fzero will return a value near a point where
fun changes sign.
x = fzero(fun,x0,options)
minimizes with the optimization parameters specified in the structure
options. You can define these parameters using the
fzero uses these
options structure fields:
||Level of display.
||Check whether objective function values are valid.
||Specify a user-defined function that the optimization function calls at each iteration.
||Termination tolerance on
[x,fval] = fzero(...)
returns the value of the objective function
fun at the solution
[x,fval,exitflag] = fzero(...)
returns a value
exitflag that describes the exit condition of
||Function converged to a solution
||Algorithm was terminated by the output function.
||Complex function value was encountered during search for an interval containing a sign change.
[x,fval,exitflag,output] = fzero(...)
returns a structure
output that contains information about the optimization:
||Number of function evaluations
||Number of iterations taken to find an interval
||Number of zero-finding iterations
|Note For the purposes of this command, zeros are considered to be points where the function actually crosses, not just touches, the x-axis.|
fun is the function whose zero is to be computed. It accepts a vector
x and returns a scalar
f, the objective function evaluated at
x. The function
fun can be specified as a function handle for an M-file function
myfun is an M-file function such as
or as a function handle for an anonymous function:
Other arguments are described in the syntax descriptions above.
Example 1. Calculate by finding the zero of the sine function near 3.
Example 2. To find the zero of cosine between 1 and 2
cos(2) differ in sign.
Example 3. To find a zero of the function
write an anonymous function
Then find the zero near 2:
Because this function is a polynomial, the statement
roots([1 0 -2 -5]) finds the same real zero, and a complex conjugate pair of zeros.
fun is parameterized, you can use anonymous functions to capture the problem-dependent parameters. For example, suppose you want to minimize the objective function
myfun defined by the following M-file function.
myfun has an extra parameter
a, so you cannot pass it directly to
fzero. To optimize for a specific value of
a, such as
a = 2.
fzerowith a one-argument anonymous function that captures that value of
myfunwith two arguments:
fzero command 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 . A Fortran version, upon which the
fzero M-file is based, is in .
fzero command finds a point where the function changes sign. If the function is continuous, this is also a point where the function has a value near zero. If the function is not continuous,
fzero may return values that are discontinuous points instead of zeros. For example,
1.5708, a discontinuous point in
fzero command 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. Because the function never crosses the x-axis, however, no zero is found. For functions with no valid zeros,
fzero executes until
NaN, or a complex value is detected.
@), anonymous functions
 Brent, R., Algorithms for Minimization Without Derivatives, Prentice-Hall, 1973.
 Forsythe, G. E., M. A. Malcolm, and C. B. Moler, Computer Methods for Mathematical Computations, Prentice-Hall, 1976.
© 1994-2005 The MathWorks, Inc.