Skip to content
DeepForgeby svx
All problems
MediumOptimizationop-040

Newton Step 1D With Finite Differences

Problem

Take one Newton step on f(x) = x^4 - 3*x^2 + 2*x using central finite differences.

With difference step h, estimate g = (f(x+h) - f(x-h)) / (2h) and curvature = (f(x+h) - 2*f(x) + f(x-h)) / h^2, then return x - g / curvature. Use the exact polynomial for the evaluations.

Hint

The second difference divided by h squared estimates the curvature.

Test cases

case 1
in: [2,0.00001]
expected: 1.4761901871974508
case 2
in: [0.5,0.00001]
expected: 0.3333334088697898
case 3
in: [-1.5,0.00001]
expected: -1.3809523404207176
case 4
in: [0,0.00001]
expected: 0.33333333334389625
Starter codePython
def newton_step_1d(x, h):
    # Your code here
    pass

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