Skip to content
DeepForgeby svx
All problems
EasyCalculusca-007

Second Derivative Central Difference

Problem

Approximate the second derivative of f(x) = sum(coeffs[i] * x^i) at x with the central difference formula:

f''(x) ≈ (f(x + h) - 2 * f(x) + f(x - h)) / h^2

Use the default step h = 1e-3.

Hint

The numerator is a centered second difference; divide it by h squared.

Test cases

case 1
in: [[1,0,1],4]
expected: 2
case 2
in: [[0,0,0,2],1]
expected: 12
case 3
in: [[0,0,0,1],0]
expected: 0
case 4
in: [[5],3]
expected: 0
Starter codePython
def second_derivative(coeffs, x, h=1e-3):
    # coeffs[i] is the coefficient of x^i
    # Your code here
    pass

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