All problems
Forward Difference Derivative
Problem
Approximate the derivative of f(x) = sum(coeffs[i] * x^i) at x using the forward difference quotient:
f'(x) ≈ (f(x + h) - f(x)) / h
coeffs[i] is the coefficient of x^i and h defaults to 1e-6.
Hint
Evaluate the polynomial at x and at x + h, then divide the difference by h.
Test cases
case 1
in: [[1,2,1],2]
expected: 6.000001
case 2
in: [[0,0,2],-1]
expected: -3.999998
case 3
in: [[7],5]
expected: 0
case 4
in: [[0,3],10]
expected: 3
Starter codePython
def forward_difference(coeffs, x, h=1e-6):
# coeffs[i] is the coefficient of x^i
# Your code here
pass4 test cases · run your code against them in the editor