Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose we have a function, f0, in R, and we know it is increasing (possibly fla

ID: 3577762 • Letter: S

Question

Suppose we have a function, f0, in R, and we know it is increasing (possibly flat in places, non-decreasing) on the interval from A to B. We also know that f(A) is negative and f CB) is positive. Write a function, called fin that finds the value xo such that 0. The function fo may have a flat spot at o, and in this case, co should be the smallest x such that f (x) is 0. The arguments to find00 are: two required parameters A and B, and one optional input argument, tol which has a default value of 0.001. The return value of your function a value that is within tol of it. Be careful that your examination of f x) takes into account the machine tolerance. That is, the function call (x) may not return the exact analytic value. Use the bisection method/binary search approach to find xo.

Explanation / Answer

find0 <- function(A, B, tol=0.001){
    while(f(mid)>tol){
        mid <- (A+B)/2
        if(f(mid)>0){
            B <- mid
        }
        else{
            A <- mid
        }
    }
    return(mid)
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote