fzero

Find a root of a univariate real function within an interval.

Syntax

x = fzero(@func,interval)

x = fzero(@func,interval,options)

[x,fval,info,output] = fzero(...)

Inputs

func
The function whose root is to be found.
interval
A two-element vector containing the root.
Type: double
Dimension: vector
options
A struct containing option settings.
See optimset for details.

Outputs

x
The location of the approximate root.
fval
The function value at the approximate root.
info
The convergence status flag.
info = 1
Function value converged to within tolX.
info = 0
Reached maximum number of iterations or function calls.
output
A struct containing iteration details. The members are as follows:
iterations
The number of iterations.
nfev
The number of function evaluations.
xiter
The function values of the interval end points at each iteration.
fvaliter
The interval end points at each iteration.

Example

function y = func(x)
    y = (x-3)^4 - 16;
end

options = optimset('TolX', 1.0e-8);
interval = [1, 6];
[x,fval] = fzero(@func, interval, options)
x = 4.99999999
fval = -4.18902e-07

Comments

fzero implements ACM Transactions on Mathematical Software algorithm 748, which does not require derivatives.

Options for convergence tolerance controls are specified with optimset.

To pass additional parameters to a function argument, use an anonymous function.

The optimset options and defaults are as follows:
  • MaxIter: 100
  • MaxFunEvals: 400
  • TolX: 1.0e-7