find_roots: Numerically find roots of a function

View source: R/find_roots.R

find_rootsR Documentation

Numerically find roots of a function

Description

Root-finding algorithm using sliding windows to numerically find the roots of a function within a range.

Usage

find_roots(f, from, to, n = 10, size = 1, precis = NULL, ...)

Arguments

f

The function whose roots to find (must have one argument only)

from, to

The bounds of the range of values to explore

n

The number of bins in which to split the range

size

The size of the sliding window, in number of bins

precis

To what precision digit to round the solutions (no rounding if NULL)

...

Additional arguments to be passed to uniroot_noerr

Details

The function numerically looks for one root within each window, then removes duplicate solutions and returns the output. Sometimes duplicate solutions may not be recognized as such because they differ by a negligible amount. Use the precis argument to round those solutions to a lower precision (done using round) and recognize them as duplicates.

Value

A vector of solutions

See Also

get_sliding_windows, uniroot_noerr

Examples


f <- function(x) x^2 - 1
find_roots(f, -10, 10)


rscherrer/speciomx documentation built on March 28, 2023, 8:49 p.m.