Skip to content
DeepForgeby svx
All problems
EasyCalculusca-018

Bisection Step

Problem

Perform one step of the bisection method on the continuous function f(x) = sum(coeffs[i] * x^i) with bracket [a, b].

Return the new bracket [lo, hi] as a two-element list. If f at the midpoint is exactly 0.0, return [midpoint, midpoint].

Hint

Keep the half where f changes sign by comparing f(a) * f(mid) with 0.

Test cases

case 1
in: [[-2,0,1],1,2]
expected: [1,1.5]
case 2
in: [[-2,-1,0,1],1,2]
expected: [1.5,2]
case 3
in: [[0,1],-1,1]
expected: [0,0]
case 4
in: [[-4,0,1],0,3]
expected: [1.5,3]
Starter codePython
def bisection_step(coeffs, a, b):
    # Return the new bracket [lo, hi]
    # Your code here
    pass

4 test cases · run your code against them in the editor