BFfzero {NLRoot}R Documentation

Bisection Method

Description

Bisection Method to Find the Root of Nonlinear Equation

Usage

BFfzero(f, a, b, num = 10, eps = 1e-05)

Arguments

f

the objective function which we will use to solve for the root

a

mininum of the interval which cantains the root from Bisection Method

b

maxinum of the interval which cantains the root from Bisection Method

num

the number of sections that the interval which from Bisection Method

eps

the level of precision that |x(k+1)-x(k)| should be satisfied in order to get the idear real root. eps=1e-5 when it is default

Details

Be careful to choose a & b. If not we maybe fail to find the root

Value

a root of the objective function which between the interwal from a to b

Note

Maintainer:Zheng Sengui<1225620446@qq.com>

Author(s)

Zheng Sengui,Lu Xufen,Hou Qiongchen,Zheng Jianhui

References

Luis Torgo (2003) Data Mining with R:learning by case studies. LIACC-FEP, University of Porto

See Also

NDHfzero,NIMfzero,SMfzero

Examples

f<-function(x){x^3-x-1};f1<-function(x){3*x^2-1};

    BFfzero(f,0,2)
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (f, a, b, num = 10, eps = 1e-05) 
{
    h = abs(b - a)/num
    i = 0
    j = 0
    a1 = b1 = 0
    while (i <= num) {
        a1 = a + i * h
        b1 = a1 + h
        if (f(a1) == 0) {
            print(a1)
            print(f(a1))
        }
        else if (f(b1) == 0) {
            print(b1)
            print(f(b1))
        }
        else if (f(a1) * f(b1) < 0) {
            repeat {
                if (abs(b1 - a1) < eps) 
                  break
                x <- (a1 + b1)/2
                if (f(a1) * f(x) < 0) 
                  b1 <- x
                else a1 <- x
            }
            print(j + 1)
            j = j + 1
            print((a1 + b1)/2)
            print(f((a1 + b1)/2))
        }
        i = i + 1
    }
    if (j == 0) 
        print("finding root is fail")
    else print("finding root is successful")
  }

[Package NLRoot version 1.0 Index]