fork download
  1. # calculating derivatives
  2.  
  3. def deriv(f):
  4. dx = 0.0001
  5. return lambda x : (f(x+dx) - f(x)) / dx
  6.  
  7. def cube(x):
  8. return x*x*x
  9.  
  10. cube_deriv = deriv(cube)
  11.  
  12. print(cube_deriv(2))
  13. print(cube_deriv(3))
  14. print(cube_deriv(4))
Success #stdin #stdout 0.01s 118656KB
stdin
Standard input is empty
stdout
12.00060001
27.0009000101
48.0012000099