Learn R Programming

pracma (version 1.4.5)

fzero: Root Finding

Description

Find root of continuous function of one variable.

Usage

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

zeroin(f, interval, ..., tol = .Machine$double.eps^(1/2))

Arguments

f
function whose root is to be found.
x0
a point near the root or an interval giving end points.
interval
vector of length 2, defining a finite interval on the real line.
maxiter
maximum number of iterations.
tol
absolute tolerance.
...
additional variables to be passed to the function.

Value

  • List with
  • xlocation of the root.
  • fvalfunction value at the root.

Details

fzero tries to find a zero of f near x0, if x0 is a scalar. Expands the interval until different signs are found at the endpoints or the maximum number of iterations is exceeded.

If x0 is a vector of length two, fzero assumes x0 is an interval where the sign of x0[1] differs from the sign of x0[1]. An error occurs if this is not true.

zeroin implements a version of the Brent-Dekker algorithm.

This approach will not find zeroes of quadratic order.

References

Quarteroni, A., R. Sacco, and F. Saleri (2007). Numerical Mathematics. Second Edition, Springer-Verlag, Berlin Heidelberg.

See Also

brent_dekker, newtonRaphson

Examples

Run this code
fzero(sin, 3)                    # 3.141593 +- 1.25e-13
fzero(cos,c(1, 2))               # 1.570796 +- 1.02e-9
fzero(function(x) x^3-2*x-5, 2)  # 2.094551 +- 1.58e-11

Run the code above in your browser using DataLab