Description Usage Arguments Value Examples
Find the root of a function between two points a and b using the bisection method.
1 2 3 4 5 6 | unibisect(f, a, b, tol = 10 * .Machine$double.eps, maxit = 100L)
fast_unibisect(f, a, b, tol = 10 * .Machine$double.eps, bisections = 8L,
maxit = 100L)
simple_unibisect(f, a, b, tol = 10 * .Machine$double.eps, maxit = 100L)
|
f |
function |
a |
lower bound |
b |
upper bound |
tol |
tolerance, defaults to 10*.Machine$double.eps |
maxit |
maximum number of iterations |
bisections |
number or bisection steps for fast unibisect |
a list
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | f <- function(x) x^2 - 2
a <- 0; b <- 2
unibisect(f, a, b)
simple_unibisect(f, a, b)
fast_unibisect(f, a, b)
(out <- unibisect(f, a, b))
curve(f(x), col = "red", from = a, to = b)
with(out$evals, points(x, fx))
out$n_evals # = number of function calls
plot(1:out$n_evals, out$evals$fx)
f <- sin
a <- .1; b <- 2*pi - .2
(out <- unibisect(f, a, b))
curve(f(x), col = "red", from = a, to = b)
with(out$evals, points(x, fx))
out$n_evals # = number of function calls
plot(1:out$n_evals, out$evals$fx)
f <- function(x) (x-.24) * (x - .51) * (x - .76)
a <- 0; b <- 1
(out <- unibisect(f, a, b))
curve(f(x), col = "red", from = a, to = b)
with(out$evals, points(x, fx))
out$n_evals # = number of function calls
plot(1:out$n_evals, out$evals$fx)
f <- function(x) pbeta(x, 90, 10) - .5
a <- 0; b <- 1
(out <- fast_unibisect(f, 0, 1))
curve(f(x), col = "red", from = 0, to = 1)
with(out$evals, points(x, fx))
library(ggplot2)
ggplot(out$evals, aes(x, fx, color = method)) +
stat_function(fun = f, color = "black") +
geom_point()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.