# Illustrating the concept of numerical differentiation # The function to be differentiated is f(x) = x**3 # The derivative of the function is 3 x**2 # At x = 2, the derivative is therefore 12 # # The purpose of this script is to show that if # delta is small, then the derivative can be # approximated by # (f(x+delta)-f(x))/delta # Three different values of delta delta_list = [0.1,0.01,0.001] # The value of x x = 2 # To calculate the approximate derivative for each value # delta derivative_app = [ ((x + d)**3 - x**3)/d for d in delta_list] # To display the approximate derivative for k in range(0,len(delta_list)): print('For d = {0:0.3f}: approximate derivative = {1:0.8f}' .format(delta_list[k],derivative_app[k]))