Learn R Programming

mosaic (version 0.3-13)

findZeros: Find the zeros of a function

Description

Compute numerically the zeros of a function.

Usage

findZeros(expr, ..., xlim = NULL, npts = 1000)

Arguments

expr
A formula. The right side names the variable with respect to which the zeros should be found. The left side is an expression, e.g. sin(x) ~ x. All variables named in the expression must be assigned values via ...
...
Specific numerical values for the unbound variables in the expression.
xlim
The range of the dependent variable to search for zeros. Inf is a legitimate value, but is interpreted in the numerical sense as the non-Inf largest floating point number.
npts
How many sub-intervals to divide the xlim into when looking for candidates for zeros. The default is usually good enough. If Inf is involved, the intervals are logarithmically spaced up to the largest finite floating poin

Value

  • A set of zero or more numerical values. Plugging these into the expression on the left side of the formula should result in values near zero.

Details

Searches numerically using uniroot.

Examples

Run this code
findZeros( sin(x) ~ x, xlim=c(-10,10) )
findZeros( A*sin(2*pi*t/P) ~ t, xlim=c(0,100), P=50, A=2)
# Interval of a normal at half its maximum height.
findZeros( dnorm(x,mean=0,sd=10) - 0.5*dnorm(0,mean=0,sd=10) ~ x, xlim=c(-Inf,Inf))

Run the code above in your browser using DataLab