Description Usage Arguments Details Value Note Author(s) References See Also
View source: R/bisection.method.R
This is a visual demonstration of finding the root of an equation f(x) = 0 on an interval using the Bisection Method.
1 2 3 4 5 6 7 8 9 10 | bisection.method(
FUN = function(x) x^2 - 4,
rg = c(-1, 10),
tol = 0.001,
interact = FALSE,
main,
xlab,
ylab,
...
)
|
FUN |
the function in the equation to solve (univariate) |
rg |
a vector containing the end-points of the interval to be searched
for the root; in a |
tol |
the desired accuracy (convergence tolerance) |
interact |
logical; whether choose the end-points by cliking on the curve (for two times) directly? |
xlab, ylab, main |
axis and main titles to be used in the plot |
... |
other arguments passed to |
Suppose we want to solve the equation f(x) = 0. Given two points a and b such that f(a) and f(b) have opposite signs, we know by the intermediate value theorem that f must have at least one root in the interval [a, b] as long as f is continuous on this interval. The bisection method divides the interval in two by computing c = (a + b) / 2. There are now two possibilities: either f(a) and f(c) have opposite signs, or f(c) and f(b) have opposite signs. The bisection algorithm is then applied recursively to the sub-interval where the sign change occurs.
During the process of searching, the mid-point of subintervals are annotated in the graph by both texts and blue straight lines, and the end-points are denoted in dashed red lines. The root of each iteration is also plotted in the right margin of the graph.
A list containing
root |
the root found by the algorithm |
value |
the value of |
iter |
number of
iterations; if it is equal to |
The maximum number of iterations is specified in
ani.options('nmax')
.
Yihui Xie
Examples at https://yihui.org/animation/example/bisection-method/
For more information about Bisection method, please see https://en.wikipedia.org/wiki/Bisection_method
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.