All problems
Secant Method One Step
Problem
Take one secant-method step for f(x) = sum(coeffs[i] * x^i) using the two starting points x0 and x1:
x2 = x1 - f(x1) * (x1 - x0) / (f(x1) - f(x0))
If f(x1) == f(x0), return x1 unchanged.
Hint
The secant method replaces the derivative with a finite-difference slope.
Test cases
case 1
in: [[-2,0,1],1,2]
expected: 1.3333333333333333
case 2
in: [[-2,-1,0,1],1,2]
expected: 1.3333333333333333
case 3
in: [[-1,0,1],0,1]
expected: 1
case 4
in: [[0,0,1],1,-1]
expected: -1
Starter codePython
def secant_step(coeffs, x0, x1):
# Your code here
pass4 test cases · run your code against them in the editor