Learn R Programming

mosaic (version 0.2-3)

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 interpretted in the numerical sense.
npts
How many sub-intervals to divide the xlim into when looking for candidates for zeros. If Inf is involved, the intervals are numerically spaced up to the largest finite floating point number.

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)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