Last active
September 27, 2020 15:13
-
-
Save wulab/b93869589a876419d0a3b67c9e641cf6 to your computer and use it in GitHub Desktop.
Derivative of a Function
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
def deriv(f) | |
dx = 0.000001 | |
->(x) { (f.(x+dx) - f.(x)) / dx } | |
end | |
f = ->(x) { x*x + 2*x + 1 } | |
g = deriv(f) | |
g.(2) | |
# => 6.000001000927568 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment