You will write a bisection function that refuses to start without a change of sign, and counts its own steps.
The idea. Take the midpoint, keep the half where the sign changes, and stop when the width is below the tolerance.
Your tasks.
sign_change(f, a, b). Return True when and have opposite signs, or one of them is .bisect(f, a, b, tol). Return None when there is no sign change. Otherwise return (midpoint, steps).steps_needed(a, b, tol). Return the least whole with tol.Run your code once to unlock the worked solution.
Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…