Last active
November 24, 2016 13:42
-
-
Save aherve/c4c6facac35a5c1f2318455e1ca5ec51 to your computer and use it in GitHub Desktop.
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
| derivative = -> f { # we take a function as argument | |
| -> x { # the function takes a real x as argument | |
| ( f.(x+1e-3) - f.(x-1e-3) ) / ( 2e-3 ) # apply the scheme | |
| } | |
| } | |
| # Let's try: | |
| derivative_of_square = derivative.(square) => #<Proc:0x00000001b7c270@(irb):24 (lambda)> . Yay, a new function ! | |
| #Can we use it ? | |
| square.(3) # => 9 | |
| derivative_of_square.(3) # => 5.999999999999339 ~ 2*3. Cool ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment