Learn R Programming

pracma (version 1.8.8)

fzero: Root Finding

Description

Find root of continuous function of one variable.

Usage

fzero(f, x, ..., maxiter = 100, tol = .Machine$double.eps^(1/2))

Arguments

f
function whose root is sought.
x
a point near the root or an interval giving end points.
maxiter
maximum number of iterations.
tol
relative tolerance.
...
additional arguments to be passed to the function.

Value

  • fzero returns a list with
  • xlocation of the root.
  • fvalfunction value at the root.

Details

fzero tries to find a zero of f near x, if x is a scalar. Expands the interval until different signs are found at the endpoints or the maximum number of iterations is exceeded. If x is a vector of length two, fzero assumes x is an interval where the sign of x[1] differs from the sign of x[1]. An error occurs if this is not the case.

``This is essentially the ACM algorithm 748. The structure of the algorithm has been transformed non-trivially: it implement here a FSM version using one interior point determination and one bracketing per iteration, thus reducing the number of temporary variables and simplifying the structure.''

This approach will not find zeroes of quadratic order.

References

Alefeld, Potra and Shi (1995). Enclosing Zeros of Continuous Functions. ACM Transactions on Mathematical Software, Vol. 21, No. 3.

See Also

uniroot, brent

Examples

Run this code
fzero(sin, 3)                    # 3.141593
fzero(cos,c(1, 2))               # 1.570796
fzero(function(x) x^3-2*x-5, 2)  # 2.094551

Run the code above in your browser using DataLab