Skip to content
Prev 312396 / 398506 Next

Help in Bissection algorithm

And have the function return a value.  All values
set in the function will be destroyed when the
function is done - you must return something and
the caller must assign the return value to a variable
if you want to keep it.

E.g.,
raiz
function (f, a, b, e) 
{
    i <- 0
    repeat {
        if (i > 50) {
            break
        }
        if (abs(a - b) < e) {
            m = (a + b)/2
            raiz1 = m
        }
        if (abs(a - b) > e) {
            m = (a + b)/2
            af = f(a)
            if ((af * f(m)) > 0) {
                a = m
            }
            if ((af * f(m)) < 0) {
                b = m
            }
        }
        i = i + 1
    }
    c(a, b) # bounds on estimate of root
}
[1] -1.316074 -1.316074
[1]  7.566836e-12 -5.231717e-10

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com