"""Example from the exercise 03 sept 2026: Write a function that uses a forward difference to compute the derivative of a function f(x) in a point x. The function f and the point x are given as arguments.""" def diff(f, x, h=1e-6): r = (f(x + h) - f(x)) / h return r def g(x): return x**2 - 2 x = 2.0 dg = diff(g, x=x) print(f"dg/dx = {dg:g}") """ Alternatively, we can use a lambda function to specify the function directly in the argument list to diff:""" dg = diff(lambda x: x**3 - 4*x + 2, x=1.5) print(f"dg/dx = {dg:g}") """ Terminal> python num_diff.py dg/dx = 4 dg/dx = 2.75 """