Problem 1 Write a Julia function bisectsearch that takes a function f(x) and an
ID: 2894944 • Letter: P
Question
Problem 1 Write a Julia function bisectsearch that takes a function f(x) and an interval a, b for which f (a) and f (b) have opposite signs, and returns a root of f within that interval. Hints: while writing your bisect search function, test it on a simple function whose root you know, for example f(x) = x2-4, which has the root x = 2 . You're likely to make mistakes in your first attempt at any algorithm. To help you find and fix errors, add some diagnostic printing to your function that prints out a, b, and f(c) at each iteration. Add an optional argument diagnostics to the function that turns the printing on and off. Make diagnostics default to false. While developing your function, use a simple and sure stopping condition, for example, iterating a fixed number of times, perhaps ten or twenty. f ( b ) , rather than evaluating these Store the values of f ( a ) and f ( b ) in temporary variables, eg. fa, quantities repeatedly for the same values of a and b. In real-world applications, evaluating f is expensive, so you want to minimize the number of function evaluations! fb f ( a ) , · = Once you've got the logic of bisection working correctly, make sure it works for any floating-point type, and change the stopping condition to ensure an appropriate level of accuracy for the given floating point type. I suggest stopping the searclh when either (b - a) (lal bl)Explanation / Answer
This is a Matlab code:-
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.