Suppose we have a function, f0, in R, and we know it is increasing (possibly fla
ID: 3579762 • 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)
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.