Navigation

Operators and Keywords

Function List:

C++ API

: fzero (fun, x0)
: fzero (fun, x0, options)
: [x, fval, info, output] = fzero (…)

Find a zero of a univariate function.

fun is a function handle, inline function, or string containing the name of the function to evaluate.

x0 should be a two-element vector specifying two points which bracket a zero. In other words, there must be a change in sign of the function between x0(1) and x0(2). More mathematically, the following must hold

sign (fun(x0(1))) * sign (fun(x0(2))) <= 0

If x0 is a single scalar then several nearby and distant values are probed in an attempt to obtain a valid bracketing. If this is not successful, the function fails.

options is a structure specifying additional options. Currently, fzero recognizes these options: "FunValCheck", "OutputFcn", "TolX", "MaxIter", "MaxFunEvals". For a description of these options, see ‘optimset’.

On exit, the function returns x, the approximate zero point and fval, the function value thereof.

info is an exit flag that can have these values:

  • 1 The algorithm converged to a solution.
  • 0 Maximum number of iterations or function evaluations has been reached.
  • -1 The algorithm has been terminated from user output function.
  • -5 The algorithm may have converged to a singular point.

output is a structure containing runtime information about the fzero algorithm. Fields in the structure are:

  • iterations Number of iterations through loop.
  • nfev Number of function evaluations.
  • bracketx A two-element vector with the final bracketing of the zero along the x-axis.
  • brackety A two-element vector with the final bracketing of the zero along the y-axis.

See also: optimset, fsolve.

Package: octave