MATLAB Function Reference
  Go to function:
    Search    Help Desk 
fzero    Examples   See Also

Zero of a function of one variable

Syntax

Description

x = fzero(fun,x0) tries to find a zero of fun near x0. fun (usually an M-file, built-in function, or an inline object) should take a scalar real value and return a real scalar value when called with feval: f=feval(fun,x). The value x returned by fzero is near a point where fun changes sign, or NaN if the search fails.

x = fzero(fun,x0) where x0 is a vector of length two, assumes 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) where x0 is a scalar value, uses x0 as a starting guess. fzero looks for an interval containing a sign change for fun and containing x0. If no such interval is found, NaN is returned. In this case, the search terminates when the search interval is expanded until an Inf, NaN, or complex value is found.

x = fzero(fun,x0,options) minimizes with the optimization parameters specified in the structure options. You can define these parameters using the optimset function. fzero uses these options structure fields:

x = fzero(fun,x0,options,P1,P2,...) provides for additional arguments passed to the function, f=feval(fun,x,P1,P2,...). Pass an empty matrix for options to use the default values.

[x,fval] = fzero(...) returns the value of the objective function fun at the solution x.

[x,fval,exitflag] = fzero(...) returns a value exitflag that describes the exit condition of fzero:

[x,fval,exitflag,output] = fzero(...) returns a structure output that contains information about the optimization:

NOTE
For the purposes of this command, zeros are considered to be points where the function actually crosses, not just touches, the x-axis.

Arguments

fun is a string containing the name of a file in which an arbitrary function of one variable is defined. fun can also be an inline object.

Other arguments are described in the syntax descriptions above.

Examples

Calculate by finding the zero of the sine function near 3.

To find the zero of cosine between 1 and 2

        1.5708

Note that cos(1) and cos(2) differ in sign.

To find a zero of the function

write an M-file called f.m.

To 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.

fzero('abs(x)+1', 1) returns NaN since this function does not change sign anywhere on the real axis (and does not have a zero as well).

Algorithm

The 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 [1]. A Fortran version, upon which the fzero M-file is based, is in [2].

Limitations

The 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 Inf, NaN, or a complex value is detected.

See Also

roots, fminbnd, inline, optimset

References

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

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



[ Previous | Help Desk | Next ]

Hosted by www.Geocities.ws

1