All problems
Newton Method One Step
Problem
Take one Newton-Raphson step for the polynomial f(x) = sum(coeffs[i] * x^i), starting at x0:
x1 = x0 - f(x0) / f'(x0)
Return x1 as a float. Assume f'(x0) != 0.
Hint
Differentiate term by term, then subtract the ratio f / f' from x0.
Test cases
case 1
in: [[-2,0,1],1]
expected: 1.5
case 2
in: [[-2,0,1],2]
expected: 1.5
case 3
in: [[-2,-1,0,1],2]
expected: 1.6363636363636365
case 4
in: [[0,0,1],3]
expected: 1.5
case 5
in: [[5,2],0]
expected: -2.5
Starter codePython
def newton_step(coeffs, x0):
# Your code here
pass5 test cases · run your code against them in the editor