Created
March 15, 2013 02:55
-
-
Save jobliz/5167177 to your computer and use it in GitHub Desktop.
The definition of derivative "just works" when coded in a programming language.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from http://funcall.blogspot.sg/2009/03/not-lisp-again.html | |
def deriv(f, dx=.0001): | |
return lambda x: (f(x + dx) - f(x)) / dx | |
cube = lambda x: x**3 | |
d = deriv(cube) | |
for n in xrange(5): | |
print n, d(n) | |
# 0 1e-08 | |
# 1 3.00030001 | |
# 2 12.00060001 | |
# 3 27.0009000101 | |
# 4 48.0012000099 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment